From 3a729cc3c60f1aafdee405513d43cdf43693269d Mon Sep 17 00:00:00 2001 From: asamusev Date: Sat, 1 Dec 2018 22:54:38 +0300 Subject: [PATCH] update recursive middleware --- codegen/templates/args.gotpl | 15 +- codegen/templates/data.go | 4 +- codegen/templates/input.gotpl | 38 +--- codegen/testserver/generated.go | 368 +++++++++++++++----------------- codegen/type.go | 58 +++++ 5 files changed, 242 insertions(+), 241 deletions(-) diff --git a/codegen/templates/args.gotpl b/codegen/templates/args.gotpl index ec89c9aa112..b4f11857af5 100644 --- a/codegen/templates/args.gotpl +++ b/codegen/templates/args.gotpl @@ -37,20 +37,7 @@ {{ end }} {{- if $arg.IsInput }} - {{ if $arg.IsPtr }} - if arg{{$i}} != nil { - arg{{$i}}, err = e.{{ .GQLType }}Middleware(ctx, arg{{$i}}) - if err != nil { - return nil, err - } - } - {{ else }} - args{{$i}}, err := e.{{ .GQLType }}Middleware(ctx, &arg{{$i}}) - if err != nil { - return nil, err - } - arg{{$i}} = *args{{$i}} - {{ end }} + {{ $arg.Middleware (print "arg" $i) (print "arg" $i) }} {{- end }} {{ else }} diff --git a/codegen/templates/data.go b/codegen/templates/data.go index 3f9239d5df1..677d51ea534 100644 --- a/codegen/templates/data.go +++ b/codegen/templates/data.go @@ -1,10 +1,10 @@ package templates var data = map[string]string{ - "args.gotpl": "\targs := map[string]interface{}{}\n\tvar err error\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 or $arg.Directives $arg.IsInput }}\n\t\t\t\t{{ if $arg.Directives }}\n \targm{{$i}}, err := graphql.ChainFieldMiddleware([]graphql.FieldMiddleware{\n\t\t\t\t\t{{- range $directive := $arg.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{{- range $dArg := $directive.Args }}\n\t\t\t\t\t\t\t{{- if and $dArg.IsPtr $dArg.Value }}{{ $dArg.GoVarName }} := {{ $dArg.Value }}{{ end -}}\n\t\t\t\t\t\t{{- end }}\n\t\t\t\t\t\t\treturn e.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs \"tmp\" \"n\" }})\n\t\t\t\t\t\t},\n\t\t\t\t\t{{- end }}\n\t\t\t\t\t}...)(ctx, func(ctx2 context.Context)(args{{$i}} interface{},err error){\n\t\t\t\t\t{{$arg.Unmarshal (print \"args\" $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\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\t{{ else }}\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{{ end }}\n\n\t\t\t\t{{- if $arg.IsInput }}\n\t\t\t\t\t{{ if $arg.IsPtr }}\n\t\t\t\t\t\tif arg{{$i}} != nil {\n\t\t\t\t\t\t\targ{{$i}}, err = e.{{ .GQLType }}Middleware(ctx, arg{{$i}})\n\t\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t{{ else }}\n\t\t\t\t\t\targs{{$i}}, err := e.{{ .GQLType }}Middleware(ctx, &arg{{$i}})\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t\t}\n\t\t\t\t\t\targ{{$i}} = *args{{$i}}\n\t\t\t\t\t{{ end }}\n\t\t\t\t{{- end }}\n\n\t\t\t{{ else }}\n\t\t\t{{$arg.Unmarshal (print \"arg\" $i) \"tmp\" }}\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\t{{- end }}\n\t\t}\n\t\targs[{{$arg.GQLName|quote}}] = arg{{$i}}\n\t{{- end }}\n\treturn args, err\n", + "args.gotpl": "\targs := map[string]interface{}{}\n\tvar err error\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 or $arg.Directives $arg.IsInput }}\n\t\t\t\t{{ if $arg.Directives }}\n \targm{{$i}}, err := graphql.ChainFieldMiddleware([]graphql.FieldMiddleware{\n\t\t\t\t\t{{- range $directive := $arg.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{{- range $dArg := $directive.Args }}\n\t\t\t\t\t\t\t{{- if and $dArg.IsPtr $dArg.Value }}{{ $dArg.GoVarName }} := {{ $dArg.Value }}{{ end -}}\n\t\t\t\t\t\t{{- end }}\n\t\t\t\t\t\t\treturn e.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs \"tmp\" \"n\" }})\n\t\t\t\t\t\t},\n\t\t\t\t\t{{- end }}\n\t\t\t\t\t}...)(ctx, func(ctx2 context.Context)(args{{$i}} interface{},err error){\n\t\t\t\t\t{{$arg.Unmarshal (print \"args\" $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\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\t{{ else }}\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{{ end }}\n\n\t\t\t\t{{- if $arg.IsInput }}\n\t\t\t\t\t {{ $arg.Middleware (print \"arg\" $i) (print \"arg\" $i) }}\n\t\t\t\t{{- end }}\n\n\t\t\t{{ else }}\n\t\t\t{{$arg.Unmarshal (print \"arg\" $i) \"tmp\" }}\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\t{{- end }}\n\t\t}\n\t\targs[{{$arg.GQLName|quote}}] = arg{{$i}}\n\t{{- end }}\n\treturn args, err\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})\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\tvar out graphql.OrderedMap\n\t\t\tout.Add(field.Alias, func() graphql.Marshaler { {{ $field.WriteJson }} }())\n\t\t\treturn &out\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.FullName}}{{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}\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", - "input.gotpl": "\t{{- if .IsMarshaled }}\n\tfunc Unmarshal{{ .GQLType }}(v interface{}) ({{.FullName}}, error) {\n\t\tvar it {{.FullName}}\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 *{{.FullName}}) (*{{.FullName}}, error) {\n\t\tvar err error\n\t\t{{ if .Directives }}\n\t\tcObj, err := graphql.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 $arg.Value }}\n\t\t\t\t\t\t\t{{$arg.GoVarName}}:={{ $arg.Value | dump}}\n\t\t\t\t\t\t{{ else if and $arg.IsPtr $arg.Default }}\n\t\t\t\t\t\t\t{{$arg.GoVarName}}:={{ $arg.Default | 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.(*{{.FullName}})\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"expect {{.FullName}}\")\n\t\t}\n\t\t{{ end }}\n\n\t\t{{- range $field := .Fields }}\n\t\t{{ if $field.HasDirectives }}\n\t\t{{ $resolveName := \"\" }}\n\t\t{{ $declareName := \"\" }}\n\t\t{{ if $field.IsPtr }}\n\t\t\t{{ $resolveName = \"*\" }}\n\t\t\t{{ $declareName = \"&\" }}\n\t\t{{ end }}\n\t\t\tc{{$field.GoFieldName}}, err := graphql.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 $arg.Value }}\n\t\t\t\t\t\t\t\t{{$arg.GoVarName}}:={{ $arg.Value | dump}}\n\t\t\t\t\t\t\t{{ else if and $arg.IsPtr $arg.Default }}\n\t\t\t\t\t\t\t\t{{$arg.GoVarName}}:={{ $arg.Default | 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\treturn e.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs ( print $resolveName \"obj.\" $field.GoFieldName ) \"n\"}})\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 {{$resolveName}}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.FullName }}); 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\t\t{{ if $field.IsInput }}\n\n \t\t{{ if and $field.IsPtr (not $field.IsSlice) }}\n \t\t\tif obj.{{$field.GoFieldName}} != nil {\n \t\t\t\tobj.{{$field.GoFieldName}}, err = e.{{ $field.GQLType }}Middleware(ctx, obj.{{$field.GoFieldName}})\n \t\t\t\tif err != nil {\n \t\t\t\t\treturn obj, err\n \t\t\t\t}\n \t\t\t}\n \t\t{{ else if $field.IsSlice }}\n \t\t\tfor i := range obj.{{$field.GoFieldName}} {\n \t\t\t {{ if eq ($field.Modifiers|len) 2 }}\n \t\t\t\t if obj.{{$field.GoFieldName}}[i] != nil {\n \t\t\t\t\tobj.{{$field.GoFieldName}}[i], err = e.{{ $field.GQLType }}Middleware(ctx, obj.{{$field.GoFieldName}}[i])\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 }\n \t\t\t{{ else }}\n \t\t\t\titd, err := e.{{ $field.GQLType }}Middleware(ctx, &obj.{{$field.GoFieldName}}[i])\n \t\t\t\tif err != nil {\n \t\t\t\t\treturn nil, err\n \t\t\t\t}\n \t\t\t\tobj.{{$field.GoFieldName}}[i] = *itd\n \t\t\t{{ end }}\n \t\t\t}\n \t\t\t{{ else }}\n \t\t\t{{$field.GoFieldName}}, err := e.{{ $field.GQLType }}Middleware(ctx, &obj.{{$field.GoFieldName}})\n \t\t\tif err != nil {\n \t\t\t\treturn obj, err\n \t\t\t}\n \t\t\tobj.{{$field.GoFieldName}} = *{{$field.GoFieldName}}\n \t\t{{ end }}\n \t\t{{ end }}\n\n\t\t{{- end }}\n\t\treturn obj, err\n\t}\n", + "input.gotpl": "\t{{- if .IsMarshaled }}\n\tfunc Unmarshal{{ .GQLType }}(v interface{}) ({{.FullName}}, error) {\n\t\tvar it {{.FullName}}\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 *{{.FullName}}) (*{{.FullName}}, error) {\n\t\tvar err error\n\t\t{{ if .Directives }}\n\t\tcObj, err := graphql.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 $arg.Value }}\n\t\t\t\t\t\t\t{{$arg.GoVarName}}:={{ $arg.Value | dump}}\n\t\t\t\t\t\t{{ else if and $arg.IsPtr $arg.Default }}\n\t\t\t\t\t\t\t{{$arg.GoVarName}}:={{ $arg.Default | 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.(*{{.FullName}})\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"expect {{.FullName}}\")\n\t\t}\n\t\t{{ end }}\n\n\t\t{{- range $field := .Fields }}\n\t\t{{ if $field.HasDirectives }}\n\t\t{{ $resolveName := \"\" }}\n\t\t{{ $declareName := \"\" }}\n\t\t{{ if $field.IsPtr }}\n\t\t\t{{ $resolveName = \"*\" }}\n\t\t\t{{ $declareName = \"&\" }}\n\t\t{{ end }}\n\t\t\tc{{$field.GoFieldName}}, err := graphql.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 $arg.Value }}\n\t\t\t\t\t\t\t\t{{$arg.GoVarName}}:={{ $arg.Value | dump}}\n\t\t\t\t\t\t\t{{ else if and $arg.IsPtr $arg.Default }}\n\t\t\t\t\t\t\t\t{{$arg.GoVarName}}:={{ $arg.Default | 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\treturn e.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs ( print $resolveName \"obj.\" $field.GoFieldName ) \"n\"}})\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 {{$resolveName}}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.FullName }}); 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, err\n\t}\n", "interface.gotpl": "{{- $interface := . }}\n\nfunc (ec *executionContext) _{{$interface.GQLType}}(ctx context.Context, sel ast.SelectionSet, obj *{{$interface.FullName}}) 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.FullName}}:\n\t\t\t\treturn ec._{{$implementor.GQLType}}(ctx, sel, &obj)\n\t\t{{- end}}\n\t\tcase *{{$implementor.FullName}}:\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}} interface {\n\t\t\tIs{{.GoType}}()\n\t\t}\n\t{{- else }}\n\t\ttype {{.GoType}} 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{{- if $field.GoFieldName }}\n\t\t\t\t\t{{ $field.GoFieldName }} {{$field.Signature}} `json:\"{{$field.GQLName}}\"`\n\t\t\t\t{{- else }}\n\t\t\t\t\t{{ $field.GoFKName }} {{$field.GoFKType}}\n\t\t\t\t{{- end }}\n\t\t\t{{- end }}\n\t\t}\n\n\t\t{{- range $iface := .Implements }}\n\t\t\tfunc ({{$model.GoType}}) Is{{$iface.GoType}}() {}\n\t\t{{- end }}\n\n\t{{- end }}\n{{- end}}\n\n{{ range $enum := .Enums }}\n\t{{with .Description}}{{.|prefixLines \"// \"}} {{end}}\n\ttype {{.GoType}} 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}}{{ .Name|toCamel }} {{$enum.GoType}} = {{.Name|quote}}\n\t{{- end }}\n\t)\n\n\tfunc (e {{.GoType}}) IsValid() bool {\n\t\tswitch e {\n\t\tcase {{ range $index, $element := .Values}}{{if $index}},{{end}}{{ $enum.GoType }}{{ $element.Name|toCamel }}{{end}}:\n\t\t\treturn true\n\t\t}\n\t\treturn false\n\t}\n\n\tfunc (e {{.GoType}}) String() string {\n\t\treturn string(e)\n\t}\n\n\tfunc (e *{{.GoType}}) 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}}(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}}) 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.FullName}} {{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\t{{if $object.IsConcurrent}} var wg sync.WaitGroup {{end}}\n\tout := graphql.NewOrderedMap(len(fields))\n\tinvalid := false\n\tfor i, field := range fields {\n\t\tout.Keys[i] = field.Alias\n\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\twg.Add(1)\n\t\t\t\tgo func(i int, field graphql.CollectedField) {\n\t\t\t{{- end }}\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{{- if $field.IsConcurrent }}\n\t\t\t\t\twg.Done()\n\t\t\t\t}(i, field)\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\t{{if $object.IsConcurrent}} wg.Wait() {{end}}\n\tif invalid { return graphql.Null }\n\treturn out\n}\n{{- end }}\n", diff --git a/codegen/templates/input.gotpl b/codegen/templates/input.gotpl index e837300c7f5..4fec239adcb 100644 --- a/codegen/templates/input.gotpl +++ b/codegen/templates/input.gotpl @@ -107,41 +107,9 @@ {{- end }} - {{ if $field.IsInput }} - - {{ if and $field.IsPtr (not $field.IsSlice) }} - if obj.{{$field.GoFieldName}} != nil { - obj.{{$field.GoFieldName}}, err = e.{{ $field.GQLType }}Middleware(ctx, obj.{{$field.GoFieldName}}) - if err != nil { - return obj, err - } - } - {{ else if $field.IsSlice }} - for i := range obj.{{$field.GoFieldName}} { - {{ if eq ($field.Modifiers|len) 2 }} - if obj.{{$field.GoFieldName}}[i] != nil { - obj.{{$field.GoFieldName}}[i], err = e.{{ $field.GQLType }}Middleware(ctx, obj.{{$field.GoFieldName}}[i]) - if err != nil { - return nil, err - } - } - {{ else }} - itd, err := e.{{ $field.GQLType }}Middleware(ctx, &obj.{{$field.GoFieldName}}[i]) - if err != nil { - return nil, err - } - obj.{{$field.GoFieldName}}[i] = *itd - {{ end }} - } - {{ else }} - {{$field.GoFieldName}}, err := e.{{ $field.GQLType }}Middleware(ctx, &obj.{{$field.GoFieldName}}) - if err != nil { - return obj, err - } - obj.{{$field.GoFieldName}} = *{{$field.GoFieldName}} - {{ end }} - {{ end }} - + {{ if $field.IsInput }} + {{ $field.Middleware (print "obj." $field.GoFieldName ) (print "obj." $field.GoFieldName ) }} + {{- end }} {{- end }} return obj, err } diff --git a/codegen/testserver/generated.go b/codegen/testserver/generated.go index 3f97c620b14..f4071db5d79 100644 --- a/codegen/testserver/generated.go +++ b/codegen/testserver/generated.go @@ -152,11 +152,12 @@ type UserResolver interface { Friends(ctx context.Context, obj *User) ([]User, error) } -func field_Query_mapInput_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { +func (e *executableSchema) field_Query_mapInput_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { args := map[string]interface{}{} + var err error var arg0 *map[string]interface{} if tmp, ok := rawArgs["input"]; ok { - var err error + var ptr1 map[string]interface{} if tmp != nil { ptr1 = tmp.(map[string]interface{}) @@ -166,17 +167,19 @@ func field_Query_mapInput_args(rawArgs map[string]interface{}) (map[string]inter if err != nil { return nil, err } + } args["input"] = arg0 - return args, nil + return args, err } -func field_Query_recursive_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { +func (e *executableSchema) field_Query_recursive_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { args := map[string]interface{}{} + var err error var arg0 *RecursiveInputSlice if tmp, ok := rawArgs["input"]; ok { - var err error + var ptr1 RecursiveInputSlice if tmp != nil { ptr1, err = UnmarshalRecursiveInputSlice(tmp) @@ -186,17 +189,24 @@ func field_Query_recursive_args(rawArgs map[string]interface{}) (map[string]inte if err != nil { return nil, err } + + arg0, err = e.RecursiveInputSliceMiddleware(ctx, arg0) + if err != nil { + return nil, err + } + } args["input"] = arg0 - return args, nil + return args, err } -func field_Query_nestedInputs_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { +func (e *executableSchema) field_Query_nestedInputs_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { args := map[string]interface{}{} + var err error var arg0 [][]*OuterInput if tmp, ok := rawArgs["input"]; ok { - var err error + var rawIf1 []interface{} if tmp != nil { if tmp1, ok := tmp.([]interface{}); ok { @@ -227,17 +237,29 @@ func field_Query_nestedInputs_args(rawArgs map[string]interface{}) (map[string]i if err != nil { return nil, err } + + for idx1 := range arg0 { + for idx2 := range arg0[idx1] { + + arg0[idx1][idx2], err = e.OuterInputMiddleware(ctx, arg0[idx1][idx2]) + if err != nil { + return nil, err + } + } + } + } args["input"] = arg0 - return args, nil + return args, err } -func field_Query_keywords_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { +func (e *executableSchema) field_Query_keywords_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { args := map[string]interface{}{} + var err error var arg0 *Keywords if tmp, ok := rawArgs["input"]; ok { - var err error + var ptr1 Keywords if tmp != nil { ptr1, err = UnmarshalKeywords(tmp) @@ -247,32 +269,38 @@ func field_Query_keywords_args(rawArgs map[string]interface{}) (map[string]inter if err != nil { return nil, err } + + arg0, err = e.KeywordsMiddleware(ctx, arg0) + if err != nil { + return nil, err + } + } args["input"] = arg0 - return args, nil + return args, err } -func field_Query_user_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { +func (e *executableSchema) field_Query_user_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { args := map[string]interface{}{} + var err error var arg0 int if tmp, ok := rawArgs["id"]; ok { - var err error arg0, err = graphql.UnmarshalInt(tmp) if err != nil { return nil, err } } args["id"] = arg0 - return args, nil + return args, err } -func field_Query_nullableArg_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { +func (e *executableSchema) field_Query_nullableArg_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { args := map[string]interface{}{} + var err error var arg0 *int if tmp, ok := rawArgs["arg"]; ok { - var err error var ptr1 int if tmp != nil { ptr1, err = graphql.UnmarshalInt(tmp) @@ -284,15 +312,15 @@ func field_Query_nullableArg_args(rawArgs map[string]interface{}) (map[string]in } } args["arg"] = arg0 - return args, nil + return args, err } -func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { +func (e *executableSchema) field_Query_keywordArgs_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { args := map[string]interface{}{} + var err error var arg0 string if tmp, ok := rawArgs["break"]; ok { - var err error arg0, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -301,7 +329,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["break"] = arg0 var arg1 string if tmp, ok := rawArgs["default"]; ok { - var err error arg1, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -310,7 +337,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["default"] = arg1 var arg2 string if tmp, ok := rawArgs["func"]; ok { - var err error arg2, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -319,7 +345,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["func"] = arg2 var arg3 string if tmp, ok := rawArgs["interface"]; ok { - var err error arg3, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -328,7 +353,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["interface"] = arg3 var arg4 string if tmp, ok := rawArgs["select"]; ok { - var err error arg4, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -337,7 +361,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["select"] = arg4 var arg5 string if tmp, ok := rawArgs["case"]; ok { - var err error arg5, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -346,7 +369,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["case"] = arg5 var arg6 string if tmp, ok := rawArgs["defer"]; ok { - var err error arg6, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -355,7 +377,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["defer"] = arg6 var arg7 string if tmp, ok := rawArgs["go"]; ok { - var err error arg7, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -364,7 +385,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["go"] = arg7 var arg8 string if tmp, ok := rawArgs["map"]; ok { - var err error arg8, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -373,7 +393,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["map"] = arg8 var arg9 string if tmp, ok := rawArgs["struct"]; ok { - var err error arg9, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -382,7 +401,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["struct"] = arg9 var arg10 string if tmp, ok := rawArgs["chan"]; ok { - var err error arg10, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -391,7 +409,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["chan"] = arg10 var arg11 string if tmp, ok := rawArgs["else"]; ok { - var err error arg11, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -400,7 +417,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["else"] = arg11 var arg12 string if tmp, ok := rawArgs["goto"]; ok { - var err error arg12, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -409,7 +425,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["goto"] = arg12 var arg13 string if tmp, ok := rawArgs["package"]; ok { - var err error arg13, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -418,7 +433,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["package"] = arg13 var arg14 string if tmp, ok := rawArgs["switch"]; ok { - var err error arg14, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -427,7 +441,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["switch"] = arg14 var arg15 string if tmp, ok := rawArgs["const"]; ok { - var err error arg15, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -436,7 +449,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["const"] = arg15 var arg16 string if tmp, ok := rawArgs["fallthrough"]; ok { - var err error arg16, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -445,7 +457,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["fallthrough"] = arg16 var arg17 string if tmp, ok := rawArgs["if"]; ok { - var err error arg17, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -454,7 +465,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["if"] = arg17 var arg18 string if tmp, ok := rawArgs["range"]; ok { - var err error arg18, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -463,7 +473,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["range"] = arg18 var arg19 string if tmp, ok := rawArgs["type"]; ok { - var err error arg19, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -472,7 +481,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["type"] = arg19 var arg20 string if tmp, ok := rawArgs["continue"]; ok { - var err error arg20, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -481,7 +489,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["continue"] = arg20 var arg21 string if tmp, ok := rawArgs["for"]; ok { - var err error arg21, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -490,7 +497,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["for"] = arg21 var arg22 string if tmp, ok := rawArgs["import"]; ok { - var err error arg22, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -499,7 +505,6 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["import"] = arg22 var arg23 string if tmp, ok := rawArgs["return"]; ok { - var err error arg23, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err @@ -508,59 +513,58 @@ func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]in args["return"] = arg23 var arg24 string if tmp, ok := rawArgs["var"]; ok { - var err error arg24, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err } } args["var"] = arg24 - return args, nil + return args, err } -func field_Query___type_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { +func (e *executableSchema) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { args := map[string]interface{}{} + var err error var arg0 string if tmp, ok := rawArgs["name"]; ok { - var err error arg0, err = graphql.UnmarshalString(tmp) if err != nil { return nil, err } } args["name"] = arg0 - return args, nil + return args, err } -func field___Type_fields_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { +func (e *executableSchema) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { args := map[string]interface{}{} + var err error var arg0 bool if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { return nil, err } } args["includeDeprecated"] = arg0 - return args, nil + return args, err } -func field___Type_enumValues_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { +func (e *executableSchema) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { args := map[string]interface{}{} + var err error var arg0 bool if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { return nil, err } } args["includeDeprecated"] = arg0 - return args, nil + return args, err } @@ -708,7 +712,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in break } - args, err := field_Query_mapInput_args(rawArgs) + args, err := e.field_Query_mapInput_args(context.TODO(), rawArgs) if err != nil { return 0, false } @@ -720,7 +724,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in break } - args, err := field_Query_recursive_args(rawArgs) + args, err := e.field_Query_recursive_args(context.TODO(), rawArgs) if err != nil { return 0, false } @@ -732,7 +736,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in break } - args, err := field_Query_nestedInputs_args(rawArgs) + args, err := e.field_Query_nestedInputs_args(context.TODO(), rawArgs) if err != nil { return 0, false } @@ -751,7 +755,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in break } - args, err := field_Query_keywords_args(rawArgs) + args, err := e.field_Query_keywords_args(context.TODO(), rawArgs) if err != nil { return 0, false } @@ -791,7 +795,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in break } - args, err := field_Query_user_args(rawArgs) + args, err := e.field_Query_user_args(context.TODO(), rawArgs) if err != nil { return 0, false } @@ -803,7 +807,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in break } - args, err := field_Query_nullableArg_args(rawArgs) + args, err := e.field_Query_nullableArg_args(context.TODO(), rawArgs) if err != nil { return 0, false } @@ -815,7 +819,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in break } - args, err := field_Query_keywordArgs_args(rawArgs) + args, err := e.field_Query_keywordArgs_args(context.TODO(), rawArgs) if err != nil { return 0, false } @@ -968,7 +972,6 @@ func (ec *executionContext) _Circle_radius(ctx context.Context, field graphql.Co defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Circle", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -992,7 +995,6 @@ func (ec *executionContext) _Circle_area(ctx context.Context, field graphql.Coll defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Circle", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1045,7 +1047,6 @@ func (ec *executionContext) _EmbeddedPointer_ID(ctx context.Context, field graph defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "EmbeddedPointer", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1069,7 +1070,6 @@ func (ec *executionContext) _EmbeddedPointer_Title(ctx context.Context, field gr defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "EmbeddedPointer", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1135,7 +1135,6 @@ func (ec *executionContext) _Error_id(ctx context.Context, field graphql.Collect defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Error", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1162,7 +1161,6 @@ func (ec *executionContext) _Error_errorOnNonRequiredField(ctx context.Context, defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Error", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1186,7 +1184,6 @@ func (ec *executionContext) _Error_errorOnRequiredField(ctx context.Context, fie defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Error", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1213,7 +1210,6 @@ func (ec *executionContext) _Error_nilOnRequiredField(ctx context.Context, field defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Error", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1279,7 +1275,6 @@ func (ec *executionContext) _ForcedResolver_field(ctx context.Context, field gra defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "ForcedResolver", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1338,7 +1333,6 @@ func (ec *executionContext) _InnerObject_id(ctx context.Context, field graphql.C defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "InnerObject", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1395,7 +1389,6 @@ func (ec *executionContext) _InvalidIdentifier_id(ctx context.Context, field gra defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "InvalidIdentifier", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1452,7 +1445,6 @@ func (ec *executionContext) _It_id(ctx context.Context, field graphql.CollectedF defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "It", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1528,7 +1520,6 @@ func (ec *executionContext) _ModelMethods_resolverField(ctx context.Context, fie defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "ModelMethods", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1555,7 +1546,6 @@ func (ec *executionContext) _ModelMethods_noContext(ctx context.Context, field g defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "ModelMethods", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1582,7 +1572,6 @@ func (ec *executionContext) _ModelMethods_withContext(ctx context.Context, field defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "ModelMethods", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1639,7 +1628,6 @@ func (ec *executionContext) _OuterObject_inner(ctx context.Context, field graphq defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "OuterObject", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1797,7 +1785,6 @@ func (ec *executionContext) _Query_invalidIdentifier(ctx context.Context, field defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Query", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1826,7 +1813,6 @@ func (ec *executionContext) _Query_collision(ctx context.Context, field graphql. defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Query", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -1853,18 +1839,18 @@ func (ec *executionContext) _Query_collision(ctx context.Context, field graphql. func (ec *executionContext) _Query_mapInput(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_mapInput_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ Object: "Query", - Args: args, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_mapInput_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -1887,18 +1873,18 @@ func (ec *executionContext) _Query_mapInput(ctx context.Context, field graphql.C func (ec *executionContext) _Query_recursive(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_recursive_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ Object: "Query", - Args: args, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_recursive_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -1921,18 +1907,18 @@ func (ec *executionContext) _Query_recursive(ctx context.Context, field graphql. func (ec *executionContext) _Query_nestedInputs(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_nestedInputs_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ Object: "Query", - Args: args, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_nestedInputs_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -1957,7 +1943,6 @@ func (ec *executionContext) _Query_nestedOutputs(ctx context.Context, field grap defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Query", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2047,18 +2032,18 @@ func (ec *executionContext) _Query_nestedOutputs(ctx context.Context, field grap func (ec *executionContext) _Query_keywords(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_keywords_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ Object: "Query", - Args: args, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_keywords_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2082,7 +2067,6 @@ func (ec *executionContext) _Query_shapes(ctx context.Context, field graphql.Col defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Query", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2143,7 +2127,6 @@ func (ec *executionContext) _Query_errorBubble(ctx context.Context, field graphq defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Query", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2172,7 +2155,6 @@ func (ec *executionContext) _Query_modelMethods(ctx context.Context, field graph defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Query", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2201,7 +2183,6 @@ func (ec *executionContext) _Query_valid(ctx context.Context, field graphql.Coll defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Query", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2226,18 +2207,18 @@ func (ec *executionContext) _Query_valid(ctx context.Context, field graphql.Coll func (ec *executionContext) _Query_user(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_user_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ Object: "Query", - Args: args, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_user_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2260,18 +2241,18 @@ func (ec *executionContext) _Query_user(ctx context.Context, field graphql.Colle func (ec *executionContext) _Query_nullableArg(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_nullableArg_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ Object: "Query", - Args: args, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_nullableArg_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2294,18 +2275,18 @@ func (ec *executionContext) _Query_nullableArg(ctx context.Context, field graphq func (ec *executionContext) _Query_keywordArgs(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_keywordArgs_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ Object: "Query", - Args: args, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_keywordArgs_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2327,18 +2308,18 @@ func (ec *executionContext) _Query_keywordArgs(ctx context.Context, field graphq func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query___type_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ Object: "Query", - Args: args, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query___type_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2364,7 +2345,6 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Query", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2424,7 +2404,6 @@ func (ec *executionContext) _Rectangle_length(ctx context.Context, field graphql defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Rectangle", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2448,7 +2427,6 @@ func (ec *executionContext) _Rectangle_width(ctx context.Context, field graphql. defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Rectangle", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2472,7 +2450,6 @@ func (ec *executionContext) _Rectangle_area(ctx context.Context, field graphql.C defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "Rectangle", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2605,7 +2582,6 @@ func (ec *executionContext) _User_id(ctx context.Context, field graphql.Collecte defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "User", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2632,7 +2608,6 @@ func (ec *executionContext) _User_friends(ctx context.Context, field graphql.Col defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "User", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2734,7 +2709,6 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Directive", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2761,7 +2735,6 @@ func (ec *executionContext) ___Directive_description(ctx context.Context, field defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Directive", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2785,7 +2758,6 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Directive", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2821,7 +2793,6 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Directive", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2920,7 +2891,6 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__EnumValue", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2947,7 +2917,6 @@ func (ec *executionContext) ___EnumValue_description(ctx context.Context, field defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__EnumValue", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2971,7 +2940,6 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__EnumValue", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -2998,7 +2966,6 @@ func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__EnumValue", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3075,7 +3042,6 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Field", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3102,7 +3068,6 @@ func (ec *executionContext) ___Field_description(ctx context.Context, field grap defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Field", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3126,7 +3091,6 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Field", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3186,7 +3150,6 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Field", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3221,7 +3184,6 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Field", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3248,7 +3210,6 @@ func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, fiel defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Field", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3315,7 +3276,6 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__InputValue", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3342,7 +3302,6 @@ func (ec *executionContext) ___InputValue_description(ctx context.Context, field defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__InputValue", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3366,7 +3325,6 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__InputValue", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3401,7 +3359,6 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__InputValue", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3473,7 +3430,6 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Schema", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3533,7 +3489,6 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Schema", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3568,7 +3523,6 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Schema", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3597,7 +3551,6 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Schema", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3626,7 +3579,6 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Schema", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3732,7 +3684,6 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Type", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3759,7 +3710,6 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Type", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3787,7 +3737,6 @@ func (ec *executionContext) ___Type_description(ctx context.Context, field graph defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Type", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3809,18 +3758,18 @@ func (ec *executionContext) ___Type_description(ctx context.Context, field graph func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_fields_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ Object: "__Type", - Args: args, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field___Type_fields_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -3874,7 +3823,6 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Type", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3931,7 +3879,6 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Type", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -3986,18 +3933,18 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_enumValues_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ Object: "__Type", - Args: args, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field___Type_enumValues_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -4051,7 +3998,6 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Type", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -4108,7 +4054,6 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ Object: "__Type", - Args: nil, Field: field, } ctx = graphql.WithResolverContext(ctx, rctx) @@ -4157,6 +4102,12 @@ func (ec *executionContext) _ShapeUnion(ctx context.Context, sel ast.SelectionSe } } +func (e *executableSchema) ChangesMiddleware(ctx context.Context, obj *map[string]interface{}) (*map[string]interface{}, error) { + var err error + + return obj, err +} + func UnmarshalInnerInput(v interface{}) (InnerInput, error) { var it InnerInput var asMap = v.(map[string]interface{}) @@ -4175,6 +4126,12 @@ func UnmarshalInnerInput(v interface{}) (InnerInput, error) { return it, nil } +func (e *executableSchema) InnerInputMiddleware(ctx context.Context, obj *InnerInput) (*InnerInput, error) { + var err error + + return obj, err +} + func UnmarshalKeywords(v interface{}) (Keywords, error) { var it Keywords var asMap = v.(map[string]interface{}) @@ -4337,6 +4294,12 @@ func UnmarshalKeywords(v interface{}) (Keywords, error) { return it, nil } +func (e *executableSchema) KeywordsMiddleware(ctx context.Context, obj *Keywords) (*Keywords, error) { + var err error + + return obj, err +} + func UnmarshalOuterInput(v interface{}) (OuterInput, error) { var it OuterInput var asMap = v.(map[string]interface{}) @@ -4355,6 +4318,17 @@ func UnmarshalOuterInput(v interface{}) (OuterInput, error) { return it, nil } +func (e *executableSchema) OuterInputMiddleware(ctx context.Context, obj *OuterInput) (*OuterInput, error) { + var err error + + mTmp1, err := e.InnerInputMiddleware(ctx, &obj.Inner) + if err != nil { + return nil, err + } + obj.Inner = *mTmp1 + return obj, err +} + func UnmarshalRecursiveInputSlice(v interface{}) (RecursiveInputSlice, error) { var it RecursiveInputSlice var asMap = v.(map[string]interface{}) @@ -4384,6 +4358,20 @@ func UnmarshalRecursiveInputSlice(v interface{}) (RecursiveInputSlice, error) { return it, nil } +func (e *executableSchema) RecursiveInputSliceMiddleware(ctx context.Context, obj *RecursiveInputSlice) (*RecursiveInputSlice, error) { + var err error + + for idx1 := range obj.Self { + + mTmp2, err := e.RecursiveInputSliceMiddleware(ctx, &obj.Self[idx1]) + if err != nil { + return nil, err + } + obj.Self[idx1] = *mTmp2 + } + return obj, err +} + func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { defer func() { if r := recover(); r != nil { diff --git a/codegen/type.go b/codegen/type.go index 04d9bb2fde1..ecf52fd5beb 100644 --- a/codegen/type.go +++ b/codegen/type.go @@ -161,6 +161,64 @@ func (t Type) unmarshal(result, raw string, remainingMods []string, depth int) s }) } +func (t Type) Middleware(result, raw string) string { + return t.middleware(result, raw, t.Modifiers, 1) +} + +func (t Type) middleware(result, raw string, remainingMods []string, depth int) string { + if len(remainingMods) == 1 && remainingMods[0] == modPtr { + return tpl(`{{- if .t.Marshaler }} + {{.result}}, err = e.{{ .t.GQLType }}Middleware(ctx, {{.raw}}) + if err != nil { + return nil, err + } + {{- end }}`, map[string]interface{}{ + "result": result, + "raw": raw, + "t": t, + }) + } + switch { + case len(remainingMods) > 0 && remainingMods[0] == modPtr: + return tpl(`if {{.raw}} != nil { + {{.next}} + }`, map[string]interface{}{ + "t": t, + "raw": raw, + "result": result, + "mods": strings.Join(remainingMods[1:], ""), + "next": t.middleware(result, raw, remainingMods[1:], depth+1), + }) + + case len(remainingMods) > 0 && remainingMods[0] == modList: + var index = "idx" + strconv.Itoa(depth) + + return tpl(`for {{.index}} := range {{.raw}} { + {{ .next -}} + }`, map[string]interface{}{ + "raw": raw, + "index": index, + "result": result, + "type": strings.Join(remainingMods, "") + t.NamedType.FullName(), + "next": t.middleware(result+"["+index+"]", raw+"["+index+"]", remainingMods[1:], depth+1), + }) + } + + ptr := "mTmp" + strconv.Itoa(depth) + return tpl(`{{- if .t.Marshaler }} + {{.ptr}}, err := e.{{ .t.GQLType }}Middleware(ctx, &{{.raw}}) + if err != nil { + return nil, err + } + {{ .result }} = *{{.ptr}} + {{- end }}`, map[string]interface{}{ + "result": result, + "raw": raw, + "ptr": ptr, + "t": t, + }) +} + func (t Type) Marshal(val string) string { if t.AliasedType != nil { val = t.GoType + "(" + val + ")"