diff --git a/codegen/templates/data.go b/codegen/templates/data.go index 917f31626d7..5dd711aab81 100644 --- a/codegen/templates/data.go +++ b/codegen/templates/data.go @@ -1,9 +1,9 @@ package templates var data = map[string]string{ - "args.gotpl": "\t{{- if . }}args := map[string]interface{}{} {{end}}\n\t{{- range $i, $arg := . }}\n\t\tvar arg{{$i}} {{$arg.Signature }}\n\t\tif tmp, ok := field.Args[{{$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\tec.Error(ctx, err)\n\t\t\t\t{{- if $arg.Object.Stream }}\n\t\t\t\t\treturn nil\n\t\t\t\t{{- else }}\n\t\t\t\t\treturn graphql.Null\n\t\t\t\t{{- end }}\n\t\t\t}\n\t\t} {{ if $arg.Default }} else {\n\t\t\tvar tmp interface{} = {{ $arg.Default | dump }}\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\tec.Error(ctx, err)\n\t\t\t\t{{- if $arg.Object.Stream }}\n\t\t\t\t\treturn nil\n\t\t\t\t{{- else }}\n\t\t\t\t\treturn graphql.Null\n\t\t\t\t{{- end }}\n\t\t\t}\n\t\t}\n\t\t{{end }}\n\t\targs[{{$arg.GQLName|quote}}] = arg{{$i}}\n\t{{- end -}}\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{{- template \"args.gotpl\" $field.Args }}\n\t\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field})\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\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{{- template \"args.gotpl\" $field.Args }}\n\n\t\t{{- if $field.IsConcurrent }}\n\t\t\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\t\t\tObject: {{$object.GQLType|quote}},\n\t\t\t\tArgs: {{if $field.Args }}args{{else}}nil{{end}},\n\t\t\t\tField: field,\n\t\t\t})\n\t\t\treturn graphql.Defer(func() (ret graphql.Marshaler) {\n\t\t\t\tdefer func() {\n\t\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\t\tuserErr := ec.Recover(ctx, r)\n\t\t\t\t\t\tec.Error(ctx, userErr)\n\t\t\t\t\t\tret = graphql.Null\n\t\t\t\t\t}\n\t\t\t\t}()\n\t\t{{ else }}\n\t\t\trctx := graphql.GetResolverContext(ctx)\n\t\t\trctx.Object = {{$object.GQLType|quote}}\n\t\t\trctx.Args = {{if $field.Args }}args{{else}}nil{{end}}\n\t\t\trctx.Field = field\n\t\t\trctx.PushField(field.Alias)\n\t\t\tdefer rctx.Pop()\n\t\t{{- end }}\n\t\t\tresTmp := ec.FieldMiddleware(ctx, func(ctx context.Context) (interface{}, error) {\n\t\t\t\t{{- if $field.IsResolver }}\n\t\t\t\t\treturn ec.resolvers.{{ $field.ShortInvocation }}\n\t\t\t\t{{- else if $field.IsMethod }}\n\t\t\t\t\t{{- if $field.NoErr }}\n\t\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }}), nil\n\t\t\t\t\t{{- else }}\n\t\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }})\n\t\t\t\t\t{{- end }}\n\t\t\t\t{{- else if $field.IsVariable }}\n\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}, nil\n\t\t\t\t{{- end }}\n\t\t\t})\n\t\t\tif resTmp == nil {\n\t\t\t\treturn graphql.Null\n\t\t\t}\n\t\t\tres := resTmp.({{$field.Signature}})\n\t\t\t{{ $field.WriteJson }}\n\t\t{{- if $field.IsConcurrent }}\n\t\t\t})\n\t\t{{- end }}\n\t}\n{{ end }}\n", - "generated.gotpl": "// Code generated by github.com/vektah/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}\n}\n\ntype Config struct {\n\tResolvers ResolverRoot\n\tDirectives DirectiveRoot\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.Name|ucFirst}} graphql.FieldMiddleware\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\ntype executableSchema struct {\n\tresolvers ResolverRoot\n\tdirectives DirectiveRoot\n}\n\nfunc (e *executableSchema) Schema() *ast.Schema {\n\treturn parsedSchema\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, next graphql.Resolver) interface{} {\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\tn := next\n\t\t\t\tnext = func(ctx context.Context) (interface{}, error) {\n\t\t\t\t\treturn ec.directives.{{$directive.Name|ucFirst}}(ctx, n)\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", + "args.gotpl": "\t{{- if . }}args := map[string]interface{}{} {{end}}\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\tec.Error(ctx, err)\n\t\t\t\t{{- if $arg.Stream }}\n\t\t\t\t\treturn nil\n\t\t\t\t{{- else }}\n\t\t\t\t\treturn graphql.Null\n\t\t\t\t{{- end }}\n\t\t\t}\n\t\t}\n\t\targs[{{$arg.GQLName|quote}}] = arg{{$i}}\n\t{{- end -}}\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\t{{ template \"args.gotpl\" $field.Args }}\n\t\t{{- end }}\n\t\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field})\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\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\t{{ template \"args.gotpl\" $field.Args }}\n\t\t{{- end }}\n\n\t\t{{- if $field.IsConcurrent }}\n\t\t\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\t\t\tObject: {{$object.GQLType|quote}},\n\t\t\t\tArgs: {{if $field.Args }}args{{else}}nil{{end}},\n\t\t\t\tField: field,\n\t\t\t})\n\t\t\treturn graphql.Defer(func() (ret graphql.Marshaler) {\n\t\t\t\tdefer func() {\n\t\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\t\tuserErr := ec.Recover(ctx, r)\n\t\t\t\t\t\tec.Error(ctx, userErr)\n\t\t\t\t\t\tret = graphql.Null\n\t\t\t\t\t}\n\t\t\t\t}()\n\t\t{{ else }}\n\t\t\trctx := graphql.GetResolverContext(ctx)\n\t\t\trctx.Object = {{$object.GQLType|quote}}\n\t\t\trctx.Args = {{if $field.Args }}args{{else}}nil{{end}}\n\t\t\trctx.Field = field\n\t\t\trctx.PushField(field.Alias)\n\t\t\tdefer rctx.Pop()\n\t\t{{- end }}\n\t\t\tresTmp := ec.FieldMiddleware(ctx, func(ctx context.Context) (interface{}, error) {\n\t\t\t\t{{- if $field.IsResolver }}\n\t\t\t\t\treturn ec.resolvers.{{ $field.ShortInvocation }}\n\t\t\t\t{{- else if $field.IsMethod }}\n\t\t\t\t\t{{- if $field.NoErr }}\n\t\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }}), nil\n\t\t\t\t\t{{- else }}\n\t\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }})\n\t\t\t\t\t{{- end }}\n\t\t\t\t{{- else if $field.IsVariable }}\n\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}, nil\n\t\t\t\t{{- end }}\n\t\t\t})\n\t\t\tif resTmp == nil {\n\t\t\t\treturn graphql.Null\n\t\t\t}\n\t\t\tres := resTmp.({{$field.Signature}})\n\t\t\t{{ $field.WriteJson }}\n\t\t{{- if $field.IsConcurrent }}\n\t\t\t})\n\t\t{{- end }}\n\t}\n{{ end }}\n", + "generated.gotpl": "// Code generated by github.com/vektah/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}\n}\n\ntype Config struct {\n\tResolvers ResolverRoot\n\tDirectives DirectiveRoot\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\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\ntype executableSchema struct {\n\tresolvers ResolverRoot\n\tdirectives DirectiveRoot\n}\n\nfunc (e *executableSchema) Schema() *ast.Schema {\n\treturn parsedSchema\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, next graphql.Resolver) interface{} {\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\t{{ template \"args.gotpl\" $directive.Args }}\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/vektah/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{{- 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{{- 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\ttype {{.GoType}} string\n\tconst (\n\t{{ range $value := .Values -}}\n\t\t{{with .Description}} {{.|prefixLines \"// \"}} {{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/example/chat/generated.go b/example/chat/generated.go index 51711c680fa..512794d2e87 100644 --- a/example/chat/generated.go +++ b/example/chat/generated.go @@ -312,9 +312,10 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) } func (ec *executionContext) _Mutation_post(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 string - if tmp, ok := field.Args["text"]; ok { + if tmp, ok := rawArgs["text"]; ok { var err error arg0, err = graphql.UnmarshalString(tmp) if err != nil { @@ -324,7 +325,7 @@ func (ec *executionContext) _Mutation_post(ctx context.Context, field graphql.Co } args["text"] = arg0 var arg1 string - if tmp, ok := field.Args["username"]; ok { + if tmp, ok := rawArgs["username"]; ok { var err error arg1, err = graphql.UnmarshalString(tmp) if err != nil { @@ -334,7 +335,7 @@ func (ec *executionContext) _Mutation_post(ctx context.Context, field graphql.Co } args["username"] = arg1 var arg2 string - if tmp, ok := field.Args["roomName"]; ok { + if tmp, ok := rawArgs["roomName"]; ok { var err error arg2, err = graphql.UnmarshalString(tmp) if err != nil { @@ -391,9 +392,10 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } func (ec *executionContext) _Query_room(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 string - if tmp, ok := field.Args["name"]; ok { + if tmp, ok := rawArgs["name"]; ok { var err error arg0, err = graphql.UnmarshalString(tmp) if err != nil { @@ -431,9 +433,10 @@ func (ec *executionContext) _Query_room(ctx context.Context, field graphql.Colle } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 string - if tmp, ok := field.Args["name"]; ok { + if tmp, ok := rawArgs["name"]; ok { var err error arg0, err = graphql.UnmarshalString(tmp) if err != nil { @@ -503,9 +506,10 @@ func (ec *executionContext) _Subscription(ctx context.Context, sel ast.Selection } func (ec *executionContext) _Subscription_messageAdded(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 string - if tmp, ok := field.Args["roomName"]; ok { + if tmp, ok := rawArgs["roomName"]; ok { var err error arg0, err = graphql.UnmarshalString(tmp) if err != nil { @@ -1224,9 +1228,10 @@ 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 { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { + if tmp, ok := rawArgs["includeDeprecated"]; ok { var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { @@ -1313,9 +1318,10 @@ 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 { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { + if tmp, ok := rawArgs["includeDeprecated"]; ok { var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { diff --git a/example/config/generated.go b/example/config/generated.go index f83316f3ba9..656821bc0ef 100644 --- a/example/config/generated.go +++ b/example/config/generated.go @@ -122,9 +122,10 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) } func (ec *executionContext) _Mutation_createTodo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 NewTodo - if tmp, ok := field.Args["input"]; ok { + if tmp, ok := rawArgs["input"]; ok { var err error arg0, err = UnmarshalNewTodo(tmp) if err != nil { @@ -216,9 +217,10 @@ func (ec *executionContext) _Query_todos(ctx context.Context, field graphql.Coll } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 string - if tmp, ok := field.Args["name"]; ok { + if tmp, ok := rawArgs["name"]; ok { var err error arg0, err = graphql.UnmarshalString(tmp) if err != nil { @@ -1143,9 +1145,10 @@ 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 { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { + if tmp, ok := rawArgs["includeDeprecated"]; ok { var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { @@ -1232,9 +1235,10 @@ 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 { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { + if tmp, ok := rawArgs["includeDeprecated"]; ok { var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { diff --git a/example/dataloader/generated.go b/example/dataloader/generated.go index 21b4abdc7fe..ec67bef75b5 100644 --- a/example/dataloader/generated.go +++ b/example/dataloader/generated.go @@ -514,9 +514,10 @@ func (ec *executionContext) _Query_customers(ctx context.Context, field graphql. } func (ec *executionContext) _Query_torture(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 [][]int - if tmp, ok := field.Args["customerIds"]; ok { + if tmp, ok := rawArgs["customerIds"]; ok { var err error var rawIf1 []interface{} if tmp != nil { @@ -587,9 +588,10 @@ func (ec *executionContext) _Query_torture(ctx context.Context, field graphql.Co } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 string - if tmp, ok := field.Args["name"]; ok { + if tmp, ok := rawArgs["name"]; ok { var err error arg0, err = graphql.UnmarshalString(tmp) if err != nil { @@ -1330,9 +1332,10 @@ 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 { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { + if tmp, ok := rawArgs["includeDeprecated"]; ok { var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { @@ -1419,9 +1422,10 @@ 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 { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { + if tmp, ok := rawArgs["includeDeprecated"]; ok { var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { diff --git a/example/scalars/generated.go b/example/scalars/generated.go index 2fc65759141..ab83b0a9770 100644 --- a/example/scalars/generated.go +++ b/example/scalars/generated.go @@ -179,9 +179,10 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } func (ec *executionContext) _Query_user(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 external.ObjectID - if tmp, ok := field.Args["id"]; ok { + if tmp, ok := rawArgs["id"]; ok { var err error arg0, err = model.UnmarshalID(tmp) if err != nil { @@ -219,17 +220,10 @@ func (ec *executionContext) _Query_user(ctx context.Context, field graphql.Colle } func (ec *executionContext) _Query_search(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 model.SearchArgs - if tmp, ok := field.Args["input"]; ok { - var err error - arg0, err = UnmarshalSearchArgs(tmp) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - } else { - var tmp interface{} = map[string]interface{}{"isBanned": false, "location": "37,144"} + if tmp, ok := rawArgs["input"]; ok { var err error arg0, err = UnmarshalSearchArgs(tmp) if err != nil { @@ -237,7 +231,6 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col return graphql.Null } } - args["input"] = arg0 ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ Object: "Query", @@ -274,9 +267,10 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 string - if tmp, ok := field.Args["name"]; ok { + if tmp, ok := rawArgs["name"]; ok { var err error arg0, err = graphql.UnmarshalString(tmp) if err != nil { @@ -1208,9 +1202,10 @@ 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 { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { + if tmp, ok := rawArgs["includeDeprecated"]; ok { var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { @@ -1297,9 +1292,10 @@ 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 { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { + if tmp, ok := rawArgs["includeDeprecated"]; ok { var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { diff --git a/example/selection/generated.go b/example/selection/generated.go index db02424f8cb..335c36f67f8 100644 --- a/example/selection/generated.go +++ b/example/selection/generated.go @@ -373,9 +373,10 @@ func (ec *executionContext) _Query_events(ctx context.Context, field graphql.Col } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 string - if tmp, ok := field.Args["name"]; ok { + if tmp, ok := rawArgs["name"]; ok { var err error arg0, err = graphql.UnmarshalString(tmp) if err != nil { @@ -1116,9 +1117,10 @@ 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 { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { + if tmp, ok := rawArgs["includeDeprecated"]; ok { var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { @@ -1205,9 +1207,10 @@ 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 { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { + if tmp, ok := rawArgs["includeDeprecated"]; ok { var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { diff --git a/example/starwars/generated.go b/example/starwars/generated.go index 3cc8a734d60..9edd0019282 100644 --- a/example/starwars/generated.go +++ b/example/starwars/generated.go @@ -222,9 +222,10 @@ func (ec *executionContext) _Droid_friends(ctx context.Context, field graphql.Co } func (ec *executionContext) _Droid_friendsConnection(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 *int - if tmp, ok := field.Args["first"]; ok { + if tmp, ok := rawArgs["first"]; ok { var err error var ptr1 int if tmp != nil { @@ -239,7 +240,7 @@ func (ec *executionContext) _Droid_friendsConnection(ctx context.Context, field } args["first"] = arg0 var arg1 *string - if tmp, ok := field.Args["after"]; ok { + if tmp, ok := rawArgs["after"]; ok { var err error var ptr1 string if tmp != nil { @@ -585,17 +586,10 @@ func (ec *executionContext) _Human_name(ctx context.Context, field graphql.Colle } func (ec *executionContext) _Human_height(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 LengthUnit - if tmp, ok := field.Args["unit"]; ok { - var err error - err = (&arg0).UnmarshalGQL(tmp) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - } else { - var tmp interface{} = "METER" + if tmp, ok := rawArgs["unit"]; ok { var err error err = (&arg0).UnmarshalGQL(tmp) if err != nil { @@ -603,7 +597,6 @@ func (ec *executionContext) _Human_height(ctx context.Context, field graphql.Col return graphql.Null } } - args["unit"] = arg0 rctx := graphql.GetResolverContext(ctx) rctx.Object = "Human" @@ -674,9 +667,10 @@ func (ec *executionContext) _Human_friends(ctx context.Context, field graphql.Co } func (ec *executionContext) _Human_friendsConnection(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 *int - if tmp, ok := field.Args["first"]; ok { + if tmp, ok := rawArgs["first"]; ok { var err error var ptr1 int if tmp != nil { @@ -691,7 +685,7 @@ func (ec *executionContext) _Human_friendsConnection(ctx context.Context, field } args["first"] = arg0 var arg1 *string - if tmp, ok := field.Args["after"]; ok { + if tmp, ok := rawArgs["after"]; ok { var err error var ptr1 string if tmp != nil { @@ -819,9 +813,10 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) } func (ec *executionContext) _Mutation_createReview(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 Episode - if tmp, ok := field.Args["episode"]; ok { + if tmp, ok := rawArgs["episode"]; ok { var err error err = (&arg0).UnmarshalGQL(tmp) if err != nil { @@ -831,7 +826,7 @@ func (ec *executionContext) _Mutation_createReview(ctx context.Context, field gr } args["episode"] = arg0 var arg1 Review - if tmp, ok := field.Args["review"]; ok { + if tmp, ok := rawArgs["review"]; ok { var err error arg1, err = UnmarshalReviewInput(tmp) if err != nil { @@ -981,17 +976,10 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } func (ec *executionContext) _Query_hero(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 Episode - if tmp, ok := field.Args["episode"]; ok { - var err error - err = (&arg0).UnmarshalGQL(tmp) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - } else { - var tmp interface{} = "NEWHOPE" + if tmp, ok := rawArgs["episode"]; ok { var err error err = (&arg0).UnmarshalGQL(tmp) if err != nil { @@ -999,7 +987,6 @@ func (ec *executionContext) _Query_hero(ctx context.Context, field graphql.Colle return graphql.Null } } - args["episode"] = arg0 ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ Object: "Query", @@ -1027,9 +1014,10 @@ func (ec *executionContext) _Query_hero(ctx context.Context, field graphql.Colle } func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 Episode - if tmp, ok := field.Args["episode"]; ok { + if tmp, ok := rawArgs["episode"]; ok { var err error err = (&arg0).UnmarshalGQL(tmp) if err != nil { @@ -1039,7 +1027,7 @@ func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.Co } args["episode"] = arg0 var arg1 *time.Time - if tmp, ok := field.Args["since"]; ok { + if tmp, ok := rawArgs["since"]; ok { var err error var ptr1 time.Time if tmp != nil { @@ -1088,9 +1076,10 @@ func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.Co } func (ec *executionContext) _Query_search(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 string - if tmp, ok := field.Args["text"]; ok { + if tmp, ok := rawArgs["text"]; ok { var err error arg0, err = graphql.UnmarshalString(tmp) if err != nil { @@ -1134,9 +1123,10 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col } func (ec *executionContext) _Query_character(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 string - if tmp, ok := field.Args["id"]; ok { + if tmp, ok := rawArgs["id"]; ok { var err error arg0, err = graphql.UnmarshalID(tmp) if err != nil { @@ -1171,9 +1161,10 @@ func (ec *executionContext) _Query_character(ctx context.Context, field graphql. } func (ec *executionContext) _Query_droid(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 string - if tmp, ok := field.Args["id"]; ok { + if tmp, ok := rawArgs["id"]; ok { var err error arg0, err = graphql.UnmarshalID(tmp) if err != nil { @@ -1211,9 +1202,10 @@ func (ec *executionContext) _Query_droid(ctx context.Context, field graphql.Coll } func (ec *executionContext) _Query_human(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 string - if tmp, ok := field.Args["id"]; ok { + if tmp, ok := rawArgs["id"]; ok { var err error arg0, err = graphql.UnmarshalID(tmp) if err != nil { @@ -1251,9 +1243,10 @@ func (ec *executionContext) _Query_human(ctx context.Context, field graphql.Coll } func (ec *executionContext) _Query_starship(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 string - if tmp, ok := field.Args["id"]; ok { + if tmp, ok := rawArgs["id"]; ok { var err error arg0, err = graphql.UnmarshalID(tmp) if err != nil { @@ -1291,9 +1284,10 @@ func (ec *executionContext) _Query_starship(ctx context.Context, field graphql.C } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 string - if tmp, ok := field.Args["name"]; ok { + if tmp, ok := rawArgs["name"]; ok { var err error arg0, err = graphql.UnmarshalString(tmp) if err != nil { @@ -1486,17 +1480,10 @@ func (ec *executionContext) _Starship_name(ctx context.Context, field graphql.Co } func (ec *executionContext) _Starship_length(ctx context.Context, field graphql.CollectedField, obj *Starship) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 LengthUnit - if tmp, ok := field.Args["unit"]; ok { - var err error - err = (&arg0).UnmarshalGQL(tmp) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - } else { - var tmp interface{} = "METER" + if tmp, ok := rawArgs["unit"]; ok { var err error err = (&arg0).UnmarshalGQL(tmp) if err != nil { @@ -1504,7 +1491,6 @@ func (ec *executionContext) _Starship_length(ctx context.Context, field graphql. return graphql.Null } } - args["unit"] = arg0 ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ Object: "Starship", @@ -2259,9 +2245,10 @@ 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 { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { + if tmp, ok := rawArgs["includeDeprecated"]; ok { var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { @@ -2348,9 +2335,10 @@ 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 { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { + if tmp, ok := rawArgs["includeDeprecated"]; ok { var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { diff --git a/example/todo/generated.go b/example/todo/generated.go index 0ba31153622..58ee947ae85 100644 --- a/example/todo/generated.go +++ b/example/todo/generated.go @@ -32,7 +32,7 @@ type ResolverRoot interface { } type DirectiveRoot struct { - HasRole func(ctx context.Context, next graphql.Resolver, role string) (res interface{}, err error) + HasRole func(ctx context.Context, next graphql.Resolver, role Role) (res interface{}, err error) } type MyMutationResolver interface { CreateTodo(ctx context.Context, todo TodoInput) (Todo, error) @@ -1408,22 +1408,22 @@ func (ec *executionContext) FieldMiddleware(ctx context.Context, next graphql.Re for _, d := range rctx.Field.Definition.Directives { switch d.Name { case "hasRole": - rawArgs := d.ArgumentMap(ec.Variables) - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["role"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - } - args["role"] = arg0 if ec.directives.HasRole != nil { + rawArgs := d.ArgumentMap(ec.Variables) + args := map[string]interface{}{} + var arg0 Role + if tmp, ok := rawArgs["role"]; ok { + var err error + err = (&arg0).UnmarshalGQL(tmp) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + } + args["role"] = arg0 n := next next = func(ctx context.Context) (interface{}, error) { - return ec.directives.HasRole(ctx, n, args["role"].(string)) + return ec.directives.HasRole(ctx, n, args["role"].(Role)) } } } @@ -1475,7 +1475,7 @@ input TodoInput { scalar Map -directive @hasRole(role: String!) on FIELD_DEFINITION +directive @hasRole(role: Role!) on FIELD_DEFINITION enum Role { ADMIN diff --git a/test/generated.go b/test/generated.go index 3c3678894a0..d0b916fe451 100644 --- a/test/generated.go +++ b/test/generated.go @@ -279,9 +279,10 @@ func (ec *executionContext) _Query_path(ctx context.Context, field graphql.Colle } func (ec *executionContext) _Query_date(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 models.DateFilter - if tmp, ok := field.Args["filter"]; ok { + if tmp, ok := rawArgs["filter"]; ok { var err error arg0, err = UnmarshalDateFilter(tmp) if err != nil { @@ -371,9 +372,10 @@ func (ec *executionContext) _Query_jsonEncoding(ctx context.Context, field graph } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 string - if tmp, ok := field.Args["name"]; ok { + if tmp, ok := rawArgs["name"]; ok { var err error arg0, err = graphql.UnmarshalString(tmp) if err != nil { @@ -1234,9 +1236,10 @@ 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 { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { + if tmp, ok := rawArgs["includeDeprecated"]; ok { var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil { @@ -1323,9 +1326,10 @@ 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 { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { + if tmp, ok := rawArgs["includeDeprecated"]; ok { var err error arg0, err = graphql.UnmarshalBoolean(tmp) if err != nil {