diff options
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/codegen/config.go')
-rw-r--r-- | vendor/github.com/99designs/gqlgen/codegen/config.go | 98 |
1 files changed, 88 insertions, 10 deletions
diff --git a/vendor/github.com/99designs/gqlgen/codegen/config.go b/vendor/github.com/99designs/gqlgen/codegen/config.go index db0e467b..f9df24fb 100644 --- a/vendor/github.com/99designs/gqlgen/codegen/config.go +++ b/vendor/github.com/99designs/gqlgen/codegen/config.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "path/filepath" + "sort" "strings" "github.com/99designs/gqlgen/internal/gopath" @@ -19,7 +20,8 @@ var cfgFilenames = []string{".gqlgen.yml", "gqlgen.yml", "gqlgen.yaml"} // DefaultConfig creates a copy of the default config func DefaultConfig() *Config { return &Config{ - SchemaFilename: "schema.graphql", + SchemaFilename: SchemaFilenames{"schema.graphql"}, + SchemaStr: map[string]string{}, Model: PackageConfig{Filename: "models_gen.go"}, Exec: PackageConfig{Filename: "generated.go"}, } @@ -53,19 +55,36 @@ func LoadConfig(filename string) (*Config, error) { return nil, errors.Wrap(err, "unable to parse config") } + preGlobbing := config.SchemaFilename + config.SchemaFilename = SchemaFilenames{} + for _, f := range preGlobbing { + matches, err := filepath.Glob(f) + if err != nil { + return nil, errors.Wrapf(err, "failed to glob schema filename %s", f) + } + + for _, m := range matches { + if config.SchemaFilename.Has(m) { + continue + } + config.SchemaFilename = append(config.SchemaFilename, m) + } + } + config.FilePath = filename + config.SchemaStr = map[string]string{} return config, nil } type Config struct { - SchemaFilename string `yaml:"schema,omitempty"` - SchemaStr string `yaml:"-"` - Exec PackageConfig `yaml:"exec"` - Model PackageConfig `yaml:"model"` - Resolver PackageConfig `yaml:"resolver,omitempty"` - Models TypeMap `yaml:"models,omitempty"` - StructTag string `yaml:"struct_tag,omitempty"` + SchemaFilename SchemaFilenames `yaml:"schema,omitempty"` + SchemaStr map[string]string `yaml:"-"` + Exec PackageConfig `yaml:"exec"` + Model PackageConfig `yaml:"model"` + Resolver PackageConfig `yaml:"resolver,omitempty"` + Models TypeMap `yaml:"models,omitempty"` + StructTag string `yaml:"struct_tag,omitempty"` FilePath string `yaml:"-"` @@ -84,8 +103,37 @@ type TypeMapEntry struct { } type TypeMapField struct { - Resolver bool `yaml:"resolver"` - FieldName string `yaml:"fieldName"` + Resolver bool `yaml:"resolver"` + FieldName string `yaml:"fieldName"` +} + +type SchemaFilenames []string + +func (a *SchemaFilenames) UnmarshalYAML(unmarshal func(interface{}) error) error { + var single string + err := unmarshal(&single) + if err == nil { + *a = []string{single} + return nil + } + + var multi []string + err = unmarshal(&multi) + if err != nil { + return err + } + + *a = multi + return nil +} + +func (a SchemaFilenames) Has(file string) bool { + for _, existing := range a { + if existing == file { + return true + } + } + return false } func (c *PackageConfig) normalize() error { @@ -162,6 +210,36 @@ func (tm TypeMap) Check() error { return nil } +func (tm TypeMap) referencedPackages() []string { + var pkgs []string + + for _, typ := range tm { + if typ.Model == "map[string]interface{}" { + continue + } + pkg, _ := pkgAndType(typ.Model) + if pkg == "" || inStrSlice(pkgs, pkg) { + continue + } + pkgs = append(pkgs, pkg) + } + + sort.Slice(pkgs, func(i, j int) bool { + return pkgs[i] > pkgs[j] + }) + return pkgs +} + +func inStrSlice(haystack []string, needle string) bool { + for _, v := range haystack { + if needle == v { + return true + } + } + + return false +} + // findCfg searches for the config file in this directory and all parents up the tree // looking for the closest match func findCfg() (string, error) { |