allow omitting context

This commit is contained in:
Ben Kraft
2020-05-01 18:45:39 -07:00
parent 1156e6ceae
commit 5042a9a549
5 changed files with 24 additions and 31 deletions
+9 -17
View File
@@ -9,9 +9,10 @@ import (
)
var defaultConfig = &Config{
Schema: "schema.graphql",
Queries: "queries.graphql",
Generated: "generated.go",
Schema: "schema.graphql",
Queries: "queries.graphql",
Generated: "generated.go",
UseContext: true,
}
type Config struct {
@@ -28,19 +29,12 @@ type Config struct {
// The filename to which to write the generated code; defaults to
// generated.go
Generated string `yaml:"generated"`
// Whether the generated helpers should accept a context.Context which will
// be used to make the request; defaults to true.
UseContext bool `yaml:"use_context"`
}
func (c *Config) ValidateAndFillDefaults() error {
if c.Schema == "" {
c.Schema = defaultConfig.Schema
}
if c.Queries == "" {
c.Queries = defaultConfig.Queries
}
if c.Generated == "" {
c.Generated = defaultConfig.Generated
}
if c.Package == "" {
abs, err := filepath.Abs(c.Generated)
if err != nil {
@@ -56,10 +50,8 @@ func (c *Config) ValidateAndFillDefaults() error {
}
func ReadAndValidateConfig(filename string) (*Config, error) {
var config Config
if filename == "" {
config = *defaultConfig
} else {
config := *defaultConfig
if filename != "" {
text, err := ioutil.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("unreadable config file %v: %v", filename, err)