diff --git a/codegen/directive_build.go b/codegen/directive_build.go index f123b307ab..31a9d7f912 100644 --- a/codegen/directive_build.go +++ b/codegen/directive_build.go @@ -25,7 +25,7 @@ func (g *Generator) buildDirectives(types NamedTypes) (map[string]*Directive, er GoVarName: sanitizeArgName(arg.Name), } - if !newArg.TypeReference.IsInput && !newArg.TypeReference.IsScalar { + if !newArg.TypeReference.Definition.IsInput && !newArg.TypeReference.Definition.IsScalar { return nil, errors.Errorf("%s cannot be used as argument of directive %s(%s) only input and scalar types are allowed", arg.Type, dir.Name, arg.Name) } diff --git a/codegen/enum.go b/codegen/enum.go index 0fc497eea1..f062abbdb1 100644 --- a/codegen/enum.go +++ b/codegen/enum.go @@ -1,7 +1,7 @@ package codegen type Enum struct { - *TypeDefinition + Definition *TypeDefinition Description string Values []EnumValue } diff --git a/codegen/enum_build.go b/codegen/enum_build.go index 9519e687de..7fe2ae5868 100644 --- a/codegen/enum_build.go +++ b/codegen/enum_build.go @@ -24,18 +24,18 @@ func (g *Generator) buildEnums(ts NamedTypes) []Enum { } enum := Enum{ - TypeDefinition: namedType, - Values: values, - Description: typ.Description, + Definition: namedType, + Values: values, + Description: typ.Description, } - enum.GoType = types.NewNamed(types.NewTypeName(0, g.Config.Model.Pkg(), templates.ToCamel(enum.GQLType), nil), nil, nil) + enum.Definition.GoType = types.NewNamed(types.NewTypeName(0, g.Config.Model.Pkg(), templates.ToCamel(enum.Definition.GQLType), nil), nil, nil) enums = append(enums, enum) } sort.Slice(enums, func(i, j int) bool { - return enums[i].GQLType < enums[j].GQLType + return enums[i].Definition.GQLType < enums[j].Definition.GQLType }) return enums diff --git a/codegen/generator.go b/codegen/generator.go index 1edb0358f4..f8caaf64b9 100644 --- a/codegen/generator.go +++ b/codegen/generator.go @@ -51,15 +51,15 @@ func (g *Generator) Generate() error { } for _, model := range modelsBuild.Models { - modelCfg := g.Models[model.GQLType] - modelCfg.Model = types.TypeString(model.GoType, nil) - g.Models[model.GQLType] = modelCfg + modelCfg := g.Models[model.Definition.GQLType] + modelCfg.Model = types.TypeString(model.Definition.GoType, nil) + g.Models[model.Definition.GQLType] = modelCfg } for _, enum := range modelsBuild.Enums { - modelCfg := g.Models[enum.GQLType] - modelCfg.Model = types.TypeString(enum.GoType, nil) - g.Models[enum.GQLType] = modelCfg + modelCfg := g.Models[enum.Definition.GQLType] + modelCfg.Model = types.TypeString(enum.Definition.GoType, nil) + g.Models[enum.Definition.GQLType] = modelCfg } } diff --git a/codegen/input_build.go b/codegen/input_build.go index 1c572389ce..8862575986 100644 --- a/codegen/input_build.go +++ b/codegen/input_build.go @@ -21,7 +21,7 @@ func (g *Generator) buildInputs(namedTypes NamedTypes, prog *loader.Program) (Ob return nil, err } - if _, isMap := input.GoType.(*types.Map); !isMap { + if _, isMap := input.Definition.GoType.(*types.Map); !isMap { bindErrs := bindObject(input, g.StructTag) if len(bindErrs) > 0 { return nil, bindErrs @@ -33,14 +33,14 @@ func (g *Generator) buildInputs(namedTypes NamedTypes, prog *loader.Program) (Ob } sort.Slice(inputs, func(i, j int) bool { - return inputs[i].GQLType < inputs[j].GQLType + return inputs[i].Definition.GQLType < inputs[j].Definition.GQLType }) return inputs, nil } func (g *Generator) buildInput(types NamedTypes, typ *ast.Definition) (*Object, error) { - obj := &Object{TypeDefinition: types[typ.Name]} + obj := &Object{Definition: types[typ.Name]} typeEntry, entryExists := g.Models[typ.Name] for _, field := range typ.Fields { @@ -69,8 +69,8 @@ func (g *Generator) buildInput(types NamedTypes, typ *ast.Definition) (*Object, } } - if !newField.TypeReference.IsInput && !newField.TypeReference.IsScalar { - return nil, errors.Errorf("%s cannot be used as a field of %s. only input and scalar types are allowed", newField.GQLType, obj.GQLType) + if !newField.TypeReference.Definition.IsInput && !newField.TypeReference.Definition.IsScalar { + return nil, errors.Errorf("%s cannot be used as a field of %s. only input and scalar types are allowed", newField.Definition.GQLType, obj.Definition.GQLType) } obj.Fields = append(obj.Fields, newField) diff --git a/codegen/input_test.go b/codegen/input_test.go index d13847658c..744cf9c8ad 100644 --- a/codegen/input_test.go +++ b/codegen/input_test.go @@ -3,13 +3,11 @@ package codegen import ( "testing" - "github.com/vektah/gqlparser/gqlerror" - - "github.com/vektah/gqlparser/ast" - "github.com/99designs/gqlgen/codegen/config" "github.com/stretchr/testify/require" "github.com/vektah/gqlparser" + "github.com/vektah/gqlparser/ast" + "github.com/vektah/gqlparser/gqlerror" "golang.org/x/tools/go/loader" ) diff --git a/codegen/interface.go b/codegen/interface.go index e18e849d20..045bdba88e 100644 --- a/codegen/interface.go +++ b/codegen/interface.go @@ -1,13 +1,11 @@ package codegen type Interface struct { - *TypeDefinition - + Definition *TypeDefinition Implementors []InterfaceImplementor } type InterfaceImplementor struct { ValueReceiver bool - - *TypeDefinition + Definition *TypeDefinition } diff --git a/codegen/interface_build.go b/codegen/interface_build.go index 6d085b185d..a38d22af1f 100644 --- a/codegen/interface_build.go +++ b/codegen/interface_build.go @@ -17,21 +17,21 @@ func (g *Generator) buildInterfaces(types NamedTypes, prog *loader.Program) []*I } sort.Slice(interfaces, func(i, j int) bool { - return interfaces[i].GQLType < interfaces[j].GQLType + return interfaces[i].Definition.GQLType < interfaces[j].Definition.GQLType }) return interfaces } func (g *Generator) buildInterface(types NamedTypes, typ *ast.Definition, prog *loader.Program) *Interface { - i := &Interface{TypeDefinition: types[typ.Name]} + i := &Interface{Definition: types[typ.Name]} for _, implementor := range g.schema.GetPossibleTypes(typ) { t := types[implementor.Name] i.Implementors = append(i.Implementors, InterfaceImplementor{ - TypeDefinition: t, - ValueReceiver: g.isValueReceiver(types[typ.Name], t, prog), + Definition: t, + ValueReceiver: g.isValueReceiver(types[typ.Name], t, prog), }) } diff --git a/codegen/model.go b/codegen/model.go index 8c3acba198..09b2b4c8cf 100644 --- a/codegen/model.go +++ b/codegen/model.go @@ -1,7 +1,7 @@ package codegen type Model struct { - *TypeDefinition + Definition *TypeDefinition Description string Fields []ModelField Implements []*TypeDefinition diff --git a/codegen/models_build.go b/codegen/models_build.go index 865b57cf14..4377537657 100644 --- a/codegen/models_build.go +++ b/codegen/models_build.go @@ -43,7 +43,7 @@ func (g *Generator) buildModels(types NamedTypes, prog *loader.Program) ([]Model } sort.Slice(models, func(i, j int) bool { - return models[i].GQLType < models[j].GQLType + return models[i].Definition.GQLType < models[j].Definition.GQLType }) return models, nil @@ -51,9 +51,9 @@ func (g *Generator) buildModels(types NamedTypes, prog *loader.Program) ([]Model func (g *Generator) obj2Model(obj *Object) Model { model := Model{ - TypeDefinition: obj.TypeDefinition, - Implements: obj.Implements, - Fields: []ModelField{}, + Definition: obj.Definition, + Implements: obj.Implements, + Fields: []ModelField{}, } for i := range obj.Fields { @@ -74,8 +74,8 @@ func (g *Generator) obj2Model(obj *Object) Model { func int2Model(obj *Interface) Model { model := Model{ - TypeDefinition: obj.TypeDefinition, - Fields: []ModelField{}, + Definition: obj.Definition, + Fields: []ModelField{}, } return model diff --git a/codegen/object.go b/codegen/object.go index 4f4d2d5e17..fbcb6dabbb 100644 --- a/codegen/object.go +++ b/codegen/object.go @@ -23,8 +23,7 @@ const ( ) type Object struct { - *TypeDefinition - + Definition *TypeDefinition Fields []Field Satisfies []string Implements []*TypeDefinition @@ -65,7 +64,7 @@ type FieldArgument struct { type Objects []*Object func (o *Object) Implementors() string { - satisfiedBy := strconv.Quote(o.GQLType) + satisfiedBy := strconv.Quote(o.Definition.GQLType) for _, s := range o.Satisfies { satisfiedBy += ", " + strconv.Quote(s) } @@ -103,7 +102,7 @@ func (o *Object) IsConcurrent() bool { } func (o *Object) IsReserved() bool { - return strings.HasPrefix(o.GQLType, "__") + return strings.HasPrefix(o.Definition.GQLType, "__") } func (f *Field) HasDirectives() bool { @@ -146,7 +145,7 @@ func (f *Field) ShortInvocation() string { return "" } - return fmt.Sprintf("%s().%s(%s)", f.Object.GQLType, f.GoNameExported(), f.CallArgs()) + return fmt.Sprintf("%s().%s(%s)", f.Object.Definition.GQLType, f.GoNameExported(), f.CallArgs()) } func (f *Field) ArgsFunc() string { @@ -154,7 +153,7 @@ func (f *Field) ArgsFunc() string { return "" } - return "field_" + f.Object.GQLType + "_" + f.GQLName + "_args" + return "field_" + f.Object.Definition.GQLType + "_" + f.GQLName + "_args" } func (f *Field) ResolverType() string { @@ -162,7 +161,7 @@ func (f *Field) ResolverType() string { return "" } - return fmt.Sprintf("%s().%s(%s)", f.Object.GQLType, f.GoNameExported(), f.CallArgs()) + return fmt.Sprintf("%s().%s(%s)", f.Object.Definition.GQLType, f.GoNameExported(), f.CallArgs()) } func (f *Field) ShortResolverDeclaration() string { @@ -172,7 +171,7 @@ func (f *Field) ShortResolverDeclaration() string { res := fmt.Sprintf("%s(ctx context.Context", f.GoNameExported()) if !f.Object.Root { - res += fmt.Sprintf(", obj *%s", templates.CurrentImports.LookupType(f.Object.GoType)) + res += fmt.Sprintf(", obj *%s", templates.CurrentImports.LookupType(f.Object.Definition.GoType)) } for _, arg := range f.Args { res += fmt.Sprintf(", %s %s", arg.GoVarName, arg.Signature()) @@ -191,10 +190,10 @@ func (f *Field) ResolverDeclaration() string { if !f.IsResolver() { return "" } - res := fmt.Sprintf("%s_%s(ctx context.Context", f.Object.GQLType, f.GoNameUnexported()) + res := fmt.Sprintf("%s_%s(ctx context.Context", f.Object.Definition.GQLType, f.GoNameUnexported()) if !f.Object.Root { - res += fmt.Sprintf(", obj *%s", templates.CurrentImports.LookupType(f.Object.GoType)) + res += fmt.Sprintf(", obj *%s", templates.CurrentImports.LookupType(f.Object.Definition.GoType)) } for _, arg := range f.Args { res += fmt.Sprintf(", %s %s", arg.GoVarName, arg.Signature()) @@ -326,12 +325,12 @@ func (f *Field) doWriteJson(val string, remainingMods []string, astType *ast.Typ "index": index, "top": depth == 1, "arrayLen": len(val), - "isScalar": f.IsScalar, + "isScalar": f.Definition.IsScalar, "usePtr": usePtr, "next": f.doWriteJson(val+"["+index+"]", remainingMods[1:], astType.Elem, false, depth+1), }) - case f.IsScalar: + case f.Definition.IsScalar: if isPtr { val = "*" + val } @@ -343,7 +342,7 @@ func (f *Field) doWriteJson(val string, remainingMods []string, astType *ast.Typ } return tpl(` return ec._{{.type}}(ctx, field.Selections, {{.val}})`, map[string]interface{}{ - "type": f.GQLType, + "type": f.Definition.GQLType, "val": val, }) } @@ -355,7 +354,7 @@ func (f *FieldArgument) Stream() bool { func (os Objects) ByName(name string) *Object { for i, o := range os { - if strings.EqualFold(o.GQLType, name) { + if strings.EqualFold(o.Definition.GQLType, name) { return os[i] } } diff --git a/codegen/object_build.go b/codegen/object_build.go index 498deae39e..8d4e6a0e2e 100644 --- a/codegen/object_build.go +++ b/codegen/object_build.go @@ -25,7 +25,7 @@ func (g *Generator) buildObjects(ts NamedTypes, prog *loader.Program) (Objects, return nil, err } - if _, isMap := obj.GoType.(*types.Map); !isMap { + if _, isMap := obj.Definition.GoType.(*types.Map); !isMap { for _, bindErr := range bindObject(obj, g.StructTag) { log.Println(bindErr.Error()) log.Println(" Adding resolver method") @@ -36,7 +36,7 @@ func (g *Generator) buildObjects(ts NamedTypes, prog *loader.Program) (Objects, } sort.Slice(objects, func(i, j int) bool { - return objects[i].GQLType < objects[j].GQLType + return objects[i].Definition.GQLType < objects[j].Definition.GQLType }) return objects, nil @@ -81,10 +81,10 @@ func sanitizeArgName(name string) string { } func (g *Generator) buildObject(ts NamedTypes, typ *ast.Definition) (*Object, error) { - obj := &Object{TypeDefinition: ts[typ.Name]} + obj := &Object{Definition: ts[typ.Name]} typeEntry, entryExists := g.Models[typ.Name] - tt := types.NewTypeName(0, g.Config.Exec.Pkg(), obj.GQLType+"Resolver", nil) + tt := types.NewTypeName(0, g.Config.Exec.Pkg(), obj.Definition.GQLType+"Resolver", nil) obj.ResolverInterface = types.NewNamed(tt, nil, nil) if typ == g.schema.Query { @@ -158,8 +158,8 @@ func (g *Generator) buildObject(ts NamedTypes, typ *ast.Definition) (*Object, er Directives: dirs, } - if !newArg.TypeReference.IsInput && !newArg.TypeReference.IsScalar { - return nil, errors.Errorf("%s cannot be used as argument of %s.%s. only input and scalar types are allowed", arg.Type, obj.GQLType, field.Name) + if !newArg.TypeReference.Definition.IsInput && !newArg.TypeReference.Definition.IsScalar { + return nil, errors.Errorf("%s cannot be used as argument of %s.%s. only input and scalar types are allowed", arg.Type, obj.Definition.GQLType, field.Name) } if arg.DefaultValue != nil { diff --git a/codegen/templates/args.gotpl b/codegen/templates/args.gotpl index bb89483928..57eca14088 100644 --- a/codegen/templates/args.gotpl +++ b/codegen/templates/args.gotpl @@ -37,7 +37,7 @@ return nil, err } {{- end }} - {{- if $arg.IsInput }} + {{- if $arg.Definition.IsInput }} {{ $arg.Middleware (print "arg" $i) (print "arg" $i) }} {{- end }} } diff --git a/codegen/templates/data.go b/codegen/templates/data.go index 2a54e75d59..ec6f00da1f 100644 --- a/codegen/templates/data.go +++ b/codegen/templates/data.go @@ -1,13 +1,13 @@ package templates var data = map[string]string{ - "args.gotpl": "\targs := map[string]interface{}{}\n\t{{- range $i, $arg := . }}\n\t\tvar arg{{$i}} {{$arg.Signature }}\n\t\tif tmp, ok := rawArgs[{{$arg.GQLName|quote}}]; ok {\n\t\t\t{{- if $arg.Directives }}\n\t\t\t\targm{{$i}}, err := chainFieldMiddleware([]graphql.FieldMiddleware{\n\t\t\t\t{{- range $directive := $arg.Directives }}\n\t\t\t\t\tfunc(ctx context.Context, n graphql.Resolver) (res interface{}, err error) {\n\t\t\t\t\t{{- range $dArg := $directive.Args }}\n\t\t\t\t\t\t{{- if and $dArg.IsPtr ( notNil \"Value\" $dArg ) }}\n\t\t\t\t\t\t\t{{ $dArg.GoVarName }} := {{ $dArg.Value | dump }}\n\t\t\t\t\t\t{{- end }}\n\t\t\t\t\t{{- end }}\n\t\t\t\t\t\treturn e.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs \"tmp\" \"n\" }})\n\t\t\t\t\t},\n\t\t\t\t{{- end }}\n\t\t\t\t}...)(ctx, func(ctx2 context.Context) (interface{}, error) {\n\t\t\t\t\tvar err error\n\t\t\t\t\t{{$arg.Unmarshal (print \"arg\" $i) \"tmp\" }}\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\t\t\t\t\treturn arg{{ $i }}, nil\n\t\t\t\t})\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t\tif data, ok := argm{{$i}}.({{$arg.Signature }}); ok {\n\t\t\t\t\targ{{$i}} = data\n\t\t\t\t} else {\n\t\t\t\t\treturn nil, errors.New(\"expect {{$arg.Signature }}\")\n\t\t\t\t}\n\t\t\t{{- else }}\n\t\t\t\tvar err error\n\t\t\t\t{{ $arg.Unmarshal (print \"arg\" $i) \"tmp\" }}\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t{{- end }}\n\t\t\t{{- if $arg.IsInput }}\n\t\t\t\t{{ $arg.Middleware (print \"arg\" $i) (print \"arg\" $i) }}\n\t\t\t{{- end }}\n\t\t}\n\t\targs[{{$arg.GQLName|quote}}] = arg{{$i}}\n\t{{- end }}\n\treturn args, nil\n", - "field.gotpl": "{{ $field := . }}\n{{ $object := $field.Object }}\n\n{{- if $object.Stream }}\n\tfunc (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler {\n\t\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\t\tField: field,\n\t\t\tArgs: nil,\n\t\t})\n\t\t{{- if $field.Args }}\n\t\t\trawArgs := field.ArgumentMap(ec.Variables)\n\t\t\targs, err := ec.{{ $field.ArgsFunc }}(ctx,rawArgs)\n\t\t\tif err != nil {\n\t\t\t\tec.Error(ctx, err)\n\t\t\t\treturn nil\n\t\t\t}\n\t\t{{- end }}\n\t\t// FIXME: subscriptions are missing request middleware stack https://github.com/99designs/gqlgen/issues/259\n\t\t// and Tracer stack\n\t\trctx := ctx\n\t\tresults, err := ec.resolvers.{{ $field.ShortInvocation }}\n\t\tif err != nil {\n\t\t\tec.Error(ctx, err)\n\t\t\treturn nil\n\t\t}\n\t\treturn func() graphql.Marshaler {\n\t\t\tres, ok := <-results\n\t\t\tif !ok {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\treturn graphql.WriterFunc(func(w io.Writer) {\n\t\t\t\tw.Write([]byte{'{'})\n\t\t\t\tgraphql.MarshalString(field.Alias).MarshalGQL(w)\n\t\t\t\tw.Write([]byte{':'})\n\t\t\t\tfunc() graphql.Marshaler {\n\t\t\t\t\t{{ $field.WriteJson }}\n\t\t\t\t}().MarshalGQL(w)\n\t\t\t\tw.Write([]byte{'}'})\n\t\t\t})\n\t\t}\n\t}\n{{ else }}\n\t// nolint: vetshadow\n\tfunc (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField, {{if not $object.Root}}obj *{{$object.GoType | ref}}{{end}}) graphql.Marshaler {\n\t\tctx = ec.Tracer.StartFieldExecution(ctx, field)\n\t\tdefer func () { ec.Tracer.EndFieldExecution(ctx) }()\n\t\trctx := &graphql.ResolverContext{\n\t\t\tObject: {{$object.GQLType|quote}},\n\t\t\tField: field,\n\t\t\tArgs: nil,\n\t\t}\n\t\tctx = graphql.WithResolverContext(ctx, rctx)\n\t\t{{- if $field.Args }}\n\t\t\trawArgs := field.ArgumentMap(ec.Variables)\n\t\t\targs, err := ec.{{ $field.ArgsFunc }}(ctx,rawArgs)\n\t\t\tif err != nil {\n\t\t\t\tec.Error(ctx, err)\n\t\t\t\treturn graphql.Null\n\t\t\t}\n\t\t\trctx.Args = args\n\t\t{{- end }}\n\t\tctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx)\n\t\tresTmp := ec.FieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(rctx context.Context) (interface{}, error) {\n\t\t\tctx = rctx // use context from middleware stack in children\n\t\t\t{{- if $field.IsResolver }}\n\t\t\t\treturn ec.resolvers.{{ $field.ShortInvocation }}\n\t\t\t{{- else if $field.IsMethod }}\n\t\t\t\t{{- if $field.NoErr }}\n\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }}), nil\n\t\t\t\t{{- else }}\n\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }})\n\t\t\t\t{{- end }}\n\t\t\t{{- else if $field.IsVariable }}\n\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}, nil\n\t\t\t{{- end }}\n\t\t})\n\t\tif resTmp == nil {\n\t\t\t{{- if $field.ASTType.NonNull }}\n\t\t\t\tif !ec.HasError(rctx) {\n\t\t\t\t\tec.Errorf(ctx, \"must not be null\")\n\t\t\t\t}\n\t\t\t{{- end }}\n\t\t\treturn graphql.Null\n\t\t}\n\t\tres := resTmp.({{$field.Signature}})\n\t\trctx.Result = res\n\t\tctx = ec.Tracer.StartFieldChildExecution(ctx)\n\t\t{{ $field.WriteJson }}\n\t}\n{{ end }}\n", - "generated.gotpl": "// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.\n\npackage {{ .PackageName }}\n\nimport (\n\t%%%IMPORTS%%%\n\n\t{{ reserveImport \"context\" }}\n\t{{ reserveImport \"fmt\" }}\n\t{{ reserveImport \"io\" }}\n\t{{ reserveImport \"strconv\" }}\n\t{{ reserveImport \"time\" }}\n\t{{ reserveImport \"sync\" }}\n\t{{ reserveImport \"errors\" }}\n\t{{ reserveImport \"bytes\" }}\n\n\t{{ reserveImport \"github.com/vektah/gqlparser\" }}\n\t{{ reserveImport \"github.com/vektah/gqlparser/ast\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql/introspection\" }}\n)\n\n// NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface.\nfunc NewExecutableSchema(cfg Config) graphql.ExecutableSchema {\n\treturn &executableSchema{\n\t\tresolvers: cfg.Resolvers,\n\t\tdirectives: cfg.Directives,\n\t\tcomplexity: cfg.Complexity,\n\t}\n}\n\ntype Config struct {\n\tResolvers ResolverRoot\n\tDirectives DirectiveRoot\n\tComplexity ComplexityRoot\n}\n\ntype ResolverRoot interface {\n{{- range $object := .Objects -}}\n\t{{ if $object.HasResolvers -}}\n\t\t{{$object.GQLType}}() {{$object.GQLType}}Resolver\n\t{{ end }}\n{{- end }}\n}\n\ntype DirectiveRoot struct {\n{{ range $directive := .Directives }}\n\t{{ $directive.Declaration }}\n{{ end }}\n}\n\ntype ComplexityRoot struct {\n{{ range $object := .Objects }}\n\t{{ if not $object.IsReserved -}}\n\t\t{{ $object.GQLType|toCamel }} struct {\n\t\t{{ range $field := $object.Fields -}}\n\t\t\t{{ if not $field.IsReserved -}}\n\t\t\t\t{{ $field.GQLName|toCamel }} {{ $field.ComplexitySignature }}\n\t\t\t{{ end }}\n\t\t{{- end }}\n\t\t}\n\t{{- end }}\n{{ end }}\n}\n\n{{ range $object := .Objects -}}\n\t{{ if $object.HasResolvers }}\n\t\ttype {{$object.GQLType}}Resolver interface {\n\t\t{{ range $field := $object.Fields -}}\n\t\t\t{{ $field.ShortResolverDeclaration }}\n\t\t{{ end }}\n\t\t}\n\t{{- end }}\n{{- end }}\n\n{{ range $object := .Objects -}}\n\t{{ range $field := $object.Fields -}}\n\t\t{{ if $field.Args }}\n\t\t\tfunc (e *executableSchema){{ $field.ArgsFunc }}(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {\n\t\t\t{{ template \"args.gotpl\" $field.Args }}\n\t\t\t}\n\t\t{{ end }}\n\t{{ end }}\n{{- end }}\n\n{{ range $directive := .Directives }}\n\t{{ if $directive.Args }}\n\t\tfunc (e *executableSchema){{ $directive.ArgsFunc }}(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {\n\t\t{{ template \"args.gotpl\" $directive.Args }}\n\t\t}\n\t{{ end }}\n{{ end }}\n\ntype executableSchema struct {\n\tresolvers ResolverRoot\n\tdirectives DirectiveRoot\n\tcomplexity ComplexityRoot\n}\n\nfunc (e *executableSchema) Schema() *ast.Schema {\n\treturn parsedSchema\n}\n\nfunc (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) {\n\tswitch typeName + \".\" + field {\n\t{{ range $object := .Objects }}\n\t\t{{ if not $object.IsReserved }}\n\t\t\t{{ range $field := $object.Fields }}\n\t\t\t\t{{ if not $field.IsReserved }}\n\t\t\t\t\tcase \"{{$object.GQLType}}.{{$field.GQLName}}\":\n\t\t\t\t\t\tif e.complexity.{{$object.GQLType|toCamel}}.{{$field.GQLName|toCamel}} == nil {\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\t{{ if $field.Args }}\n\t\t\t\t\t\t\targs, err := e.{{ $field.ArgsFunc }}(context.TODO(),rawArgs)\n\t\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\t\treturn 0, false\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t{{ end }}\n\t\t\t\t\t\treturn e.complexity.{{$object.GQLType|toCamel}}.{{$field.GQLName|toCamel}}(childComplexity{{if $field.Args}}, {{$field.ComplexityArgs}} {{end}}), true\n\t\t\t\t{{ end }}\n\t\t\t{{ end }}\n\t\t{{ end }}\n\t{{ end }}\n\t}\n\treturn 0, false\n}\n\nfunc (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {\n\t{{- if .QueryRoot }}\n\t\tec := executionContext{graphql.GetRequestContext(ctx), e}\n\n\t\tbuf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte {\n\t\t\tdata := ec._{{.QueryRoot.GQLType}}(ctx, op.SelectionSet)\n\t\t\tvar buf bytes.Buffer\n\t\t\tdata.MarshalGQL(&buf)\n\t\t\treturn buf.Bytes()\n\t\t})\n\n\t\treturn &graphql.Response{\n\t\t\tData: buf,\n\t\t\tErrors: ec.Errors,\n\t\t\tExtensions: ec.Extensions,\t\t}\n\t{{- else }}\n\t\treturn graphql.ErrorResponse(ctx, \"queries are not supported\")\n\t{{- end }}\n}\n\nfunc (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {\n\t{{- if .MutationRoot }}\n\t\tec := executionContext{graphql.GetRequestContext(ctx), e}\n\n\t\tbuf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte {\n\t\t\tdata := ec._{{.MutationRoot.GQLType}}(ctx, op.SelectionSet)\n\t\t\tvar buf bytes.Buffer\n\t\t\tdata.MarshalGQL(&buf)\n\t\t\treturn buf.Bytes()\n\t\t})\n\n\t\treturn &graphql.Response{\n\t\t\tData: buf,\n\t\t\tErrors: ec.Errors,\n\t\t\tExtensions: ec.Extensions,\n\t\t}\n\t{{- else }}\n\t\treturn graphql.ErrorResponse(ctx, \"mutations are not supported\")\n\t{{- end }}\n}\n\nfunc (e *executableSchema) Subscription(ctx context.Context, op *ast.OperationDefinition) func() *graphql.Response {\n\t{{- if .SubscriptionRoot }}\n\t\tec := executionContext{graphql.GetRequestContext(ctx), e}\n\n\t\tnext := ec._{{.SubscriptionRoot.GQLType}}(ctx, op.SelectionSet)\n\t\tif ec.Errors != nil {\n\t\t\treturn graphql.OneShot(&graphql.Response{Data: []byte(\"null\"), Errors: ec.Errors})\n\t\t}\n\n\t\tvar buf bytes.Buffer\n\t\treturn func() *graphql.Response {\n\t\t\tbuf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte {\n\t\t\t\tbuf.Reset()\n\t\t\t\tdata := next()\n\n\t\t\t\tif data == nil {\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\tdata.MarshalGQL(&buf)\n\t\t\t\treturn buf.Bytes()\n\t\t\t})\n\n\t\t\tif buf == nil {\n\t\t\t\treturn nil\n\t\t\t}\n\n\t\t\treturn &graphql.Response{\n\t\t\t\tData: buf,\n\t\t\t\tErrors: ec.Errors,\n\t\t\t\tExtensions: ec.Extensions,\n\t\t\t}\n\t\t}\n\t{{- else }}\n\t\treturn graphql.OneShot(graphql.ErrorResponse(ctx, \"subscriptions are not supported\"))\n\t{{- end }}\n}\n\ntype executionContext struct {\n\t*graphql.RequestContext\n\t*executableSchema\n}\n\n{{- range $object := .Objects }}\n\t{{ template \"object.gotpl\" $object }}\n\n\t{{- range $field := $object.Fields }}\n\t\t{{ template \"field.gotpl\" $field }}\n\t{{ end }}\n{{- end}}\n\n{{- range $interface := .Interfaces }}\n\t{{ template \"interface.gotpl\" $interface }}\n{{- end }}\n\n{{- range $input := .Inputs }}\n\t{{ template \"input.gotpl\" $input }}\n{{- end }}\n\nfunc (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\tec.Error(ctx, ec.Recover(ctx, r))\n\t\t\tret = nil\n\t\t}\n\t}()\n\t{{- if .Directives }}\n\trctx := graphql.GetResolverContext(ctx)\n\tfor _, d := range rctx.Field.Definition.Directives {\n\t\tswitch d.Name {\n\t\t{{- range $directive := .Directives }}\n\t\tcase \"{{$directive.Name}}\":\n\t\t\tif ec.directives.{{$directive.Name|ucFirst}} != nil {\n\t\t\t\t{{- if $directive.Args }}\n\t\t\t\t\trawArgs := d.ArgumentMap(ec.Variables)\n\t\t\t\t\targs, err := ec.{{ $directive.ArgsFunc }}(ctx,rawArgs)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tec.Error(ctx, err)\n\t\t\t\t\t\treturn nil\n\t\t\t\t\t}\n\t\t\t\t{{- end }}\n\t\t\t\tn := next\n\t\t\t\tnext = func(ctx context.Context) (interface{}, error) {\n\t\t\t\t\treturn ec.directives.{{$directive.Name|ucFirst}}({{$directive.CallArgs}})\n\t\t\t\t}\n\t\t\t}\n\t\t{{- end }}\n\t\t}\n\t}\n\t{{- end }}\n\tres, err := ec.ResolverMiddleware(ctx, next)\n\tif err != nil {\n\t\tec.Error(ctx, err)\n\t\treturn nil\n\t}\n\treturn res\n}\n\nfunc (ec *executionContext) introspectSchema() (*introspection.Schema, error) {\n\tif ec.DisableIntrospection {\n\t\treturn nil, errors.New(\"introspection disabled\")\n\t}\n\treturn introspection.WrapSchema(parsedSchema), nil\n}\n\nfunc (ec *executionContext) introspectType(name string) (*introspection.Type, error) {\n\tif ec.DisableIntrospection {\n\t\treturn nil, errors.New(\"introspection disabled\")\n\t}\n\treturn introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil\n}\n\nvar parsedSchema = gqlparser.MustLoadSchema(\n\t{{- range $filename, $schema := .SchemaRaw }}\n\t\t&ast.Source{Name: {{$filename|quote}}, Input: {{$schema|rawQuote}}},\n\t{{- end }}\n)\n\n\n\n// ChainFieldMiddleware add chain by FieldMiddleware\n// nolint: deadcode\nfunc chainFieldMiddleware(handleFunc ...graphql.FieldMiddleware) graphql.FieldMiddleware {\n\tn := len(handleFunc)\n\n\tif n > 1 {\n\t\tlastI := n - 1\n\t\treturn func(ctx context.Context, next graphql.Resolver) (interface{}, error) {\n\t\t\tvar (\n\t\t\t\tchainHandler graphql.Resolver\n\t\t\t\tcurI int\n\t\t\t)\n\t\t\tchainHandler = func(currentCtx context.Context) (interface{}, error) {\n\t\t\t\tif curI == lastI {\n\t\t\t\t\treturn next(currentCtx)\n\t\t\t\t}\n\t\t\t\tcurI++\n\t\t\t\tres, err := handleFunc[curI](currentCtx, chainHandler)\n\t\t\t\tcurI--\n\t\t\t\treturn res, err\n\n\t\t\t}\n\t\t\treturn handleFunc[0](ctx, chainHandler)\n\t\t}\n\t}\n\n\tif n == 1 {\n\t\treturn handleFunc[0]\n\t}\n\n\treturn func(ctx context.Context, next graphql.Resolver) (interface{}, error) {\n\t\treturn next(ctx)\n\t}\n}\n", - "input.gotpl": "\t{{- if .IsMarshaled }}\n\tfunc Unmarshal{{ .GQLType }}(v interface{}) ({{.GoType | ref}}, error) {\n\t\tvar it {{.GoType | ref}}\n\t\tvar asMap = v.(map[string]interface{})\n\t\t{{ range $field := .Fields}}\n\t\t\t{{- if $field.Default}}\n\t\t\t\tif _, present := asMap[{{$field.GQLName|quote}}] ; !present {\n\t\t\t\t\tasMap[{{$field.GQLName|quote}}] = {{ $field.Default | dump }}\n\t\t\t\t}\n\t\t\t{{- end}}\n\t\t{{- end }}\n\n\t\tfor k, v := range asMap {\n\t\t\tswitch k {\n\t\t\t{{- range $field := .Fields }}\n\t\t\tcase {{$field.GQLName|quote}}:\n\t\t\t\tvar err error\n\t\t\t\t{{ $field.Unmarshal (print \"it.\" $field.GoFieldName) \"v\" }}\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn it, err\n\t\t\t\t}\n\t\t\t{{- end }}\n\t\t\t}\n\t\t}\n\n\t\treturn it, nil\n\t}\n\t{{- end }}\n\n\tfunc (e *executableSchema) {{ .GQLType }}Middleware(ctx context.Context, obj *{{.GoType | ref}}) (*{{.GoType | ref}}, error) {\n\t\t\t{{ if .Directives }}\n\t\tcObj, err := chainFieldMiddleware(\n\t\t\t[]graphql.FieldMiddleware{\n\t\t\t\t{{- range $directive := .Directives }}\n\t\t\t\t\tfunc(ctx context.Context, n graphql.Resolver) (res interface{}, err error) {\n\t\t\t\t\t{{- if $directive.Args }}\n\t\t\t\t\t{{- range $arg := $directive.Args }}\n\t\t\t\t\t\t{{- if and $arg.IsPtr ( notNil \"Value\" $arg ) }}\n\t\t\t\t\t\t\t{{ $arg.GoVarName }} := {{ $arg.Value | dump }}\n\t\t\t\t\t\t{{- end }}\n\t\t\t\t\t{{- end }}\n\t\t\t\t\t{{- end -}}\n\t\t\t\t\t\treturn e.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs \"obj\" \"n\"}})\n\t\t\t\t\t},\n\t\t\t\t{{ end }}\n\t\t\t}...\n\t\t)(ctx, func(ctx context.Context)(interface{}, error){\n\t\t\treturn obj, nil\n\t\t})\n\t\tif err != nil || cObj == nil {\n\t\t\treturn nil ,err\n\t\t}\n\t\tobj, ok := cObj.(*{{.GoType | ref}})\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"expect {{.GoType | ref}}\")\n\t\t}\n\t\t{{ end }}\n\n\t\t{{- range $field := .Fields }}\n\t\t{{ if $field.HasDirectives }}\n\t\t\tc{{$field.GoFieldName}}, err := chainFieldMiddleware(\n\t\t\t\t[]graphql.FieldMiddleware{\n\t\t\t\t\t{{- range $directive := $field.Directives }}\n\t\t\t\t\t\tfunc(ctx context.Context, n graphql.Resolver) (res interface{}, err error) {\n\t\t\t\t\t\t{{- if $directive.Args }}\n\t\t\t\t\t\t{{- range $arg := $directive.Args }}\n\t\t\t\t\t\t\t{{- if and $arg.IsPtr ( notNil \"Value\" $arg ) }}\n\t\t\t\t\t\t\t\t{{ $arg.GoVarName }} := {{ $arg.Value | dump }}\n\t\t\t\t\t\t\t{{- end }}\n\t\t\t\t\t\t{{- end }}\n\t\t\t\t\t\t{{- end }}\n\t\t\t\t\t\t\t{{ if $field.IsPtr -}}\n\t\t\t\t\t\t\t\treturn e.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs ( print \"*obj.\" $field.GoFieldName ) \"n\"}})\n\t\t\t\t\t\t\t{{- else -}}\n\t\t\t\t\t\t\t\treturn e.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs ( print \"obj.\" $field.GoFieldName ) \"n\"}})\n\t\t\t\t\t\t\t{{- end }}\n\t\t\t\t\t\t},\n\t\t\t\t\t{{ end }}\n\t\t\t\t}...\n\t\t\t)(ctx, func(ctx context.Context)(interface{}, error){\n\t\t\t\treturn {{ if $field.IsPtr }}*{{end}}obj.{{$field.GoFieldName}}, nil\n\t\t\t})\n\t\t\tif err != nil {\n\t\t\t\treturn obj ,err\n\t\t\t}\n\n\t\t\t{{ if $field.IsPtr }}\n\t\t\t\tif data, ok := c{{$field.GoFieldName}}.({{ $field.GoType | ref }}); ok {\n \t\tobj.{{$field.GoFieldName}} = &data\n \t} else {\n \t\treturn obj, errors.New(\"expect {{ $field.Signature }}\")\n \t}\n\t\t\t{{else}}\n \tif data, ok := c{{$field.GoFieldName}}.({{ $field.Signature }}); ok{\n \t\tobj.{{$field.GoFieldName}} = data\n \t}else{\n \t\treturn obj, errors.New(\"{{$field.GoFieldName}} expect {{$field.Signature }}\")\n \t}\n\t\t\t{{ end }}\n\n\t\t\t{{- end }}\n\n\t\t\t{{ if $field.IsInput }}\n\t\t\t\t{{ $field.Middleware (print \"obj.\" $field.GoFieldName ) (print \"obj.\" $field.GoFieldName ) }}\n\t\t\t{{- end }}\n\t\t{{- end }}\n\t\treturn obj, nil\n\t}\n", - "interface.gotpl": "{{- $interface := . }}\n\nfunc (ec *executionContext) _{{$interface.GQLType}}(ctx context.Context, sel ast.SelectionSet, obj *{{$interface.GoType | ref}}) graphql.Marshaler {\n\tswitch obj := (*obj).(type) {\n\tcase nil:\n\t\treturn graphql.Null\n\t{{- range $implementor := $interface.Implementors }}\n\t\t{{- if $implementor.ValueReceiver }}\n\t\t\tcase {{$implementor.GoType | ref}}:\n\t\t\t\treturn ec._{{$implementor.GQLType}}(ctx, sel, &obj)\n\t\t{{- end}}\n\t\tcase *{{$implementor.GoType | ref}}:\n\t\t\treturn ec._{{$implementor.GQLType}}(ctx, sel, obj)\n\t{{- end }}\n\tdefault:\n\t\tpanic(fmt.Errorf(\"unexpected type %T\", obj))\n\t}\n}\n", - "models.gotpl": "// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.\n\npackage {{ .PackageName }}\n\nimport (\n\t%%%IMPORTS%%%\n\n\t{{ reserveImport \"context\" }}\n\t{{ reserveImport \"fmt\" }}\n\t{{ reserveImport \"io\" }}\n\t{{ reserveImport \"strconv\" }}\n\t{{ reserveImport \"time\" }}\n\t{{ reserveImport \"sync\" }}\n\t{{ reserveImport \"errors\" }}\n\t{{ reserveImport \"bytes\" }}\n\n\t{{ reserveImport \"github.com/vektah/gqlparser\" }}\n\t{{ reserveImport \"github.com/vektah/gqlparser/ast\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql/introspection\" }}\n)\n\n{{ range $model := .Models }}\n\t{{with .Description}} {{.|prefixLines \"// \"}} {{end}}\n\t{{- if .IsInterface }}\n\t\ttype {{.GoType | ref }} interface {\n\t\t\tIs{{.GoType | ref }}()\n\t\t}\n\t{{- else }}\n\t\ttype {{.GoType | ref }} struct {\n\t\t\t{{- range $field := .Fields }}\n\t\t\t\t{{- with .Description}}\n\t\t\t\t\t{{.|prefixLines \"// \"}}\n\t\t\t\t{{- end}}\n\t\t\t\t{{ $field.GoFieldName }} {{$field.Signature}} `json:\"{{$field.GQLName}}\"`\n\t\t\t{{- end }}\n\t\t}\n\n\t\t{{- range $iface := .Implements }}\n\t\t\tfunc ({{$model.GoType | ref }}) Is{{$iface.GoType | ref }}() {}\n\t\t{{- end }}\n\n\t{{- end }}\n{{- end}}\n\n{{ range $enum := .Enums }}\n\t{{with .Description}}{{.|prefixLines \"// \"}} {{end}}\n\ttype {{.GoType | ref }} string\n\tconst (\n\t{{- range $value := .Values}}\n\t\t{{- with .Description}}\n\t\t\t{{.|prefixLines \"// \"}}\n\t\t{{- end}}\n\t\t{{$enum.GoType | ref }}{{ .Name|toCamel }} {{$enum.GoType | ref }} = {{.Name|quote}}\n\t{{- end }}\n\t)\n\n\tvar All{{.GoType | ref }} = []{{.GoType | ref }}{\n\t{{- range $value := .Values}}\n\t\t{{$enum.GoType | ref }}{{ .Name|toCamel }},\n\t{{- end }}\n\t}\n\n\tfunc (e {{.GoType | ref }}) IsValid() bool {\n\t\tswitch e {\n\t\tcase {{ range $index, $element := .Values}}{{if $index}},{{end}}{{ $enum.GoType | ref }}{{ $element.Name|toCamel }}{{end}}:\n\t\t\treturn true\n\t\t}\n\t\treturn false\n\t}\n\n\tfunc (e {{.GoType | ref }}) String() string {\n\t\treturn string(e)\n\t}\n\n\tfunc (e *{{.GoType | ref }}) UnmarshalGQL(v interface{}) error {\n\t\tstr, ok := v.(string)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"enums must be strings\")\n\t\t}\n\n\t\t*e = {{.GoType | ref }}(str)\n\t\tif !e.IsValid() {\n\t\t\treturn fmt.Errorf(\"%s is not a valid {{.GQLType}}\", str)\n\t\t}\n\t\treturn nil\n\t}\n\n\tfunc (e {{.GoType | ref }}) MarshalGQL(w io.Writer) {\n\t\tfmt.Fprint(w, strconv.Quote(e.String()))\n\t}\n\n{{- end }}\n", - "object.gotpl": "{{ $object := . }}\n\nvar {{ $object.GQLType|lcFirst}}Implementors = {{$object.Implementors}}\n\n// nolint: gocyclo, errcheck, gas, goconst\n{{- if .Stream }}\nfunc (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel ast.SelectionSet) func() graphql.Marshaler {\n\tfields := graphql.CollectFields(ctx, sel, {{$object.GQLType|lcFirst}}Implementors)\n\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\tObject: {{$object.GQLType|quote}},\n\t})\n\tif len(fields) != 1 {\n\t\tec.Errorf(ctx, \"must subscribe to exactly one stream\")\n\t\treturn nil\n\t}\n\n\tswitch fields[0].Name {\n\t{{- range $field := $object.Fields }}\n\tcase \"{{$field.GQLName}}\":\n\t\treturn ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, fields[0])\n\t{{- end }}\n\tdefault:\n\t\tpanic(\"unknown field \" + strconv.Quote(fields[0].Name))\n\t}\n}\n{{- else }}\nfunc (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel ast.SelectionSet{{if not $object.Root}}, obj *{{$object.GoType | ref }} {{end}}) graphql.Marshaler {\n\tfields := graphql.CollectFields(ctx, sel, {{$object.GQLType|lcFirst}}Implementors)\n\t{{if $object.Root}}\n\t\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\t\tObject: {{$object.GQLType|quote}},\n\t\t})\n\t{{end}}\n\n\tout := graphql.NewFieldSet(fields)\n\tinvalid := false\n\tfor i, field := range fields {\n\t\tswitch field.Name {\n\t\tcase \"__typename\":\n\t\t\tout.Values[i] = graphql.MarshalString({{$object.GQLType|quote}})\n\t\t{{- range $field := $object.Fields }}\n\t\tcase \"{{$field.GQLName}}\":\n\t\t\t{{- if $field.IsConcurrent }}\n\t\t\t\tfield := field\n\t\t\t\tout.Concurrently(i, func() (res graphql.Marshaler) {\n\t\t\t\t\tres = ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}})\n\t\t\t\t\t{{- if $field.ASTType.NonNull }}\n\t\t\t\t\t\tif res == graphql.Null {\n\t\t\t\t\t\t\tinvalid = true\n\t\t\t\t\t\t}\n\t\t\t\t\t{{- end }}\n\t\t\t\t\treturn res\n\t\t\t\t})\n\t\t\t{{- else }}\n\t\t\t\tout.Values[i] = ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}})\n\t\t\t\t{{- if $field.ASTType.NonNull }}\n\t\t\t\t\tif out.Values[i] == graphql.Null {\n\t\t\t\t\t\tinvalid = true\n\t\t\t\t\t}\n\t\t\t\t{{- end }}\n\t\t\t{{- end }}\n\t\t{{- end }}\n\t\tdefault:\n\t\t\tpanic(\"unknown field \" + strconv.Quote(field.Name))\n\t\t}\n\t}\n\tout.Dispatch()\n\tif invalid { return graphql.Null }\n\treturn out\n}\n{{- end }}\n", - "resolver.gotpl": "package {{ .PackageName }}\n\nimport (\n\t%%%IMPORTS%%%\n\n\t{{ reserveImport \"context\" }}\n\t{{ reserveImport \"fmt\" }}\n\t{{ reserveImport \"io\" }}\n\t{{ reserveImport \"strconv\" }}\n\t{{ reserveImport \"time\" }}\n\t{{ reserveImport \"sync\" }}\n\t{{ reserveImport \"errors\" }}\n\t{{ reserveImport \"bytes\" }}\n\n\t{{ reserveImport \"github.com/99designs/gqlgen/handler\" }}\n\t{{ reserveImport \"github.com/vektah/gqlparser\" }}\n\t{{ reserveImport \"github.com/vektah/gqlparser/ast\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql/introspection\" }}\n)\n\ntype {{.ResolverType}} struct {}\n\n{{ range $object := .Objects -}}\n\t{{- if $object.HasResolvers -}}\n\t\tfunc (r *{{$.ResolverType}}) {{$object.GQLType}}() {{ $object.ResolverInterface | ref }} {\n\t\t\treturn &{{lcFirst $object.GQLType}}Resolver{r}\n\t\t}\n\t{{ end -}}\n{{ end }}\n\n{{ range $object := .Objects -}}\n\t{{- if $object.HasResolvers -}}\n\t\ttype {{lcFirst $object.GQLType}}Resolver struct { *Resolver }\n\n\t\t{{ range $field := $object.Fields -}}\n\t\t\t{{- if $field.IsResolver -}}\n\t\t\tfunc (r *{{lcFirst $object.GQLType}}Resolver) {{ $field.ShortResolverDeclaration }} {\n\t\t\t\tpanic(\"not implemented\")\n\t\t\t}\n\t\t\t{{ end -}}\n\t\t{{ end -}}\n\t{{ end -}}\n{{ end }}\n", + "args.gotpl": "\targs := map[string]interface{}{}\n\t{{- range $i, $arg := . }}\n\t\tvar arg{{$i}} {{$arg.Signature }}\n\t\tif tmp, ok := rawArgs[{{$arg.GQLName|quote}}]; ok {\n\t\t\t{{- if $arg.Directives }}\n\t\t\t\targm{{$i}}, err := chainFieldMiddleware([]graphql.FieldMiddleware{\n\t\t\t\t{{- range $directive := $arg.Directives }}\n\t\t\t\t\tfunc(ctx context.Context, n graphql.Resolver) (res interface{}, err error) {\n\t\t\t\t\t{{- range $dArg := $directive.Args }}\n\t\t\t\t\t\t{{- if and $dArg.IsPtr ( notNil \"Value\" $dArg ) }}\n\t\t\t\t\t\t\t{{ $dArg.GoVarName }} := {{ $dArg.Value | dump }}\n\t\t\t\t\t\t{{- end }}\n\t\t\t\t\t{{- end }}\n\t\t\t\t\t\treturn e.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs \"tmp\" \"n\" }})\n\t\t\t\t\t},\n\t\t\t\t{{- end }}\n\t\t\t\t}...)(ctx, func(ctx2 context.Context) (interface{}, error) {\n\t\t\t\t\tvar err error\n\t\t\t\t\t{{$arg.Unmarshal (print \"arg\" $i) \"tmp\" }}\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\t\t\t\t\treturn arg{{ $i }}, nil\n\t\t\t\t})\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t\tif data, ok := argm{{$i}}.({{$arg.Signature }}); ok {\n\t\t\t\t\targ{{$i}} = data\n\t\t\t\t} else {\n\t\t\t\t\treturn nil, errors.New(\"expect {{$arg.Signature }}\")\n\t\t\t\t}\n\t\t\t{{- else }}\n\t\t\t\tvar err error\n\t\t\t\t{{ $arg.Unmarshal (print \"arg\" $i) \"tmp\" }}\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t{{- end }}\n\t\t\t{{- if $arg.Definition.IsInput }}\n\t\t\t\t{{ $arg.Middleware (print \"arg\" $i) (print \"arg\" $i) }}\n\t\t\t{{- end }}\n\t\t}\n\t\targs[{{$arg.GQLName|quote}}] = arg{{$i}}\n\t{{- end }}\n\treturn args, nil\n", + "field.gotpl": "{{ $field := . }}\n{{ $object := $field.Object }}\n\n{{- if $object.Stream }}\n\tfunc (ec *executionContext) _{{$object.Definition.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler {\n\t\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\t\tField: field,\n\t\t\tArgs: nil,\n\t\t})\n\t\t{{- if $field.Args }}\n\t\t\trawArgs := field.ArgumentMap(ec.Variables)\n\t\t\targs, err := ec.{{ $field.ArgsFunc }}(ctx,rawArgs)\n\t\t\tif err != nil {\n\t\t\t\tec.Error(ctx, err)\n\t\t\t\treturn nil\n\t\t\t}\n\t\t{{- end }}\n\t\t// FIXME: subscriptions are missing request middleware stack https://github.com/99designs/gqlgen/issues/259\n\t\t// and Tracer stack\n\t\trctx := ctx\n\t\tresults, err := ec.resolvers.{{ $field.ShortInvocation }}\n\t\tif err != nil {\n\t\t\tec.Error(ctx, err)\n\t\t\treturn nil\n\t\t}\n\t\treturn func() graphql.Marshaler {\n\t\t\tres, ok := <-results\n\t\t\tif !ok {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\treturn graphql.WriterFunc(func(w io.Writer) {\n\t\t\t\tw.Write([]byte{'{'})\n\t\t\t\tgraphql.MarshalString(field.Alias).MarshalGQL(w)\n\t\t\t\tw.Write([]byte{':'})\n\t\t\t\tfunc() graphql.Marshaler {\n\t\t\t\t\t{{ $field.WriteJson }}\n\t\t\t\t}().MarshalGQL(w)\n\t\t\t\tw.Write([]byte{'}'})\n\t\t\t})\n\t\t}\n\t}\n{{ else }}\n\t// nolint: vetshadow\n\tfunc (ec *executionContext) _{{$object.Definition.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField, {{if not $object.Root}}obj *{{$object.Definition.GoType | ref}}{{end}}) graphql.Marshaler {\n\t\tctx = ec.Tracer.StartFieldExecution(ctx, field)\n\t\tdefer func () { ec.Tracer.EndFieldExecution(ctx) }()\n\t\trctx := &graphql.ResolverContext{\n\t\t\tObject: {{$object.Definition.GQLType|quote}},\n\t\t\tField: field,\n\t\t\tArgs: nil,\n\t\t}\n\t\tctx = graphql.WithResolverContext(ctx, rctx)\n\t\t{{- if $field.Args }}\n\t\t\trawArgs := field.ArgumentMap(ec.Variables)\n\t\t\targs, err := ec.{{ $field.ArgsFunc }}(ctx,rawArgs)\n\t\t\tif err != nil {\n\t\t\t\tec.Error(ctx, err)\n\t\t\t\treturn graphql.Null\n\t\t\t}\n\t\t\trctx.Args = args\n\t\t{{- end }}\n\t\tctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx)\n\t\tresTmp := ec.FieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(rctx context.Context) (interface{}, error) {\n\t\t\tctx = rctx // use context from middleware stack in children\n\t\t\t{{- if $field.IsResolver }}\n\t\t\t\treturn ec.resolvers.{{ $field.ShortInvocation }}\n\t\t\t{{- else if $field.IsMethod }}\n\t\t\t\t{{- if $field.NoErr }}\n\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }}), nil\n\t\t\t\t{{- else }}\n\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }})\n\t\t\t\t{{- end }}\n\t\t\t{{- else if $field.IsVariable }}\n\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}, nil\n\t\t\t{{- end }}\n\t\t})\n\t\tif resTmp == nil {\n\t\t\t{{- if $field.ASTType.NonNull }}\n\t\t\t\tif !ec.HasError(rctx) {\n\t\t\t\t\tec.Errorf(ctx, \"must not be null\")\n\t\t\t\t}\n\t\t\t{{- end }}\n\t\t\treturn graphql.Null\n\t\t}\n\t\tres := resTmp.({{$field.Signature}})\n\t\trctx.Result = res\n\t\tctx = ec.Tracer.StartFieldChildExecution(ctx)\n\t\t{{ $field.WriteJson }}\n\t}\n{{ end }}\n", + "generated.gotpl": "// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.\n\npackage {{ .PackageName }}\n\nimport (\n\t%%%IMPORTS%%%\n\n\t{{ reserveImport \"context\" }}\n\t{{ reserveImport \"fmt\" }}\n\t{{ reserveImport \"io\" }}\n\t{{ reserveImport \"strconv\" }}\n\t{{ reserveImport \"time\" }}\n\t{{ reserveImport \"sync\" }}\n\t{{ reserveImport \"errors\" }}\n\t{{ reserveImport \"bytes\" }}\n\n\t{{ reserveImport \"github.com/vektah/gqlparser\" }}\n\t{{ reserveImport \"github.com/vektah/gqlparser/ast\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql/introspection\" }}\n)\n\n// NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface.\nfunc NewExecutableSchema(cfg Config) graphql.ExecutableSchema {\n\treturn &executableSchema{\n\t\tresolvers: cfg.Resolvers,\n\t\tdirectives: cfg.Directives,\n\t\tcomplexity: cfg.Complexity,\n\t}\n}\n\ntype Config struct {\n\tResolvers ResolverRoot\n\tDirectives DirectiveRoot\n\tComplexity ComplexityRoot\n}\n\ntype ResolverRoot interface {\n{{- range $object := .Objects -}}\n\t{{ if $object.HasResolvers -}}\n\t\t{{$object.Definition.GQLType}}() {{$object.Definition.GQLType}}Resolver\n\t{{ end }}\n{{- end }}\n}\n\ntype DirectiveRoot struct {\n{{ range $directive := .Directives }}\n\t{{ $directive.Declaration }}\n{{ end }}\n}\n\ntype ComplexityRoot struct {\n{{ range $object := .Objects }}\n\t{{ if not $object.IsReserved -}}\n\t\t{{ $object.Definition.GQLType|toCamel }} struct {\n\t\t{{ range $field := $object.Fields -}}\n\t\t\t{{ if not $field.IsReserved -}}\n\t\t\t\t{{ $field.GQLName|toCamel }} {{ $field.ComplexitySignature }}\n\t\t\t{{ end }}\n\t\t{{- end }}\n\t\t}\n\t{{- end }}\n{{ end }}\n}\n\n{{ range $object := .Objects -}}\n\t{{ if $object.HasResolvers }}\n\t\ttype {{$object.Definition.GQLType}}Resolver interface {\n\t\t{{ range $field := $object.Fields -}}\n\t\t\t{{ $field.ShortResolverDeclaration }}\n\t\t{{ end }}\n\t\t}\n\t{{- end }}\n{{- end }}\n\n{{ range $object := .Objects -}}\n\t{{ range $field := $object.Fields -}}\n\t\t{{ if $field.Args }}\n\t\t\tfunc (e *executableSchema){{ $field.ArgsFunc }}(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {\n\t\t\t{{ template \"args.gotpl\" $field.Args }}\n\t\t\t}\n\t\t{{ end }}\n\t{{ end }}\n{{- end }}\n\n{{ range $directive := .Directives }}\n\t{{ if $directive.Args }}\n\t\tfunc (e *executableSchema){{ $directive.ArgsFunc }}(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {\n\t\t{{ template \"args.gotpl\" $directive.Args }}\n\t\t}\n\t{{ end }}\n{{ end }}\n\ntype executableSchema struct {\n\tresolvers ResolverRoot\n\tdirectives DirectiveRoot\n\tcomplexity ComplexityRoot\n}\n\nfunc (e *executableSchema) Schema() *ast.Schema {\n\treturn parsedSchema\n}\n\nfunc (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) {\n\tswitch typeName + \".\" + field {\n\t{{ range $object := .Objects }}\n\t\t{{ if not $object.IsReserved }}\n\t\t\t{{ range $field := $object.Fields }}\n\t\t\t\t{{ if not $field.IsReserved }}\n\t\t\t\t\tcase \"{{$object.Definition.GQLType}}.{{$field.GQLName}}\":\n\t\t\t\t\t\tif e.complexity.{{$object.Definition.GQLType|toCamel}}.{{$field.GQLName|toCamel}} == nil {\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\t{{ if $field.Args }}\n\t\t\t\t\t\t\targs, err := e.{{ $field.ArgsFunc }}(context.TODO(),rawArgs)\n\t\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\t\treturn 0, false\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t{{ end }}\n\t\t\t\t\t\treturn e.complexity.{{$object.Definition.GQLType|toCamel}}.{{$field.GQLName|toCamel}}(childComplexity{{if $field.Args}}, {{$field.ComplexityArgs}} {{end}}), true\n\t\t\t\t{{ end }}\n\t\t\t{{ end }}\n\t\t{{ end }}\n\t{{ end }}\n\t}\n\treturn 0, false\n}\n\nfunc (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {\n\t{{- if .QueryRoot }}\n\t\tec := executionContext{graphql.GetRequestContext(ctx), e}\n\n\t\tbuf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte {\n\t\t\tdata := ec._{{.QueryRoot.Definition.GQLType}}(ctx, op.SelectionSet)\n\t\t\tvar buf bytes.Buffer\n\t\t\tdata.MarshalGQL(&buf)\n\t\t\treturn buf.Bytes()\n\t\t})\n\n\t\treturn &graphql.Response{\n\t\t\tData: buf,\n\t\t\tErrors: ec.Errors,\n\t\t\tExtensions: ec.Extensions,\t\t}\n\t{{- else }}\n\t\treturn graphql.ErrorResponse(ctx, \"queries are not supported\")\n\t{{- end }}\n}\n\nfunc (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {\n\t{{- if .MutationRoot }}\n\t\tec := executionContext{graphql.GetRequestContext(ctx), e}\n\n\t\tbuf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte {\n\t\t\tdata := ec._{{.MutationRoot.Definition.GQLType}}(ctx, op.SelectionSet)\n\t\t\tvar buf bytes.Buffer\n\t\t\tdata.MarshalGQL(&buf)\n\t\t\treturn buf.Bytes()\n\t\t})\n\n\t\treturn &graphql.Response{\n\t\t\tData: buf,\n\t\t\tErrors: ec.Errors,\n\t\t\tExtensions: ec.Extensions,\n\t\t}\n\t{{- else }}\n\t\treturn graphql.ErrorResponse(ctx, \"mutations are not supported\")\n\t{{- end }}\n}\n\nfunc (e *executableSchema) Subscription(ctx context.Context, op *ast.OperationDefinition) func() *graphql.Response {\n\t{{- if .SubscriptionRoot }}\n\t\tec := executionContext{graphql.GetRequestContext(ctx), e}\n\n\t\tnext := ec._{{.SubscriptionRoot.Definition.GQLType}}(ctx, op.SelectionSet)\n\t\tif ec.Errors != nil {\n\t\t\treturn graphql.OneShot(&graphql.Response{Data: []byte(\"null\"), Errors: ec.Errors})\n\t\t}\n\n\t\tvar buf bytes.Buffer\n\t\treturn func() *graphql.Response {\n\t\t\tbuf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte {\n\t\t\t\tbuf.Reset()\n\t\t\t\tdata := next()\n\n\t\t\t\tif data == nil {\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\tdata.MarshalGQL(&buf)\n\t\t\t\treturn buf.Bytes()\n\t\t\t})\n\n\t\t\tif buf == nil {\n\t\t\t\treturn nil\n\t\t\t}\n\n\t\t\treturn &graphql.Response{\n\t\t\t\tData: buf,\n\t\t\t\tErrors: ec.Errors,\n\t\t\t\tExtensions: ec.Extensions,\n\t\t\t}\n\t\t}\n\t{{- else }}\n\t\treturn graphql.OneShot(graphql.ErrorResponse(ctx, \"subscriptions are not supported\"))\n\t{{- end }}\n}\n\ntype executionContext struct {\n\t*graphql.RequestContext\n\t*executableSchema\n}\n\n{{- range $object := .Objects }}\n\t{{ template \"object.gotpl\" $object }}\n\n\t{{- range $field := $object.Fields }}\n\t\t{{ template \"field.gotpl\" $field }}\n\t{{ end }}\n{{- end}}\n\n{{- range $interface := .Interfaces }}\n\t{{ template \"interface.gotpl\" $interface }}\n{{- end }}\n\n{{- range $input := .Inputs }}\n\t{{ template \"input.gotpl\" $input }}\n{{- end }}\n\nfunc (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\tec.Error(ctx, ec.Recover(ctx, r))\n\t\t\tret = nil\n\t\t}\n\t}()\n\t{{- if .Directives }}\n\trctx := graphql.GetResolverContext(ctx)\n\tfor _, d := range rctx.Field.Definition.Directives {\n\t\tswitch d.Name {\n\t\t{{- range $directive := .Directives }}\n\t\tcase \"{{$directive.Name}}\":\n\t\t\tif ec.directives.{{$directive.Name|ucFirst}} != nil {\n\t\t\t\t{{- if $directive.Args }}\n\t\t\t\t\trawArgs := d.ArgumentMap(ec.Variables)\n\t\t\t\t\targs, err := ec.{{ $directive.ArgsFunc }}(ctx,rawArgs)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tec.Error(ctx, err)\n\t\t\t\t\t\treturn nil\n\t\t\t\t\t}\n\t\t\t\t{{- end }}\n\t\t\t\tn := next\n\t\t\t\tnext = func(ctx context.Context) (interface{}, error) {\n\t\t\t\t\treturn ec.directives.{{$directive.Name|ucFirst}}({{$directive.CallArgs}})\n\t\t\t\t}\n\t\t\t}\n\t\t{{- end }}\n\t\t}\n\t}\n\t{{- end }}\n\tres, err := ec.ResolverMiddleware(ctx, next)\n\tif err != nil {\n\t\tec.Error(ctx, err)\n\t\treturn nil\n\t}\n\treturn res\n}\n\nfunc (ec *executionContext) introspectSchema() (*introspection.Schema, error) {\n\tif ec.DisableIntrospection {\n\t\treturn nil, errors.New(\"introspection disabled\")\n\t}\n\treturn introspection.WrapSchema(parsedSchema), nil\n}\n\nfunc (ec *executionContext) introspectType(name string) (*introspection.Type, error) {\n\tif ec.DisableIntrospection {\n\t\treturn nil, errors.New(\"introspection disabled\")\n\t}\n\treturn introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil\n}\n\nvar parsedSchema = gqlparser.MustLoadSchema(\n\t{{- range $filename, $schema := .SchemaRaw }}\n\t\t&ast.Source{Name: {{$filename|quote}}, Input: {{$schema|rawQuote}}},\n\t{{- end }}\n)\n\n\n\n// ChainFieldMiddleware add chain by FieldMiddleware\n// nolint: deadcode\nfunc chainFieldMiddleware(handleFunc ...graphql.FieldMiddleware) graphql.FieldMiddleware {\n\tn := len(handleFunc)\n\n\tif n > 1 {\n\t\tlastI := n - 1\n\t\treturn func(ctx context.Context, next graphql.Resolver) (interface{}, error) {\n\t\t\tvar (\n\t\t\t\tchainHandler graphql.Resolver\n\t\t\t\tcurI int\n\t\t\t)\n\t\t\tchainHandler = func(currentCtx context.Context) (interface{}, error) {\n\t\t\t\tif curI == lastI {\n\t\t\t\t\treturn next(currentCtx)\n\t\t\t\t}\n\t\t\t\tcurI++\n\t\t\t\tres, err := handleFunc[curI](currentCtx, chainHandler)\n\t\t\t\tcurI--\n\t\t\t\treturn res, err\n\n\t\t\t}\n\t\t\treturn handleFunc[0](ctx, chainHandler)\n\t\t}\n\t}\n\n\tif n == 1 {\n\t\treturn handleFunc[0]\n\t}\n\n\treturn func(ctx context.Context, next graphql.Resolver) (interface{}, error) {\n\t\treturn next(ctx)\n\t}\n}\n", + "input.gotpl": "\t{{- if .Definition.IsMarshaled }}\n\tfunc Unmarshal{{ .Definition.GQLType }}(v interface{}) ({{.Definition.GoType | ref}}, error) {\n\t\tvar it {{.Definition.GoType | ref}}\n\t\tvar asMap = v.(map[string]interface{})\n\t\t{{ range $field := .Fields}}\n\t\t\t{{- if $field.Default}}\n\t\t\t\tif _, present := asMap[{{$field.GQLName|quote}}] ; !present {\n\t\t\t\t\tasMap[{{$field.GQLName|quote}}] = {{ $field.Default | dump }}\n\t\t\t\t}\n\t\t\t{{- end}}\n\t\t{{- end }}\n\n\t\tfor k, v := range asMap {\n\t\t\tswitch k {\n\t\t\t{{- range $field := .Fields }}\n\t\t\tcase {{$field.GQLName|quote}}:\n\t\t\t\tvar err error\n\t\t\t\t{{ $field.Unmarshal (print \"it.\" $field.GoFieldName) \"v\" }}\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn it, err\n\t\t\t\t}\n\t\t\t{{- end }}\n\t\t\t}\n\t\t}\n\n\t\treturn it, nil\n\t}\n\t{{- end }}\n\n\tfunc (e *executableSchema) {{ .Definition.GQLType }}Middleware(ctx context.Context, obj *{{.Definition.GoType | ref}}) (*{{.Definition.GoType | ref}}, error) {\n\t\t\t{{ if .Directives }}\n\t\tcObj, err := chainFieldMiddleware(\n\t\t\t[]graphql.FieldMiddleware{\n\t\t\t\t{{- range $directive := .Directives }}\n\t\t\t\t\tfunc(ctx context.Context, n graphql.Resolver) (res interface{}, err error) {\n\t\t\t\t\t{{- if $directive.Args }}\n\t\t\t\t\t{{- range $arg := $directive.Args }}\n\t\t\t\t\t\t{{- if and $arg.IsPtr ( notNil \"Value\" $arg ) }}\n\t\t\t\t\t\t\t{{ $arg.GoVarName }} := {{ $arg.Value | dump }}\n\t\t\t\t\t\t{{- end }}\n\t\t\t\t\t{{- end }}\n\t\t\t\t\t{{- end -}}\n\t\t\t\t\t\treturn e.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs \"obj\" \"n\"}})\n\t\t\t\t\t},\n\t\t\t\t{{ end }}\n\t\t\t}...\n\t\t)(ctx, func(ctx context.Context)(interface{}, error){\n\t\t\treturn obj, nil\n\t\t})\n\t\tif err != nil || cObj == nil {\n\t\t\treturn nil ,err\n\t\t}\n\t\tobj, ok := cObj.(*{{.Definition.GoType | ref}})\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"expect {{.Definition.GoType | ref}}\")\n\t\t}\n\t\t{{ end }}\n\n\t\t{{- range $field := .Fields }}\n\t\t{{ if $field.HasDirectives }}\n\t\t\tc{{$field.GoFieldName}}, err := chainFieldMiddleware(\n\t\t\t\t[]graphql.FieldMiddleware{\n\t\t\t\t\t{{- range $directive := $field.Directives }}\n\t\t\t\t\t\tfunc(ctx context.Context, n graphql.Resolver) (res interface{}, err error) {\n\t\t\t\t\t\t{{- if $directive.Args }}\n\t\t\t\t\t\t{{- range $arg := $directive.Args }}\n\t\t\t\t\t\t\t{{- if and $arg.IsPtr ( notNil \"Value\" $arg ) }}\n\t\t\t\t\t\t\t\t{{ $arg.GoVarName }} := {{ $arg.Value | dump }}\n\t\t\t\t\t\t\t{{- end }}\n\t\t\t\t\t\t{{- end }}\n\t\t\t\t\t\t{{- end }}\n\t\t\t\t\t\t\t{{ if $field.IsPtr -}}\n\t\t\t\t\t\t\t\treturn e.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs ( print \"*obj.\" $field.GoFieldName ) \"n\"}})\n\t\t\t\t\t\t\t{{- else -}}\n\t\t\t\t\t\t\t\treturn e.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs ( print \"obj.\" $field.GoFieldName ) \"n\"}})\n\t\t\t\t\t\t\t{{- end }}\n\t\t\t\t\t\t},\n\t\t\t\t\t{{ end }}\n\t\t\t\t}...\n\t\t\t)(ctx, func(ctx context.Context)(interface{}, error){\n\t\t\t\treturn {{ if $field.IsPtr }}*{{end}}obj.{{$field.GoFieldName}}, nil\n\t\t\t})\n\t\t\tif err != nil {\n\t\t\t\treturn obj ,err\n\t\t\t}\n\n\t\t\t{{ if $field.IsPtr }}\n\t\t\t\tif data, ok := c{{$field.GoFieldName}}.({{ $field.Definition.GoType | ref }}); ok {\n \t\tobj.{{$field.GoFieldName}} = &data\n \t} else {\n \t\treturn obj, errors.New(\"expect {{ $field.Signature }}\")\n \t}\n\t\t\t{{else}}\n \tif data, ok := c{{$field.GoFieldName}}.({{ $field.Signature }}); ok{\n \t\tobj.{{$field.GoFieldName}} = data\n \t}else{\n \t\treturn obj, errors.New(\"{{$field.GoFieldName}} expect {{$field.Signature }}\")\n \t}\n\t\t\t{{ end }}\n\n\t\t\t{{- end }}\n\n\t\t\t{{ if $field.Definition.IsInput }}\n\t\t\t\t{{ $field.Middleware (print \"obj.\" $field.GoFieldName ) (print \"obj.\" $field.GoFieldName ) }}\n\t\t\t{{- end }}\n\t\t{{- end }}\n\t\treturn obj, nil\n\t}\n", + "interface.gotpl": "{{- $interface := . }}\n\nfunc (ec *executionContext) _{{$interface.Definition.GQLType}}(ctx context.Context, sel ast.SelectionSet, obj *{{$interface.Definition.GoType | ref}}) graphql.Marshaler {\n\tswitch obj := (*obj).(type) {\n\tcase nil:\n\t\treturn graphql.Null\n\t{{- range $implementor := $interface.Implementors }}\n\t\t{{- if $implementor.ValueReceiver }}\n\t\t\tcase {{$implementor.Definition.GoType | ref}}:\n\t\t\t\treturn ec._{{$implementor.Definition.GQLType}}(ctx, sel, &obj)\n\t\t{{- end}}\n\t\tcase *{{$implementor.Definition.GoType | ref}}:\n\t\t\treturn ec._{{$implementor.Definition.GQLType}}(ctx, sel, obj)\n\t{{- end }}\n\tdefault:\n\t\tpanic(fmt.Errorf(\"unexpected type %T\", obj))\n\t}\n}\n", + "models.gotpl": "// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.\n\npackage {{ .PackageName }}\n\nimport (\n\t%%%IMPORTS%%%\n\n\t{{ reserveImport \"context\" }}\n\t{{ reserveImport \"fmt\" }}\n\t{{ reserveImport \"io\" }}\n\t{{ reserveImport \"strconv\" }}\n\t{{ reserveImport \"time\" }}\n\t{{ reserveImport \"sync\" }}\n\t{{ reserveImport \"errors\" }}\n\t{{ reserveImport \"bytes\" }}\n\n\t{{ reserveImport \"github.com/vektah/gqlparser\" }}\n\t{{ reserveImport \"github.com/vektah/gqlparser/ast\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql/introspection\" }}\n)\n\n{{ range $model := .Models }}\n\t{{with .Description}} {{.|prefixLines \"// \"}} {{end}}\n\t{{- if .Definition.IsInterface }}\n\t\ttype {{.Definition.GoType | ref }} interface {\n\t\t\tIs{{.Definition.GoType | ref }}()\n\t\t}\n\t{{- else }}\n\t\ttype {{.Definition.GoType | ref }} struct {\n\t\t\t{{- range $field := .Fields }}\n\t\t\t\t{{- with .Description}}\n\t\t\t\t\t{{.|prefixLines \"// \"}}\n\t\t\t\t{{- end}}\n\t\t\t\t{{ $field.GoFieldName }} {{$field.Signature}} `json:\"{{$field.GQLName}}\"`\n\t\t\t{{- end }}\n\t\t}\n\n\t\t{{- range $iface := .Implements }}\n\t\t\tfunc ({{$model.Definition.GoType | ref }}) Is{{$iface.GoType | ref }}() {}\n\t\t{{- end }}\n\n\t{{- end }}\n{{- end}}\n\n{{ range $enum := .Enums }}\n\t{{with .Description}}{{.|prefixLines \"// \"}} {{end}}\n\ttype {{.Definition.GoType | ref }} string\n\tconst (\n\t{{- range $value := .Values}}\n\t\t{{- with .Description}}\n\t\t\t{{.|prefixLines \"// \"}}\n\t\t{{- end}}\n\t\t{{$enum.Definition.GoType | ref }}{{ .Name|toCamel }} {{$enum.Definition.GoType | ref }} = {{.Name|quote}}\n\t{{- end }}\n\t)\n\n\tvar All{{.Definition.GoType | ref }} = []{{.Definition.GoType | ref }}{\n\t{{- range $value := .Values}}\n\t\t{{$enum.Definition.GoType | ref }}{{ .Name|toCamel }},\n\t{{- end }}\n\t}\n\n\tfunc (e {{.Definition.GoType | ref }}) IsValid() bool {\n\t\tswitch e {\n\t\tcase {{ range $index, $element := .Values}}{{if $index}},{{end}}{{ $enum.Definition.GoType | ref }}{{ $element.Name|toCamel }}{{end}}:\n\t\t\treturn true\n\t\t}\n\t\treturn false\n\t}\n\n\tfunc (e {{.Definition.GoType | ref }}) String() string {\n\t\treturn string(e)\n\t}\n\n\tfunc (e *{{.Definition.GoType | ref }}) UnmarshalGQL(v interface{}) error {\n\t\tstr, ok := v.(string)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"enums must be strings\")\n\t\t}\n\n\t\t*e = {{.Definition.GoType | ref }}(str)\n\t\tif !e.IsValid() {\n\t\t\treturn fmt.Errorf(\"%s is not a valid {{.Definition.GQLType}}\", str)\n\t\t}\n\t\treturn nil\n\t}\n\n\tfunc (e {{.Definition.GoType | ref }}) MarshalGQL(w io.Writer) {\n\t\tfmt.Fprint(w, strconv.Quote(e.String()))\n\t}\n\n{{- end }}\n", + "object.gotpl": "{{ $object := . }}\n\nvar {{ $object.Definition.GQLType|lcFirst}}Implementors = {{$object.Implementors}}\n\n// nolint: gocyclo, errcheck, gas, goconst\n{{- if .Stream }}\nfunc (ec *executionContext) _{{$object.Definition.GQLType}}(ctx context.Context, sel ast.SelectionSet) func() graphql.Marshaler {\n\tfields := graphql.CollectFields(ctx, sel, {{$object.Definition.GQLType|lcFirst}}Implementors)\n\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\tObject: {{$object.Definition.GQLType|quote}},\n\t})\n\tif len(fields) != 1 {\n\t\tec.Errorf(ctx, \"must subscribe to exactly one stream\")\n\t\treturn nil\n\t}\n\n\tswitch fields[0].Name {\n\t{{- range $field := $object.Fields }}\n\tcase \"{{$field.GQLName}}\":\n\t\treturn ec._{{$object.Definition.GQLType}}_{{$field.GQLName}}(ctx, fields[0])\n\t{{- end }}\n\tdefault:\n\t\tpanic(\"unknown field \" + strconv.Quote(fields[0].Name))\n\t}\n}\n{{- else }}\nfunc (ec *executionContext) _{{$object.Definition.GQLType}}(ctx context.Context, sel ast.SelectionSet{{if not $object.Root}}, obj *{{$object.Definition.GoType | ref }} {{end}}) graphql.Marshaler {\n\tfields := graphql.CollectFields(ctx, sel, {{$object.Definition.GQLType|lcFirst}}Implementors)\n\t{{if $object.Root}}\n\t\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\t\tObject: {{$object.Definition.GQLType|quote}},\n\t\t})\n\t{{end}}\n\n\tout := graphql.NewFieldSet(fields)\n\tinvalid := false\n\tfor i, field := range fields {\n\t\tswitch field.Name {\n\t\tcase \"__typename\":\n\t\t\tout.Values[i] = graphql.MarshalString({{$object.Definition.GQLType|quote}})\n\t\t{{- range $field := $object.Fields }}\n\t\tcase \"{{$field.GQLName}}\":\n\t\t\t{{- if $field.IsConcurrent }}\n\t\t\t\tfield := field\n\t\t\t\tout.Concurrently(i, func() (res graphql.Marshaler) {\n\t\t\t\t\tres = ec._{{$object.Definition.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}})\n\t\t\t\t\t{{- if $field.ASTType.NonNull }}\n\t\t\t\t\t\tif res == graphql.Null {\n\t\t\t\t\t\t\tinvalid = true\n\t\t\t\t\t\t}\n\t\t\t\t\t{{- end }}\n\t\t\t\t\treturn res\n\t\t\t\t})\n\t\t\t{{- else }}\n\t\t\t\tout.Values[i] = ec._{{$object.Definition.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}})\n\t\t\t\t{{- if $field.ASTType.NonNull }}\n\t\t\t\t\tif out.Values[i] == graphql.Null {\n\t\t\t\t\t\tinvalid = true\n\t\t\t\t\t}\n\t\t\t\t{{- end }}\n\t\t\t{{- end }}\n\t\t{{- end }}\n\t\tdefault:\n\t\t\tpanic(\"unknown field \" + strconv.Quote(field.Name))\n\t\t}\n\t}\n\tout.Dispatch()\n\tif invalid { return graphql.Null }\n\treturn out\n}\n{{- end }}\n", + "resolver.gotpl": "package {{ .PackageName }}\n\nimport (\n\t%%%IMPORTS%%%\n\n\t{{ reserveImport \"context\" }}\n\t{{ reserveImport \"fmt\" }}\n\t{{ reserveImport \"io\" }}\n\t{{ reserveImport \"strconv\" }}\n\t{{ reserveImport \"time\" }}\n\t{{ reserveImport \"sync\" }}\n\t{{ reserveImport \"errors\" }}\n\t{{ reserveImport \"bytes\" }}\n\n\t{{ reserveImport \"github.com/99designs/gqlgen/handler\" }}\n\t{{ reserveImport \"github.com/vektah/gqlparser\" }}\n\t{{ reserveImport \"github.com/vektah/gqlparser/ast\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql/introspection\" }}\n)\n\ntype {{.ResolverType}} struct {}\n\n{{ range $object := .Objects -}}\n\t{{- if $object.HasResolvers -}}\n\t\tfunc (r *{{$.ResolverType}}) {{$object.Definition.GQLType}}() {{ $object.ResolverInterface | ref }} {\n\t\t\treturn &{{lcFirst $object.Definition.GQLType}}Resolver{r}\n\t\t}\n\t{{ end -}}\n{{ end }}\n\n{{ range $object := .Objects -}}\n\t{{- if $object.HasResolvers -}}\n\t\ttype {{lcFirst $object.Definition.GQLType}}Resolver struct { *Resolver }\n\n\t\t{{ range $field := $object.Fields -}}\n\t\t\t{{- if $field.IsResolver -}}\n\t\t\tfunc (r *{{lcFirst $object.Definition.GQLType}}Resolver) {{ $field.ShortResolverDeclaration }} {\n\t\t\t\tpanic(\"not implemented\")\n\t\t\t}\n\t\t\t{{ end -}}\n\t\t{{ end -}}\n\t{{ end -}}\n{{ end }}\n", "server.gotpl": "package main\n\nimport (\n\t%%%IMPORTS%%%\n\n\t{{ reserveImport \"context\" }}\n\t{{ reserveImport \"log\" }}\n\t{{ reserveImport \"net/http\" }}\n\t{{ reserveImport \"os\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/handler\" }}\n)\n\nconst defaultPort = \"8080\"\n\nfunc main() {\n\tport := os.Getenv(\"PORT\")\n\tif port == \"\" {\n\t\tport = defaultPort\n\t}\n\n\thttp.Handle(\"/\", handler.Playground(\"GraphQL playground\", \"/query\"))\n\thttp.Handle(\"/query\", handler.GraphQL({{ lookupImport .ExecPackageName }}.NewExecutableSchema({{ lookupImport .ExecPackageName}}.Config{Resolvers: &{{ lookupImport .ResolverPackageName}}.Resolver{}})))\n\n\tlog.Printf(\"connect to http://localhost:%s/ for GraphQL playground\", port)\n\tlog.Fatal(http.ListenAndServe(\":\" + port, nil))\n}\n", } diff --git a/codegen/templates/field.gotpl b/codegen/templates/field.gotpl index 6b5d86f05a..2c1f89aa35 100644 --- a/codegen/templates/field.gotpl +++ b/codegen/templates/field.gotpl @@ -2,7 +2,7 @@ {{ $object := $field.Object }} {{- if $object.Stream }} - func (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { + func (ec *executionContext) _{{$object.Definition.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ Field: field, Args: nil, @@ -41,11 +41,11 @@ } {{ else }} // nolint: vetshadow - func (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField, {{if not $object.Root}}obj *{{$object.GoType | ref}}{{end}}) graphql.Marshaler { + func (ec *executionContext) _{{$object.Definition.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField, {{if not $object.Root}}obj *{{$object.Definition.GoType | ref}}{{end}}) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func () { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: {{$object.GQLType|quote}}, + Object: {{$object.Definition.GQLType|quote}}, Field: field, Args: nil, } diff --git a/codegen/templates/generated.gotpl b/codegen/templates/generated.gotpl index eade2d59d5..1a1c2250a4 100644 --- a/codegen/templates/generated.gotpl +++ b/codegen/templates/generated.gotpl @@ -38,7 +38,7 @@ type Config struct { type ResolverRoot interface { {{- range $object := .Objects -}} {{ if $object.HasResolvers -}} - {{$object.GQLType}}() {{$object.GQLType}}Resolver + {{$object.Definition.GQLType}}() {{$object.Definition.GQLType}}Resolver {{ end }} {{- end }} } @@ -52,7 +52,7 @@ type DirectiveRoot struct { type ComplexityRoot struct { {{ range $object := .Objects }} {{ if not $object.IsReserved -}} - {{ $object.GQLType|toCamel }} struct { + {{ $object.Definition.GQLType|toCamel }} struct { {{ range $field := $object.Fields -}} {{ if not $field.IsReserved -}} {{ $field.GQLName|toCamel }} {{ $field.ComplexitySignature }} @@ -65,7 +65,7 @@ type ComplexityRoot struct { {{ range $object := .Objects -}} {{ if $object.HasResolvers }} - type {{$object.GQLType}}Resolver interface { + type {{$object.Definition.GQLType}}Resolver interface { {{ range $field := $object.Fields -}} {{ $field.ShortResolverDeclaration }} {{ end }} @@ -107,8 +107,8 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in {{ if not $object.IsReserved }} {{ range $field := $object.Fields }} {{ if not $field.IsReserved }} - case "{{$object.GQLType}}.{{$field.GQLName}}": - if e.complexity.{{$object.GQLType|toCamel}}.{{$field.GQLName|toCamel}} == nil { + case "{{$object.Definition.GQLType}}.{{$field.GQLName}}": + if e.complexity.{{$object.Definition.GQLType|toCamel}}.{{$field.GQLName|toCamel}} == nil { break } {{ if $field.Args }} @@ -117,7 +117,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } {{ end }} - return e.complexity.{{$object.GQLType|toCamel}}.{{$field.GQLName|toCamel}}(childComplexity{{if $field.Args}}, {{$field.ComplexityArgs}} {{end}}), true + return e.complexity.{{$object.Definition.GQLType|toCamel}}.{{$field.GQLName|toCamel}}(childComplexity{{if $field.Args}}, {{$field.ComplexityArgs}} {{end}}), true {{ end }} {{ end }} {{ end }} @@ -131,7 +131,7 @@ func (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinitio ec := executionContext{graphql.GetRequestContext(ctx), e} buf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte { - data := ec._{{.QueryRoot.GQLType}}(ctx, op.SelectionSet) + data := ec._{{.QueryRoot.Definition.GQLType}}(ctx, op.SelectionSet) var buf bytes.Buffer data.MarshalGQL(&buf) return buf.Bytes() @@ -151,7 +151,7 @@ func (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefini ec := executionContext{graphql.GetRequestContext(ctx), e} buf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte { - data := ec._{{.MutationRoot.GQLType}}(ctx, op.SelectionSet) + data := ec._{{.MutationRoot.Definition.GQLType}}(ctx, op.SelectionSet) var buf bytes.Buffer data.MarshalGQL(&buf) return buf.Bytes() @@ -171,7 +171,7 @@ func (e *executableSchema) Subscription(ctx context.Context, op *ast.OperationDe {{- if .SubscriptionRoot }} ec := executionContext{graphql.GetRequestContext(ctx), e} - next := ec._{{.SubscriptionRoot.GQLType}}(ctx, op.SelectionSet) + next := ec._{{.SubscriptionRoot.Definition.GQLType}}(ctx, op.SelectionSet) if ec.Errors != nil { return graphql.OneShot(&graphql.Response{Data: []byte("null"), Errors: ec.Errors}) } diff --git a/codegen/templates/input.gotpl b/codegen/templates/input.gotpl index 7f1fd6d74e..6b9167ec74 100644 --- a/codegen/templates/input.gotpl +++ b/codegen/templates/input.gotpl @@ -1,6 +1,6 @@ - {{- if .IsMarshaled }} - func Unmarshal{{ .GQLType }}(v interface{}) ({{.GoType | ref}}, error) { - var it {{.GoType | ref}} + {{- if .Definition.IsMarshaled }} + func Unmarshal{{ .Definition.GQLType }}(v interface{}) ({{.Definition.GoType | ref}}, error) { + var it {{.Definition.GoType | ref}} var asMap = v.(map[string]interface{}) {{ range $field := .Fields}} {{- if $field.Default}} @@ -27,7 +27,7 @@ } {{- end }} - func (e *executableSchema) {{ .GQLType }}Middleware(ctx context.Context, obj *{{.GoType | ref}}) (*{{.GoType | ref}}, error) { + func (e *executableSchema) {{ .Definition.GQLType }}Middleware(ctx context.Context, obj *{{.Definition.GoType | ref}}) (*{{.Definition.GoType | ref}}, error) { {{ if .Directives }} cObj, err := chainFieldMiddleware( []graphql.FieldMiddleware{ @@ -50,9 +50,9 @@ if err != nil || cObj == nil { return nil ,err } - obj, ok := cObj.(*{{.GoType | ref}}) + obj, ok := cObj.(*{{.Definition.GoType | ref}}) if !ok { - return nil, errors.New("expect {{.GoType | ref}}") + return nil, errors.New("expect {{.Definition.GoType | ref}}") } {{ end }} @@ -85,7 +85,7 @@ } {{ if $field.IsPtr }} - if data, ok := c{{$field.GoFieldName}}.({{ $field.GoType | ref }}); ok { + if data, ok := c{{$field.GoFieldName}}.({{ $field.Definition.GoType | ref }}); ok { obj.{{$field.GoFieldName}} = &data } else { return obj, errors.New("expect {{ $field.Signature }}") @@ -100,7 +100,7 @@ {{- end }} - {{ if $field.IsInput }} + {{ if $field.Definition.IsInput }} {{ $field.Middleware (print "obj." $field.GoFieldName ) (print "obj." $field.GoFieldName ) }} {{- end }} {{- end }} diff --git a/codegen/templates/interface.gotpl b/codegen/templates/interface.gotpl index 9620f450e8..490e0f62f8 100644 --- a/codegen/templates/interface.gotpl +++ b/codegen/templates/interface.gotpl @@ -1,16 +1,16 @@ {{- $interface := . }} -func (ec *executionContext) _{{$interface.GQLType}}(ctx context.Context, sel ast.SelectionSet, obj *{{$interface.GoType | ref}}) graphql.Marshaler { +func (ec *executionContext) _{{$interface.Definition.GQLType}}(ctx context.Context, sel ast.SelectionSet, obj *{{$interface.Definition.GoType | ref}}) graphql.Marshaler { switch obj := (*obj).(type) { case nil: return graphql.Null {{- range $implementor := $interface.Implementors }} {{- if $implementor.ValueReceiver }} - case {{$implementor.GoType | ref}}: - return ec._{{$implementor.GQLType}}(ctx, sel, &obj) + case {{$implementor.Definition.GoType | ref}}: + return ec._{{$implementor.Definition.GQLType}}(ctx, sel, &obj) {{- end}} - case *{{$implementor.GoType | ref}}: - return ec._{{$implementor.GQLType}}(ctx, sel, obj) + case *{{$implementor.Definition.GoType | ref}}: + return ec._{{$implementor.Definition.GQLType}}(ctx, sel, obj) {{- end }} default: panic(fmt.Errorf("unexpected type %T", obj)) diff --git a/codegen/templates/models.gotpl b/codegen/templates/models.gotpl index 53e48e4cf6..606f732e31 100644 --- a/codegen/templates/models.gotpl +++ b/codegen/templates/models.gotpl @@ -22,12 +22,12 @@ import ( {{ range $model := .Models }} {{with .Description}} {{.|prefixLines "// "}} {{end}} - {{- if .IsInterface }} - type {{.GoType | ref }} interface { - Is{{.GoType | ref }}() + {{- if .Definition.IsInterface }} + type {{.Definition.GoType | ref }} interface { + Is{{.Definition.GoType | ref }}() } {{- else }} - type {{.GoType | ref }} struct { + type {{.Definition.GoType | ref }} struct { {{- range $field := .Fields }} {{- with .Description}} {{.|prefixLines "// "}} @@ -37,7 +37,7 @@ import ( } {{- range $iface := .Implements }} - func ({{$model.GoType | ref }}) Is{{$iface.GoType | ref }}() {} + func ({{$model.Definition.GoType | ref }}) Is{{$iface.GoType | ref }}() {} {{- end }} {{- end }} @@ -45,48 +45,48 @@ import ( {{ range $enum := .Enums }} {{with .Description}}{{.|prefixLines "// "}} {{end}} - type {{.GoType | ref }} string + type {{.Definition.GoType | ref }} string const ( {{- range $value := .Values}} {{- with .Description}} {{.|prefixLines "// "}} {{- end}} - {{$enum.GoType | ref }}{{ .Name|toCamel }} {{$enum.GoType | ref }} = {{.Name|quote}} + {{$enum.Definition.GoType | ref }}{{ .Name|toCamel }} {{$enum.Definition.GoType | ref }} = {{.Name|quote}} {{- end }} ) - var All{{.GoType | ref }} = []{{.GoType | ref }}{ + var All{{.Definition.GoType | ref }} = []{{.Definition.GoType | ref }}{ {{- range $value := .Values}} - {{$enum.GoType | ref }}{{ .Name|toCamel }}, + {{$enum.Definition.GoType | ref }}{{ .Name|toCamel }}, {{- end }} } - func (e {{.GoType | ref }}) IsValid() bool { + func (e {{.Definition.GoType | ref }}) IsValid() bool { switch e { - case {{ range $index, $element := .Values}}{{if $index}},{{end}}{{ $enum.GoType | ref }}{{ $element.Name|toCamel }}{{end}}: + case {{ range $index, $element := .Values}}{{if $index}},{{end}}{{ $enum.Definition.GoType | ref }}{{ $element.Name|toCamel }}{{end}}: return true } return false } - func (e {{.GoType | ref }}) String() string { + func (e {{.Definition.GoType | ref }}) String() string { return string(e) } - func (e *{{.GoType | ref }}) UnmarshalGQL(v interface{}) error { + func (e *{{.Definition.GoType | ref }}) UnmarshalGQL(v interface{}) error { str, ok := v.(string) if !ok { return fmt.Errorf("enums must be strings") } - *e = {{.GoType | ref }}(str) + *e = {{.Definition.GoType | ref }}(str) if !e.IsValid() { - return fmt.Errorf("%s is not a valid {{.GQLType}}", str) + return fmt.Errorf("%s is not a valid {{.Definition.GQLType}}", str) } return nil } - func (e {{.GoType | ref }}) MarshalGQL(w io.Writer) { + func (e {{.Definition.GoType | ref }}) MarshalGQL(w io.Writer) { fmt.Fprint(w, strconv.Quote(e.String())) } diff --git a/codegen/templates/object.gotpl b/codegen/templates/object.gotpl index 9f39b6b673..694faaa0bb 100644 --- a/codegen/templates/object.gotpl +++ b/codegen/templates/object.gotpl @@ -1,13 +1,13 @@ {{ $object := . }} -var {{ $object.GQLType|lcFirst}}Implementors = {{$object.Implementors}} +var {{ $object.Definition.GQLType|lcFirst}}Implementors = {{$object.Implementors}} // nolint: gocyclo, errcheck, gas, goconst {{- if .Stream }} -func (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel ast.SelectionSet) func() graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, {{$object.GQLType|lcFirst}}Implementors) +func (ec *executionContext) _{{$object.Definition.GQLType}}(ctx context.Context, sel ast.SelectionSet) func() graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, {{$object.Definition.GQLType|lcFirst}}Implementors) ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: {{$object.GQLType|quote}}, + Object: {{$object.Definition.GQLType|quote}}, }) if len(fields) != 1 { ec.Errorf(ctx, "must subscribe to exactly one stream") @@ -17,18 +17,18 @@ func (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel ast.Se switch fields[0].Name { {{- range $field := $object.Fields }} case "{{$field.GQLName}}": - return ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, fields[0]) + return ec._{{$object.Definition.GQLType}}_{{$field.GQLName}}(ctx, fields[0]) {{- end }} default: panic("unknown field " + strconv.Quote(fields[0].Name)) } } {{- else }} -func (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel ast.SelectionSet{{if not $object.Root}}, obj *{{$object.GoType | ref }} {{end}}) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, {{$object.GQLType|lcFirst}}Implementors) +func (ec *executionContext) _{{$object.Definition.GQLType}}(ctx context.Context, sel ast.SelectionSet{{if not $object.Root}}, obj *{{$object.Definition.GoType | ref }} {{end}}) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, {{$object.Definition.GQLType|lcFirst}}Implementors) {{if $object.Root}} ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: {{$object.GQLType|quote}}, + Object: {{$object.Definition.GQLType|quote}}, }) {{end}} @@ -37,13 +37,13 @@ func (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel ast.Se for i, field := range fields { switch field.Name { case "__typename": - out.Values[i] = graphql.MarshalString({{$object.GQLType|quote}}) + out.Values[i] = graphql.MarshalString({{$object.Definition.GQLType|quote}}) {{- range $field := $object.Fields }} case "{{$field.GQLName}}": {{- if $field.IsConcurrent }} field := field out.Concurrently(i, func() (res graphql.Marshaler) { - res = ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}}) + res = ec._{{$object.Definition.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}}) {{- if $field.ASTType.NonNull }} if res == graphql.Null { invalid = true @@ -52,7 +52,7 @@ func (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel ast.Se return res }) {{- else }} - out.Values[i] = ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}}) + out.Values[i] = ec._{{$object.Definition.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}}) {{- if $field.ASTType.NonNull }} if out.Values[i] == graphql.Null { invalid = true diff --git a/codegen/templates/resolver.gotpl b/codegen/templates/resolver.gotpl index 8919e329be..3cd74d1b10 100644 --- a/codegen/templates/resolver.gotpl +++ b/codegen/templates/resolver.gotpl @@ -23,19 +23,19 @@ type {{.ResolverType}} struct {} {{ range $object := .Objects -}} {{- if $object.HasResolvers -}} - func (r *{{$.ResolverType}}) {{$object.GQLType}}() {{ $object.ResolverInterface | ref }} { - return &{{lcFirst $object.GQLType}}Resolver{r} + func (r *{{$.ResolverType}}) {{$object.Definition.GQLType}}() {{ $object.ResolverInterface | ref }} { + return &{{lcFirst $object.Definition.GQLType}}Resolver{r} } {{ end -}} {{ end }} {{ range $object := .Objects -}} {{- if $object.HasResolvers -}} - type {{lcFirst $object.GQLType}}Resolver struct { *Resolver } + type {{lcFirst $object.Definition.GQLType}}Resolver struct { *Resolver } {{ range $field := $object.Fields -}} {{- if $field.IsResolver -}} - func (r *{{lcFirst $object.GQLType}}Resolver) {{ $field.ShortResolverDeclaration }} { + func (r *{{lcFirst $object.Definition.GQLType}}Resolver) {{ $field.ShortResolverDeclaration }} { panic("not implemented") } {{ end -}} diff --git a/codegen/type_definition.go b/codegen/type_definition.go index 20ab950b82..f7f68c41a7 100644 --- a/codegen/type_definition.go +++ b/codegen/type_definition.go @@ -49,12 +49,12 @@ func (n NamedTypes) getType(t *ast.Type) *TypeReference { panic("missing type " + t.NamedType) } res := &TypeReference{ - TypeDefinition: n[t.NamedType], - Modifiers: modifiers, - ASTType: orig, + Definition: n[t.NamedType], + Modifiers: modifiers, + ASTType: orig, } - if res.IsInterface { + if res.Definition.IsInterface { res.StripPtr() } diff --git a/codegen/type_reference.go b/codegen/type_reference.go index 3ba49ab02c..c8a9eb1183 100644 --- a/codegen/type_reference.go +++ b/codegen/type_reference.go @@ -11,18 +11,18 @@ import ( // TypeReference represents the type of a field or arg, referencing an underlying TypeDefinition (type, input, scalar) type TypeReference struct { - *TypeDefinition + Definition *TypeDefinition Modifiers []string ASTType *ast.Type } func (t TypeReference) Signature() string { - return strings.Join(t.Modifiers, "") + templates.CurrentImports.LookupType(t.TypeDefinition.GoType) + return strings.Join(t.Modifiers, "") + templates.CurrentImports.LookupType(t.Definition.GoType) } func (t TypeReference) FullSignature() string { - return strings.Join(t.Modifiers, "") + types.TypeString(t.TypeDefinition.GoType, nil) + return strings.Join(t.Modifiers, "") + types.TypeString(t.Definition.GoType, nil) } func (t TypeReference) IsPtr() bool { @@ -49,7 +49,7 @@ func (t TypeReference) unmarshal(result, raw string, remainingMods []string, dep switch { case len(remainingMods) > 0 && remainingMods[0] == modPtr: ptr := "ptr" + strconv.Itoa(depth) - return tpl(`var {{.ptr}} {{.mods}}{{.t.GoType | ref }} + return tpl(`var {{.ptr}} {{.mods}}{{.t.Definition.GoType | ref }} if {{.raw}} != nil { {{.next}} {{.result}} = &{{.ptr -}} @@ -83,7 +83,7 @@ func (t TypeReference) unmarshal(result, raw string, remainingMods []string, dep "rawSlice": rawIf, "index": index, "result": result, - "type": strings.Join(remainingMods, "") + templates.CurrentImports.LookupType(t.GoType), + "type": strings.Join(remainingMods, "") + templates.CurrentImports.LookupType(t.Definition.GoType), "next": t.unmarshal(result+"["+index+"]", rawIf+"["+index+"]", remainingMods[1:], depth+1), }) } @@ -91,10 +91,10 @@ func (t TypeReference) unmarshal(result, raw string, remainingMods []string, dep realResult := result return tpl(` - {{- if eq (.t.GoType | ref) "map[string]interface{}" }} + {{- if eq (.t.Definition.GoType | ref) "map[string]interface{}" }} {{- .result }} = {{.raw}}.(map[string]interface{}) - {{- else if .t.Unmarshaler }} - {{- .result }}, err = {{ .t.Unmarshaler | call }}({{.raw}}) + {{- else if .t.Definition.Unmarshaler }} + {{- .result }}, err = {{ .t.Definition.Unmarshaler | call }}({{.raw}}) {{- else -}} err = (&{{.result}}).UnmarshalGQL({{.raw}}) {{- end }}`, map[string]interface{}{ @@ -114,7 +114,7 @@ func (t TypeReference) middleware(result, raw string, remainingMods []string, de return tpl(` if {{.raw}} != nil { var err error - {{.result}}, err = e.{{ .t.GQLType }}Middleware(ctx, {{.raw}}) + {{.result}}, err = e.{{ .t.Definition.GQLType }}Middleware(ctx, {{.raw}}) if err != nil { return nil, err } @@ -145,14 +145,14 @@ func (t TypeReference) middleware(result, raw string, remainingMods []string, de "raw": raw, "index": index, "result": result, - "type": strings.Join(remainingMods, "") + templates.CurrentImports.LookupType(t.TypeDefinition.GoType), + "type": strings.Join(remainingMods, "") + templates.CurrentImports.LookupType(t.Definition.GoType), "next": t.middleware(result+"["+index+"]", raw+"["+index+"]", remainingMods[1:], depth+1), }) } - ptr := "m" + t.GQLType + strconv.Itoa(depth) + ptr := "m" + t.Definition.GQLType + strconv.Itoa(depth) return tpl(` - {{.ptr}}, err := e.{{ .t.GQLType }}Middleware(ctx, &{{.raw}}) + {{.ptr}}, err := e.{{ .t.Definition.GQLType }}Middleware(ctx, &{{.raw}}) if err != nil { return nil, err } @@ -165,8 +165,8 @@ func (t TypeReference) middleware(result, raw string, remainingMods []string, de } func (t TypeReference) Marshal(val string) string { - if t.Marshaler != nil { - return "return " + templates.Call(t.TypeDefinition.Marshaler) + "(" + val + ")" + if t.Definition.Marshaler != nil { + return "return " + templates.Call(t.Definition.Marshaler) + "(" + val + ")" } return "return " + val diff --git a/codegen/util.go b/codegen/util.go index e734e77c58..2c91b45ccb 100644 --- a/codegen/util.go +++ b/codegen/util.go @@ -184,7 +184,7 @@ type BindError struct { func (b BindError) Error() string { return fmt.Sprintf( "Unable to bind %s.%s to %s\n %s\n %s", - b.object.GQLType, + b.object.Definition.GQLType, b.field.GQLName, b.typ.String(), b.methodErr.Error(), @@ -212,18 +212,18 @@ func bindObject(object *Object, structTag string) BindErrors { } // first try binding to a method - methodErr := bindMethod(object.GoType, field) + methodErr := bindMethod(object.Definition.GoType, field) if methodErr == nil { continue } // otherwise try binding to a var - varErr := bindVar(object.GoType, field, structTag) + varErr := bindVar(object.Definition.GoType, field, structTag) if varErr != nil { errs = append(errs, BindError{ object: object, - typ: object.GoType, + typ: object.Definition.GoType, field: field, varErr: varErr, methodErr: methodErr,