diff options
author | Michael Muré <batolettre@gmail.com> | 2019-07-09 08:47:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-09 08:47:46 +0200 |
commit | a5c42b7c11fc082d47027ba5e0dbdeddcc14e62e (patch) | |
tree | a279d04878f3f1b1e28089779d011c0cb4b7545d /vendor/github.com/99designs/gqlgen/plugin | |
parent | eef7333243252ae81cd43921beb8e0749a170585 (diff) | |
parent | fb50d470483b91d98e27ca6f9f605f0c51af6a71 (diff) | |
download | git-bug-a5c42b7c11fc082d47027ba5e0dbdeddcc14e62e.tar.gz |
Merge pull request #177 from A-Hilaly/git-version
Check git version in repo RmConfigs
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/plugin')
4 files changed, 102 insertions, 3 deletions
diff --git a/vendor/github.com/99designs/gqlgen/plugin/modelgen/models.go b/vendor/github.com/99designs/gqlgen/plugin/modelgen/models.go index bb400f1b..376499ae 100644 --- a/vendor/github.com/99designs/gqlgen/plugin/modelgen/models.go +++ b/vendor/github.com/99designs/gqlgen/plugin/modelgen/models.go @@ -72,6 +72,11 @@ func (m *Plugin) MutateConfig(cfg *config.Config) error { return err } + err = cfg.Autobind(schema) + if err != nil { + return err + } + cfg.InjectBuiltins(schema) binder, err := cfg.NewBinder(schema) diff --git a/vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.go b/vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.go index 00a6d5c9..6785c77c 100644 --- a/vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.go +++ b/vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.go @@ -19,6 +19,7 @@ type Plugin struct{} var _ plugin.CodeGenerator = &Plugin{} func (m *Plugin) Name() string { + // TODO: typo, should be resolvergen return "resovlergen" } func (m *Plugin) GenerateCode(data *codegen.Data) error { diff --git a/vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.gotpl b/vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.gotpl index 7d95e690..66d6efac 100644 --- a/vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.gotpl +++ b/vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.gotpl @@ -20,18 +20,18 @@ type {{.ResolverType}} struct {} {{ range $object := .Objects -}} {{- if $object.HasResolvers -}} func (r *{{$.ResolverType}}) {{$object.Name}}() {{ $object.ResolverInterface | ref }} { - return &{{lcFirst $object.Name}}Resolver{r} + return &{{lcFirst $object.Name}}{{ucFirst $.ResolverType}}{r} } {{ end -}} {{ end }} {{ range $object := .Objects -}} {{- if $object.HasResolvers -}} - type {{lcFirst $object.Name}}Resolver struct { *Resolver } + type {{lcFirst $object.Name}}{{ucFirst $.ResolverType}} struct { *{{$.ResolverType}} } {{ range $field := $object.Fields -}} {{- if $field.IsResolver -}} - func (r *{{lcFirst $object.Name}}Resolver) {{$field.GoFieldName}}{{ $field.ShortResolverDeclaration }} { + func (r *{{lcFirst $object.Name}}{{ucFirst $.ResolverType}}) {{$field.GoFieldName}}{{ $field.ShortResolverDeclaration }} { panic("not implemented") } {{ end -}} diff --git a/vendor/github.com/99designs/gqlgen/plugin/schemaconfig/schemaconfig.go b/vendor/github.com/99designs/gqlgen/plugin/schemaconfig/schemaconfig.go new file mode 100644 index 00000000..1fcf4105 --- /dev/null +++ b/vendor/github.com/99designs/gqlgen/plugin/schemaconfig/schemaconfig.go @@ -0,0 +1,93 @@ +package schemaconfig + +import ( + "github.com/99designs/gqlgen/codegen/config" + "github.com/99designs/gqlgen/plugin" + "github.com/vektah/gqlparser/ast" +) + +func New() plugin.Plugin { + return &Plugin{} +} + +type Plugin struct{} + +var _ plugin.ConfigMutator = &Plugin{} + +func (m *Plugin) Name() string { + return "schemaconfig" +} + +func (m *Plugin) MutateConfig(cfg *config.Config) error { + if err := cfg.Check(); err != nil { + return err + } + + schema, _, err := cfg.LoadSchema() + if err != nil { + return err + } + + cfg.Directives["goModel"] = config.DirectiveConfig{ + SkipRuntime: true, + } + + cfg.Directives["goField"] = config.DirectiveConfig{ + SkipRuntime: true, + } + + for _, schemaType := range schema.Types { + if schemaType == schema.Query || schemaType == schema.Mutation || schemaType == schema.Subscription { + continue + } + + if bd := schemaType.Directives.ForName("goModel"); bd != nil { + if ma := bd.Arguments.ForName("model"); ma != nil { + if mv, err := ma.Value.Value(nil); err == nil { + cfg.Models.Add(schemaType.Name, mv.(string)) + } + } + if ma := bd.Arguments.ForName("models"); ma != nil { + if mvs, err := ma.Value.Value(nil); err == nil { + for _, mv := range mvs.([]interface{}) { + cfg.Models.Add(schemaType.Name, mv.(string)) + } + } + } + } + + if schemaType.Kind == ast.Object || schemaType.Kind == ast.InputObject { + for _, field := range schemaType.Fields { + if fd := field.Directives.ForName("goField"); fd != nil { + forceResolver := cfg.Models[schemaType.Name].Fields[field.Name].Resolver + fieldName := cfg.Models[schemaType.Name].Fields[field.Name].FieldName + + if ra := fd.Arguments.ForName("forceResolver"); ra != nil { + if fr, err := ra.Value.Value(nil); err == nil { + forceResolver = fr.(bool) + } + } + + if na := fd.Arguments.ForName("name"); na != nil { + if fr, err := na.Value.Value(nil); err == nil { + fieldName = fr.(string) + } + } + + if cfg.Models[schemaType.Name].Fields == nil { + cfg.Models[schemaType.Name] = config.TypeMapEntry{ + Model: cfg.Models[schemaType.Name].Model, + Fields: map[string]config.TypeMapField{}, + } + } + + cfg.Models[schemaType.Name].Fields[field.Name] = config.TypeMapField{ + FieldName: fieldName, + Resolver: forceResolver, + } + } + } + } + } + return nil +} |