diff --git a/codegen/templates/data.go b/codegen/templates/data.go index 68fc9a78dd6..8362848427a 100644 --- a/codegen/templates/data.go +++ b/codegen/templates/data.go @@ -3,7 +3,7 @@ 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\tvar err error\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}\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\t{{- if $field.Args }}\n\t\t\trawArgs := field.ArgumentMap(ec.Variables)\n\t\t\targs, err := {{ $field.ArgsFunc }}(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\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\t\tField: field,\n\t\t})\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\t{{- if $field.Args }}\n\t\t\trawArgs := field.ArgumentMap(ec.Variables)\n\t\t\targs, err := {{ $field.ArgsFunc }}(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{{- end }}\n\t\trctx := &graphql.ResolverContext{\n\t\t\tObject: {{$object.GQLType|quote}},\n\t\t\tArgs: {{if $field.Args }}args{{else}}nil{{end}},\n\t\t\tField: field,\n\t\t}\n\t\tctx = graphql.WithResolverContext(ctx, rctx)\n\t\tresTmp := ec.FieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(ctx context.Context) (interface{}, error) {\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\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{{- range $import := .Imports }}\n\t{{- $import.Write }}\n{{ end }}\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 {{ $field.ArgsFunc }}(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 {{ $directive.ArgsFunc }}(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 }}args := map[string]interface{}{} {{end}}\n\t\t\t\t\t\t{{ range $i, $arg := $field.Args }}\n\t\t\t\t\t\t\tvar arg{{$i}} {{$arg.Signature }}\n\t\t\t\t\t\t\tif tmp, ok := rawArgs[{{$arg.GQLName|quote}}]; ok {\n\t\t\t\t\t\t\t\tvar err error\n\t\t\t\t\t\t\t\t{{$arg.Unmarshal (print \"arg\" $i) \"tmp\" }}\n\t\t\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\t\t\treturn 0, false\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\targs[{{$arg.GQLName|quote}}] = arg{{$i}}\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}\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}\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\treturn &graphql.Response{\n\t\t\t\tData: buf,\n\t\t\t\tErrors: ec.Errors,\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 := {{ $directive.ArgsFunc }}(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 {\n\treturn introspection.WrapSchema(parsedSchema)\n}\n\nfunc (ec *executionContext) introspectType(name string) *introspection.Type {\n\treturn introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name])\n}\n\nvar parsedSchema = gqlparser.MustLoadSchema(\n\t&ast.Source{Name: {{.SchemaFilename|quote}}, Input: {{.SchemaRaw|rawQuote}}},\n)\n", + "generated.gotpl": "// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.\n\npackage {{ .PackageName }}\n\nimport (\n{{- range $import := .Imports }}\n\t{{- $import.Write }}\n{{ end }}\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 {{ $field.ArgsFunc }}(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 {{ $directive.ArgsFunc }}(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 := {{ $field.ArgsFunc }}(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}\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}\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\treturn &graphql.Response{\n\t\t\t\tData: buf,\n\t\t\t\tErrors: ec.Errors,\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 := {{ $directive.ArgsFunc }}(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 {\n\treturn introspection.WrapSchema(parsedSchema)\n}\n\nfunc (ec *executionContext) introspectType(name string) *introspection.Type {\n\treturn introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name])\n}\n\nvar parsedSchema = gqlparser.MustLoadSchema(\n\t&ast.Source{Name: {{.SchemaFilename|quote}}, Input: {{.SchemaRaw|rawQuote}}},\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", "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{{- range $import := .Imports }}\n\t{{- $import.Write }}\n{{ end }}\n)\n\n{{ range $model := .Models }}\n\t{{with .Description}} {{.|prefixLines \"// \"}} {{end}}\n\t{{- if .IsInterface }}\n\t\ttype {{.GoType}} interface {}\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\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", diff --git a/codegen/templates/generated.gotpl b/codegen/templates/generated.gotpl index 1d48d373816..72de6fb65ba 100644 --- a/codegen/templates/generated.gotpl +++ b/codegen/templates/generated.gotpl @@ -99,17 +99,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.{{$object.GQLType|toCamel}}.{{$field.GQLName|toCamel}} == nil { break } - {{ if $field.Args }}args := map[string]interface{}{} {{end}} - {{ range $i, $arg := $field.Args }} - var arg{{$i}} {{$arg.Signature }} - if tmp, ok := rawArgs[{{$arg.GQLName|quote}}]; ok { - var err error - {{$arg.Unmarshal (print "arg" $i) "tmp" }} - if err != nil { - return 0, false - } + {{ if $field.Args }} + args, err := {{ $field.ArgsFunc }}(rawArgs) + if err != nil { + return 0, false } - args[{{$arg.GQLName|quote}}] = arg{{$i}} {{ end }} return e.complexity.{{$object.GQLType|toCamel}}.{{$field.GQLName|toCamel}}(childComplexity{{if $field.Args}}, {{$field.ComplexityArgs}} {{end}}), true {{ end }} diff --git a/codegen/testserver/generated.go b/codegen/testserver/generated.go index af8a902340c..95202a56d43 100644 --- a/codegen/testserver/generated.go +++ b/codegen/testserver/generated.go @@ -596,22 +596,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.MapInput == nil { break } - args := map[string]interface{}{} - 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{}) - arg0 = &ptr1 - } - - if err != nil { - return 0, false - } + args, err := field_Query_mapInput_args(rawArgs) + if err != nil { + return 0, false } - args["input"] = arg0 return e.complexity.Query.MapInput(childComplexity, args["input"].(*map[string]interface{})), true @@ -619,22 +608,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.Recursive == nil { break } - args := map[string]interface{}{} - var arg0 *RecursiveInputSlice - if tmp, ok := rawArgs["input"]; ok { - var err error - var ptr1 RecursiveInputSlice - if tmp != nil { - ptr1, err = UnmarshalRecursiveInputSlice(tmp) - arg0 = &ptr1 - } - - if err != nil { - return 0, false - } + args, err := field_Query_recursive_args(rawArgs) + if err != nil { + return 0, false } - args["input"] = arg0 return e.complexity.Query.Recursive(childComplexity, args["input"].(*RecursiveInputSlice)), true @@ -642,43 +620,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.NestedInputs == nil { break } - args := map[string]interface{}{} - var arg0 [][]*OuterInput - if tmp, ok := rawArgs["input"]; ok { - var err error - var rawIf1 []interface{} - if tmp != nil { - if tmp1, ok := tmp.([]interface{}); ok { - rawIf1 = tmp1 - } else { - rawIf1 = []interface{}{tmp} - } - } - arg0 = make([][]*OuterInput, len(rawIf1)) - for idx1 := range rawIf1 { - var rawIf2 []interface{} - if rawIf1[idx1] != nil { - if tmp1, ok := rawIf1[idx1].([]interface{}); ok { - rawIf2 = tmp1 - } else { - rawIf2 = []interface{}{rawIf1[idx1]} - } - } - arg0[idx1] = make([]*OuterInput, len(rawIf2)) - for idx2 := range rawIf2 { - var ptr3 OuterInput - if rawIf2[idx2] != nil { - ptr3, err = UnmarshalOuterInput(rawIf2[idx2]) - arg0[idx1][idx2] = &ptr3 - } - } - } - if err != nil { - return 0, false - } + args, err := field_Query_nestedInputs_args(rawArgs) + if err != nil { + return 0, false } - args["input"] = arg0 return e.complexity.Query.NestedInputs(childComplexity, args["input"].([][]*OuterInput)), true @@ -693,22 +639,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.Keywords == nil { break } - args := map[string]interface{}{} - - var arg0 *Keywords - if tmp, ok := rawArgs["input"]; ok { - var err error - var ptr1 Keywords - if tmp != nil { - ptr1, err = UnmarshalKeywords(tmp) - arg0 = &ptr1 - } - if err != nil { - return 0, false - } + args, err := field_Query_keywords_args(rawArgs) + if err != nil { + return 0, false } - args["input"] = arg0 return e.complexity.Query.Keywords(childComplexity, args["input"].(*Keywords)), true @@ -737,257 +672,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.KeywordArgs == nil { break } - args := map[string]interface{}{} - - var arg0 string - if tmp, ok := rawArgs["break"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["break"] = arg0 - - var arg1 string - if tmp, ok := rawArgs["default"]; ok { - var err error - arg1, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["default"] = arg1 - - var arg2 string - if tmp, ok := rawArgs["func"]; ok { - var err error - arg2, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["func"] = arg2 - - var arg3 string - if tmp, ok := rawArgs["interface"]; ok { - var err error - arg3, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["interface"] = arg3 - - var arg4 string - if tmp, ok := rawArgs["select"]; ok { - var err error - arg4, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["select"] = arg4 - - var arg5 string - if tmp, ok := rawArgs["case"]; ok { - var err error - arg5, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["case"] = arg5 - - var arg6 string - if tmp, ok := rawArgs["defer"]; ok { - var err error - arg6, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["defer"] = arg6 - - var arg7 string - if tmp, ok := rawArgs["go"]; ok { - var err error - arg7, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["go"] = arg7 - - var arg8 string - if tmp, ok := rawArgs["map"]; ok { - var err error - arg8, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["map"] = arg8 - var arg9 string - if tmp, ok := rawArgs["struct"]; ok { - var err error - arg9, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["struct"] = arg9 - - var arg10 string - if tmp, ok := rawArgs["chan"]; ok { - var err error - arg10, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["chan"] = arg10 - - var arg11 string - if tmp, ok := rawArgs["else"]; ok { - var err error - arg11, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["else"] = arg11 - - var arg12 string - if tmp, ok := rawArgs["goto"]; ok { - var err error - arg12, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["goto"] = arg12 - - var arg13 string - if tmp, ok := rawArgs["package"]; ok { - var err error - arg13, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["package"] = arg13 - - var arg14 string - if tmp, ok := rawArgs["switch"]; ok { - var err error - arg14, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["switch"] = arg14 - - var arg15 string - if tmp, ok := rawArgs["const"]; ok { - var err error - arg15, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["const"] = arg15 - - var arg16 string - if tmp, ok := rawArgs["fallthrough"]; ok { - var err error - arg16, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["fallthrough"] = arg16 - - var arg17 string - if tmp, ok := rawArgs["if"]; ok { - var err error - arg17, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["if"] = arg17 - - var arg18 string - if tmp, ok := rawArgs["range"]; ok { - var err error - arg18, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["range"] = arg18 - - var arg19 string - if tmp, ok := rawArgs["type"]; ok { - var err error - arg19, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["type"] = arg19 - - var arg20 string - if tmp, ok := rawArgs["continue"]; ok { - var err error - arg20, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["continue"] = arg20 - - var arg21 string - if tmp, ok := rawArgs["for"]; ok { - var err error - arg21, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["for"] = arg21 - - var arg22 string - if tmp, ok := rawArgs["import"]; ok { - var err error - arg22, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["import"] = arg22 - - var arg23 string - if tmp, ok := rawArgs["return"]; ok { - var err error - arg23, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["return"] = arg23 - - var arg24 string - if tmp, ok := rawArgs["var"]; ok { - var err error - arg24, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } + args, err := field_Query_keywordArgs_args(rawArgs) + if err != nil { + return 0, false } - args["var"] = arg24 return e.complexity.Query.KeywordArgs(childComplexity, args["break"].(string), args["default"].(string), args["func"].(string), args["interface"].(string), args["select"].(string), args["case"].(string), args["defer"].(string), args["go"].(string), args["map"].(string), args["struct"].(string), args["chan"].(string), args["else"].(string), args["goto"].(string), args["package"].(string), args["switch"].(string), args["const"].(string), args["fallthrough"].(string), args["if"].(string), args["range"].(string), args["type"].(string), args["continue"].(string), args["for"].(string), args["import"].(string), args["return"].(string), args["var"].(string)), true diff --git a/example/chat/generated.go b/example/chat/generated.go index 2e32dbdb174..c975da0a1b0 100644 --- a/example/chat/generated.go +++ b/example/chat/generated.go @@ -242,37 +242,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Mutation.Post == nil { break } - args := map[string]interface{}{} - - var arg0 string - if tmp, ok := rawArgs["text"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["text"] = arg0 - - var arg1 string - if tmp, ok := rawArgs["username"]; ok { - var err error - arg1, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } - } - args["username"] = arg1 - var arg2 string - if tmp, ok := rawArgs["roomName"]; ok { - var err error - arg2, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } + args, err := field_Mutation_post_args(rawArgs) + if err != nil { + return 0, false } - args["roomName"] = arg2 return e.complexity.Mutation.Post(childComplexity, args["text"].(string), args["username"].(string), args["roomName"].(string)), true @@ -280,17 +254,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.Room == nil { break } - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["name"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } + args, err := field_Query_room_args(rawArgs) + if err != nil { + return 0, false } - args["name"] = arg0 return e.complexity.Query.Room(childComplexity, args["name"].(string)), true @@ -298,17 +266,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Subscription.MessageAdded == nil { break } - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["roomName"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } + args, err := field_Subscription_messageAdded_args(rawArgs) + if err != nil { + return 0, false } - args["roomName"] = arg0 return e.complexity.Subscription.MessageAdded(childComplexity, args["roomName"].(string)), true diff --git a/example/config/generated.go b/example/config/generated.go index e7c31473638..55153853fd5 100644 --- a/example/config/generated.go +++ b/example/config/generated.go @@ -148,17 +148,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Mutation.CreateTodo == nil { break } - args := map[string]interface{}{} - var arg0 NewTodo - if tmp, ok := rawArgs["input"]; ok { - var err error - arg0, err = UnmarshalNewTodo(tmp) - if err != nil { - return 0, false - } + args, err := field_Mutation_createTodo_args(rawArgs) + if err != nil { + return 0, false } - args["input"] = arg0 return e.complexity.Mutation.CreateTodo(childComplexity, args["input"].(NewTodo)), true diff --git a/example/dataloader/generated.go b/example/dataloader/generated.go index d9c424dc095..b43dabfdc47 100644 --- a/example/dataloader/generated.go +++ b/example/dataloader/generated.go @@ -300,28 +300,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.Torture1d == nil { break } - args := map[string]interface{}{} - - var arg0 []int - if tmp, ok := rawArgs["customerIds"]; ok { - var err error - var rawIf1 []interface{} - if tmp != nil { - if tmp1, ok := tmp.([]interface{}); ok { - rawIf1 = tmp1 - } else { - rawIf1 = []interface{}{tmp} - } - } - arg0 = make([]int, len(rawIf1)) - for idx1 := range rawIf1 { - arg0[idx1], err = graphql.UnmarshalInt(rawIf1[idx1]) - } - if err != nil { - return 0, false - } + + args, err := field_Query_torture1d_args(rawArgs) + if err != nil { + return 0, false } - args["customerIds"] = arg0 return e.complexity.Query.Torture1d(childComplexity, args["customerIds"].([]int)), true @@ -329,39 +312,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.Torture2d == nil { break } - args := map[string]interface{}{} - var arg0 [][]int - if tmp, ok := rawArgs["customerIds"]; ok { - var err error - var rawIf1 []interface{} - if tmp != nil { - if tmp1, ok := tmp.([]interface{}); ok { - rawIf1 = tmp1 - } else { - rawIf1 = []interface{}{tmp} - } - } - arg0 = make([][]int, len(rawIf1)) - for idx1 := range rawIf1 { - var rawIf2 []interface{} - if rawIf1[idx1] != nil { - if tmp1, ok := rawIf1[idx1].([]interface{}); ok { - rawIf2 = tmp1 - } else { - rawIf2 = []interface{}{rawIf1[idx1]} - } - } - arg0[idx1] = make([]int, len(rawIf2)) - for idx2 := range rawIf2 { - arg0[idx1][idx2], err = graphql.UnmarshalInt(rawIf2[idx2]) - } - } - if err != nil { - return 0, false - } + args, err := field_Query_torture2d_args(rawArgs) + if err != nil { + return 0, false } - args["customerIds"] = arg0 return e.complexity.Query.Torture2d(childComplexity, args["customerIds"].([][]int)), true diff --git a/example/scalars/generated.go b/example/scalars/generated.go index e766666af79..c7f0e3c3f85 100644 --- a/example/scalars/generated.go +++ b/example/scalars/generated.go @@ -178,17 +178,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.User == nil { break } - args := map[string]interface{}{} - var arg0 external.ObjectID - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = model.UnmarshalID(tmp) - if err != nil { - return 0, false - } + args, err := field_Query_user_args(rawArgs) + if err != nil { + return 0, false } - args["id"] = arg0 return e.complexity.Query.User(childComplexity, args["id"].(external.ObjectID)), true @@ -196,17 +190,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.Search == nil { break } - args := map[string]interface{}{} - var arg0 model.SearchArgs - if tmp, ok := rawArgs["input"]; ok { - var err error - arg0, err = UnmarshalSearchArgs(tmp) - if err != nil { - return 0, false - } + args, err := field_Query_search_args(rawArgs) + if err != nil { + return 0, false } - args["input"] = arg0 return e.complexity.Query.Search(childComplexity, args["input"].(model.SearchArgs)), true diff --git a/example/starwars/generated.go b/example/starwars/generated.go index d89ba8d5704..d850e929d3b 100644 --- a/example/starwars/generated.go +++ b/example/starwars/generated.go @@ -464,37 +464,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Droid.FriendsConnection == nil { break } - args := map[string]interface{}{} - var arg0 *int - if tmp, ok := rawArgs["first"]; ok { - var err error - var ptr1 int - if tmp != nil { - ptr1, err = graphql.UnmarshalInt(tmp) - arg0 = &ptr1 - } - - if err != nil { - return 0, false - } - } - args["first"] = arg0 - - var arg1 *string - if tmp, ok := rawArgs["after"]; ok { - var err error - var ptr1 string - if tmp != nil { - ptr1, err = graphql.UnmarshalID(tmp) - arg1 = &ptr1 - } - - if err != nil { - return 0, false - } + args, err := field_Droid_friendsConnection_args(rawArgs) + if err != nil { + return 0, false } - args["after"] = arg1 return e.complexity.Droid.FriendsConnection(childComplexity, args["first"].(*int), args["after"].(*string)), true @@ -572,17 +546,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Human.Height == nil { break } - args := map[string]interface{}{} - var arg0 LengthUnit - if tmp, ok := rawArgs["unit"]; ok { - var err error - err = (&arg0).UnmarshalGQL(tmp) - if err != nil { - return 0, false - } + args, err := field_Human_height_args(rawArgs) + if err != nil { + return 0, false } - args["unit"] = arg0 return e.complexity.Human.Height(childComplexity, args["unit"].(LengthUnit)), true @@ -604,37 +572,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Human.FriendsConnection == nil { break } - args := map[string]interface{}{} - - var arg0 *int - if tmp, ok := rawArgs["first"]; ok { - var err error - var ptr1 int - if tmp != nil { - ptr1, err = graphql.UnmarshalInt(tmp) - arg0 = &ptr1 - } - - if err != nil { - return 0, false - } - } - args["first"] = arg0 - var arg1 *string - if tmp, ok := rawArgs["after"]; ok { - var err error - var ptr1 string - if tmp != nil { - ptr1, err = graphql.UnmarshalID(tmp) - arg1 = &ptr1 - } - - if err != nil { - return 0, false - } + args, err := field_Human_friendsConnection_args(rawArgs) + if err != nil { + return 0, false } - args["after"] = arg1 return e.complexity.Human.FriendsConnection(childComplexity, args["first"].(*int), args["after"].(*string)), true @@ -656,27 +598,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Mutation.CreateReview == nil { break } - args := map[string]interface{}{} - - var arg0 Episode - if tmp, ok := rawArgs["episode"]; ok { - var err error - err = (&arg0).UnmarshalGQL(tmp) - if err != nil { - return 0, false - } - } - args["episode"] = arg0 - var arg1 Review - if tmp, ok := rawArgs["review"]; ok { - var err error - arg1, err = UnmarshalReviewInput(tmp) - if err != nil { - return 0, false - } + args, err := field_Mutation_createReview_args(rawArgs) + if err != nil { + return 0, false } - args["review"] = arg1 return e.complexity.Mutation.CreateReview(childComplexity, args["episode"].(Episode), args["review"].(Review)), true @@ -705,17 +631,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.Hero == nil { break } - args := map[string]interface{}{} - var arg0 Episode - if tmp, ok := rawArgs["episode"]; ok { - var err error - err = (&arg0).UnmarshalGQL(tmp) - if err != nil { - return 0, false - } + args, err := field_Query_hero_args(rawArgs) + if err != nil { + return 0, false } - args["episode"] = arg0 return e.complexity.Query.Hero(childComplexity, args["episode"].(Episode)), true @@ -723,32 +643,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.Reviews == nil { break } - args := map[string]interface{}{} - - var arg0 Episode - if tmp, ok := rawArgs["episode"]; ok { - var err error - err = (&arg0).UnmarshalGQL(tmp) - if err != nil { - return 0, false - } - } - args["episode"] = arg0 - var arg1 *time.Time - if tmp, ok := rawArgs["since"]; ok { - var err error - var ptr1 time.Time - if tmp != nil { - ptr1, err = graphql.UnmarshalTime(tmp) - arg1 = &ptr1 - } - - if err != nil { - return 0, false - } + args, err := field_Query_reviews_args(rawArgs) + if err != nil { + return 0, false } - args["since"] = arg1 return e.complexity.Query.Reviews(childComplexity, args["episode"].(Episode), args["since"].(*time.Time)), true @@ -756,17 +655,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.Search == nil { break } - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["text"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return 0, false - } + args, err := field_Query_search_args(rawArgs) + if err != nil { + return 0, false } - args["text"] = arg0 return e.complexity.Query.Search(childComplexity, args["text"].(string)), true @@ -774,17 +667,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.Character == nil { break } - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = graphql.UnmarshalID(tmp) - if err != nil { - return 0, false - } + args, err := field_Query_character_args(rawArgs) + if err != nil { + return 0, false } - args["id"] = arg0 return e.complexity.Query.Character(childComplexity, args["id"].(string)), true @@ -792,17 +679,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.Droid == nil { break } - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = graphql.UnmarshalID(tmp) - if err != nil { - return 0, false - } + args, err := field_Query_droid_args(rawArgs) + if err != nil { + return 0, false } - args["id"] = arg0 return e.complexity.Query.Droid(childComplexity, args["id"].(string)), true @@ -810,17 +691,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.Human == nil { break } - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = graphql.UnmarshalID(tmp) - if err != nil { - return 0, false - } + args, err := field_Query_human_args(rawArgs) + if err != nil { + return 0, false } - args["id"] = arg0 return e.complexity.Query.Human(childComplexity, args["id"].(string)), true @@ -828,17 +703,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.Starship == nil { break } - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = graphql.UnmarshalID(tmp) - if err != nil { - return 0, false - } + args, err := field_Query_starship_args(rawArgs) + if err != nil { + return 0, false } - args["id"] = arg0 return e.complexity.Query.Starship(childComplexity, args["id"].(string)), true @@ -881,17 +750,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Starship.Length == nil { break } - args := map[string]interface{}{} - var arg0 LengthUnit - if tmp, ok := rawArgs["unit"]; ok { - var err error - err = (&arg0).UnmarshalGQL(tmp) - if err != nil { - return 0, false - } + args, err := field_Starship_length_args(rawArgs) + if err != nil { + return 0, false } - args["unit"] = arg0 return e.complexity.Starship.Length(childComplexity, args["unit"].(LengthUnit)), true diff --git a/example/todo/generated.go b/example/todo/generated.go index 364336c9de6..fc77f564f7b 100644 --- a/example/todo/generated.go +++ b/example/todo/generated.go @@ -198,17 +198,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.MyMutation.CreateTodo == nil { break } - args := map[string]interface{}{} - var arg0 TodoInput - if tmp, ok := rawArgs["todo"]; ok { - var err error - arg0, err = UnmarshalTodoInput(tmp) - if err != nil { - return 0, false - } + args, err := field_MyMutation_createTodo_args(rawArgs) + if err != nil { + return 0, false } - args["todo"] = arg0 return e.complexity.MyMutation.CreateTodo(childComplexity, args["todo"].(TodoInput)), true @@ -216,27 +210,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.MyMutation.UpdateTodo == nil { break } - args := map[string]interface{}{} - - var arg0 int - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = graphql.UnmarshalInt(tmp) - if err != nil { - return 0, false - } - } - args["id"] = arg0 - var arg1 map[string]interface{} - if tmp, ok := rawArgs["changes"]; ok { - var err error - arg1 = tmp.(map[string]interface{}) - if err != nil { - return 0, false - } + args, err := field_MyMutation_updateTodo_args(rawArgs) + if err != nil { + return 0, false } - args["changes"] = arg1 return e.complexity.MyMutation.UpdateTodo(childComplexity, args["id"].(int), args["changes"].(map[string]interface{})), true @@ -244,17 +222,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.MyQuery.Todo == nil { break } - args := map[string]interface{}{} - var arg0 int - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = graphql.UnmarshalInt(tmp) - if err != nil { - return 0, false - } + args, err := field_MyQuery_todo_args(rawArgs) + if err != nil { + return 0, false } - args["id"] = arg0 return e.complexity.MyQuery.Todo(childComplexity, args["id"].(int)), true diff --git a/integration/generated.go b/integration/generated.go index b9c39ef6858..716c8913f13 100644 --- a/integration/generated.go +++ b/integration/generated.go @@ -222,17 +222,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.Date == nil { break } - args := map[string]interface{}{} - var arg0 models.DateFilter - if tmp, ok := rawArgs["filter"]; ok { - var err error - arg0, err = UnmarshalDateFilter(tmp) - if err != nil { - return 0, false - } + args, err := field_Query_date_args(rawArgs) + if err != nil { + return 0, false } - args["filter"] = arg0 return e.complexity.Query.Date(childComplexity, args["filter"].(models.DateFilter)), true @@ -254,17 +248,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in if e.complexity.Query.Error == nil { break } - args := map[string]interface{}{} - var arg0 models.ErrorType - if tmp, ok := rawArgs["type"]; ok { - var err error - err = (&arg0).UnmarshalGQL(tmp) - if err != nil { - return 0, false - } + args, err := field_Query_error_args(rawArgs) + if err != nil { + return 0, false } - args["type"] = arg0 return e.complexity.Query.Error(childComplexity, args["type"].(models.ErrorType)), true