From 4f37d17028f85eb6e12009d26bea8604e332f766 Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Wed, 1 Aug 2018 16:16:57 +1000 Subject: [PATCH 1/2] Add directive args --- Gopkg.lock | 4 +-- codegen/build.go | 6 +++- codegen/directive.go | 28 +++++++++++++++++ codegen/directive_build.go | 35 +++++++++++++++++++-- codegen/object.go | 4 +++ codegen/templates/args.gotpl | 17 ++-------- codegen/templates/field.gotpl | 10 ++++-- codegen/templates/generated.gotpl | 8 +++-- example/todo/generated.go | 52 ++++++++++++++++++++++--------- example/todo/models_gen.go | 42 +++++++++++++++++++++++++ example/todo/schema.graphql | 9 ++++-- example/todo/todo.go | 4 +-- graphql/exec.go | 20 +----------- 13 files changed, 177 insertions(+), 62 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 85008b51271..b61ca468f89 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -176,7 +176,7 @@ [[projects]] branch = "master" - digest = "1:80b5cf44d45e12f0e9b1665cf564b123a292850ce80128342e4c74b57a42c3b1" + digest = "1:07b9c7ab78ec48004cf88b4d93c10cad32c7e21b49f99db418fb0ebee0f98b90" name = "github.com/vektah/gqlparser" packages = [ ".", @@ -188,7 +188,7 @@ "validator/rules", ] pruneopts = "UT" - revision = "9d2a87e05c6d27ae2bab1bc914aaa9c21cf35d9a" + revision = "8dd97c3c1c0357d7602ca9435a8a6cb5e57b4171" [[projects]] branch = "master" diff --git a/codegen/build.go b/codegen/build.go index a2f29d4ed48..2f6f1e601e0 100644 --- a/codegen/build.go +++ b/codegen/build.go @@ -141,6 +141,10 @@ func (cfg *Config) bind() (*Build, error) { if err != nil { return nil, err } + directives, err := cfg.buildDirectives(namedTypes) + if err != nil { + return nil, err + } b := &Build{ PackageName: cfg.Exec.Package, @@ -150,7 +154,7 @@ func (cfg *Config) bind() (*Build, error) { Imports: imports.finalize(), SchemaRaw: cfg.SchemaStr, SchemaFilename: cfg.SchemaFilename, - Directives: cfg.buildDirectives(), + Directives: directives, } if cfg.schema.Query != nil { diff --git a/codegen/directive.go b/codegen/directive.go index aeeda1dcb63..ee49788bc2f 100644 --- a/codegen/directive.go +++ b/codegen/directive.go @@ -1,5 +1,33 @@ package codegen +import ( + "fmt" + "strconv" + "strings" +) + type Directive struct { Name string + Args []FieldArgument +} + +func (d *Directive) CallArgs() string { + args := []string{"ctx", "n"} + + for _, arg := range d.Args { + args = append(args, "args["+strconv.Quote(arg.GQLName)+"].("+arg.Signature()+")") + } + + return strings.Join(args, ", ") +} + +func (d *Directive) Declaration() string { + res := ucFirst(d.Name) + " func(ctx context.Context, next graphql.Resolver" + + for _, arg := range d.Args { + res += fmt.Sprintf(", %s %s", arg.GoVarName, arg.Signature()) + } + + res += ") (res interface{}, err error)" + return res } diff --git a/codegen/directive_build.go b/codegen/directive_build.go index 1d47d381432..e95a0e6690e 100644 --- a/codegen/directive_build.go +++ b/codegen/directive_build.go @@ -1,13 +1,42 @@ package codegen -func (cfg *Config) buildDirectives() (directives []*Directive) { - for name := range cfg.schema.Directives { +import "github.com/pkg/errors" + +func (cfg *Config) buildDirectives(types NamedTypes) ([]*Directive, error) { + var directives []*Directive + + for name, dir := range cfg.schema.Directives { if name == "skip" || name == "include" || name == "deprecated" { continue } + + var args []FieldArgument + for _, arg := range dir.Arguments { + newArg := FieldArgument{ + GQLName: arg.Name, + Type: types.getType(arg.Type), + GoVarName: sanitizeGoName(arg.Name), + } + + if !newArg.Type.IsInput && !newArg.Type.IsScalar { + return nil, errors.Errorf("%s cannot be used as argument of directive %s(%s) only input and scalar types are allowed", arg.Type, dir.Name, arg.Name) + } + + if arg.DefaultValue != nil { + var err error + newArg.Default, err = arg.DefaultValue.Value(nil) + if err != nil { + return nil, errors.Errorf("default value for directive argument %s(%s) is not valid: %s", dir.Name, arg.Name, err.Error()) + } + newArg.StripPtr() + } + args = append(args, newArg) + } + directives = append(directives, &Directive{ Name: name, + Args: args, }) } - return directives + return directives, nil } diff --git a/codegen/object.go b/codegen/object.go index 319bbda6714..c9cf52ddbe1 100644 --- a/codegen/object.go +++ b/codegen/object.go @@ -219,6 +219,10 @@ func (f *Field) doWriteJson(val string, remainingMods []string, isPtr bool, dept } } +func (f *FieldArgument) Stream() bool { + return f.Object != nil && f.Object.Stream +} + func (os Objects) ByName(name string) *Object { for i, o := range os { if strings.EqualFold(o.GQLType, name) { diff --git a/codegen/templates/args.gotpl b/codegen/templates/args.gotpl index f53aceec1e5..db6a0b6bd9e 100644 --- a/codegen/templates/args.gotpl +++ b/codegen/templates/args.gotpl @@ -1,30 +1,17 @@ {{- if . }}args := map[string]interface{}{} {{end}} {{- range $i, $arg := . }} var arg{{$i}} {{$arg.Signature }} - if tmp, ok := field.Args[{{$arg.GQLName|quote}}]; ok { + if tmp, ok := rawArgs[{{$arg.GQLName|quote}}]; ok { var err error {{$arg.Unmarshal (print "arg" $i) "tmp" }} if err != nil { ec.Error(ctx, err) - {{- if $arg.Object.Stream }} - return nil - {{- else }} - return graphql.Null - {{- end }} - } - } {{ if $arg.Default }} else { - var tmp interface{} = {{ $arg.Default | dump }} - var err error - {{$arg.Unmarshal (print "arg" $i) "tmp" }} - if err != nil { - ec.Error(ctx, err) - {{- if $arg.Object.Stream }} + {{- if $arg.Stream }} return nil {{- else }} return graphql.Null {{- end }} } } - {{end }} args[{{$arg.GQLName|quote}}] = arg{{$i}} {{- end -}} diff --git a/codegen/templates/field.gotpl b/codegen/templates/field.gotpl index 8e252adefaa..c324a4ecddf 100644 --- a/codegen/templates/field.gotpl +++ b/codegen/templates/field.gotpl @@ -3,7 +3,10 @@ {{- if $object.Stream }} func (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { - {{- template "args.gotpl" $field.Args }} + {{- if $field.Args }} + rawArgs := field.ArgumentMap(ec.Variables) + {{ template "args.gotpl" $field.Args }} + {{- end }} ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) results, err := ec.resolvers.{{ $field.ShortInvocation }} if err != nil { @@ -22,7 +25,10 @@ } {{ else }} func (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField, {{if not $object.Root}}obj *{{$object.FullName}}{{end}}) graphql.Marshaler { - {{- template "args.gotpl" $field.Args }} + {{- if $field.Args }} + rawArgs := field.ArgumentMap(ec.Variables) + {{ template "args.gotpl" $field.Args }} + {{- end }} {{- if $field.IsConcurrent }} ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ diff --git a/codegen/templates/generated.gotpl b/codegen/templates/generated.gotpl index cdeaba69d5e..fd2364c4f8f 100644 --- a/codegen/templates/generated.gotpl +++ b/codegen/templates/generated.gotpl @@ -31,7 +31,7 @@ type ResolverRoot interface { type DirectiveRoot struct { {{ range $directive := .Directives }} - {{$directive.Name|ucFirst}} graphql.FieldMiddleware + {{ $directive.Declaration }} {{ end }} } @@ -155,9 +155,13 @@ func (ec *executionContext) FieldMiddleware(ctx context.Context, next graphql.Re {{- range $directive := .Directives }} case "{{$directive.Name}}": if ec.directives.{{$directive.Name|ucFirst}} != nil { + {{- if $directive.Args }} + rawArgs := d.ArgumentMap(ec.Variables) + {{ template "args.gotpl" $directive.Args }} + {{- end }} n := next next = func(ctx context.Context) (interface{}, error) { - return ec.directives.{{$directive.Name|ucFirst}}(ctx, n) + return ec.directives.{{$directive.Name|ucFirst}}({{$directive.CallArgs}}) } } {{- end }} diff --git a/example/todo/generated.go b/example/todo/generated.go index 66f2e5acc55..0ba31153622 100644 --- a/example/todo/generated.go +++ b/example/todo/generated.go @@ -32,7 +32,7 @@ type ResolverRoot interface { } type DirectiveRoot struct { - IsAuthenticated graphql.FieldMiddleware + HasRole func(ctx context.Context, next graphql.Resolver, role string) (res interface{}, err error) } type MyMutationResolver interface { CreateTodo(ctx context.Context, todo TodoInput) (Todo, error) @@ -125,9 +125,10 @@ func (ec *executionContext) _MyMutation(ctx context.Context, sel ast.SelectionSe } func (ec *executionContext) _MyMutation_createTodo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} var arg0 TodoInput - if tmp, ok := field.Args["todo"]; ok { + if tmp, ok := rawArgs["todo"]; ok { var err error arg0, err = UnmarshalTodoInput(tmp) if err != nil { @@ -153,9 +154,10 @@ func (ec *executionContext) _MyMutation_createTodo(ctx context.Context, field gr } func (ec *executionContext) _MyMutation_updateTodo(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["id"]; ok { + if tmp, ok := rawArgs["id"]; ok { var err error arg0, err = graphql.UnmarshalInt(tmp) if err != nil { @@ -165,7 +167,7 @@ func (ec *executionContext) _MyMutation_updateTodo(ctx context.Context, field gr } args["id"] = arg0 var arg1 map[string]interface{} - if tmp, ok := field.Args["changes"]; ok { + if tmp, ok := rawArgs["changes"]; ok { var err error arg1 = tmp.(map[string]interface{}) if err != nil { @@ -231,9 +233,10 @@ func (ec *executionContext) _MyQuery(ctx context.Context, sel ast.SelectionSet) } func (ec *executionContext) _MyQuery_todo(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["id"]; ok { + if tmp, ok := rawArgs["id"]; ok { var err error arg0, err = graphql.UnmarshalInt(tmp) if err != nil { @@ -271,9 +274,10 @@ func (ec *executionContext) _MyQuery_todo(ctx context.Context, field graphql.Col } func (ec *executionContext) _MyQuery_authenticatedTodo(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["id"]; ok { + if tmp, ok := rawArgs["id"]; ok { var err error arg0, err = graphql.UnmarshalInt(tmp) if err != nil { @@ -375,9 +379,10 @@ func (ec *executionContext) _MyQuery_todos(ctx context.Context, field graphql.Co } func (ec *executionContext) _MyQuery___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 { @@ -1196,9 +1201,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 { @@ -1285,9 +1291,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 { @@ -1400,11 +1407,23 @@ func (ec *executionContext) FieldMiddleware(ctx context.Context, next graphql.Re rctx := graphql.GetResolverContext(ctx) for _, d := range rctx.Field.Definition.Directives { switch d.Name { - case "isAuthenticated": - if ec.directives.IsAuthenticated != nil { + 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 { n := next next = func(ctx context.Context) (interface{}, error) { - return ec.directives.IsAuthenticated(ctx, n) + return ec.directives.HasRole(ctx, n, args["role"].(string)) } } } @@ -1433,7 +1452,7 @@ var parsedSchema = gqlparser.MustLoadSchema( type MyQuery { todo(id: Int!): Todo - authenticatedTodo(id: Int!): Todo @isAuthenticated + authenticatedTodo(id: Int!): Todo @hasRole(role: ADMIN) lastTodo: Todo todos: [Todo!]! } @@ -1456,6 +1475,11 @@ input TodoInput { scalar Map -directive @isAuthenticated on FIELD_DEFINITION +directive @hasRole(role: String!) on FIELD_DEFINITION + +enum Role { + ADMIN + USER +} `}, ) diff --git a/example/todo/models_gen.go b/example/todo/models_gen.go index 0f734aae9ce..9ca2784eb06 100644 --- a/example/todo/models_gen.go +++ b/example/todo/models_gen.go @@ -2,6 +2,12 @@ package todo +import ( + fmt "fmt" + io "io" + strconv "strconv" +) + type Todo struct { ID int `json:"id"` Text string `json:"text"` @@ -11,3 +17,39 @@ type TodoInput struct { Text string `json:"text"` Done *bool `json:"done"` } + +type Role string + +const ( + RoleAdmin Role = "ADMIN" + RoleUser Role = "USER" +) + +func (e Role) IsValid() bool { + switch e { + case RoleAdmin, RoleUser: + return true + } + return false +} + +func (e Role) String() string { + return string(e) +} + +func (e *Role) UnmarshalGQL(v interface{}) error { + str, ok := v.(string) + if !ok { + return fmt.Errorf("enums must be strings") + } + + *e = Role(str) + if !e.IsValid() { + return fmt.Errorf("%s is not a valid Role", str) + } + return nil +} + +func (e Role) MarshalGQL(w io.Writer) { + fmt.Fprint(w, strconv.Quote(e.String())) +} diff --git a/example/todo/schema.graphql b/example/todo/schema.graphql index bdc631b016c..fd84dbef9db 100644 --- a/example/todo/schema.graphql +++ b/example/todo/schema.graphql @@ -5,7 +5,7 @@ schema { type MyQuery { todo(id: Int!): Todo - authenticatedTodo(id: Int!): Todo @isAuthenticated + authenticatedTodo(id: Int!): Todo @hasRole(role: ADMIN) lastTodo: Todo todos: [Todo!]! } @@ -28,4 +28,9 @@ input TodoInput { scalar Map -directive @isAuthenticated on FIELD_DEFINITION +directive @hasRole(role: Role!) on FIELD_DEFINITION + +enum Role { + ADMIN + USER +} diff --git a/example/todo/todo.go b/example/todo/todo.go index 087e58c2e16..8aad90a9c8f 100644 --- a/example/todo/todo.go +++ b/example/todo/todo.go @@ -22,11 +22,11 @@ func New() Config { lastID: 3, }, } - c.Directives.IsAuthenticated = func(ctx context.Context, next graphql.Resolver) (interface{}, error) { + c.Directives.HasRole = func(ctx context.Context, next graphql.Resolver, role Role) (interface{}, error) { rctx := graphql.GetResolverContext(ctx) idVal := rctx.Field.Arguments.ForName("id").Value id, _ := idVal.Value(make(map[string]interface{})) - if id.(int64) == 1 { + if id.(int64) == 1 && role == RoleAdmin { return nil, nil } return next(ctx) diff --git a/graphql/exec.go b/graphql/exec.go index 5231abc2bd8..387c34cc091 100644 --- a/graphql/exec.go +++ b/graphql/exec.go @@ -29,24 +29,7 @@ func collectFields(reqCtx *RequestContext, selSet ast.SelectionSet, satisfies [] continue } f := getOrCreateField(&groupedFields, sel.Alias, func() CollectedField { - f := CollectedField{Field: sel} - if len(sel.Arguments) > 0 { - f.Args = map[string]interface{}{} - for _, arg := range sel.Arguments { - if arg.Value.Kind == ast.Variable { - if val, ok := reqCtx.Variables[arg.Value.Raw]; ok { - f.Args[arg.Name] = val - } - } else { - var err error - f.Args[arg.Name], err = arg.Value.Value(reqCtx.Variables) - if err != nil { - panic(err) - } - } - } - } - return f + return CollectedField{Field: sel} }) f.Selections = append(f.Selections, sel.SelectionSet...) @@ -95,7 +78,6 @@ func collectFields(reqCtx *RequestContext, selSet ast.SelectionSet, satisfies [] type CollectedField struct { *ast.Field - Args map[string]interface{} Selections ast.SelectionSet } From 3bef596d022a4c58c30e7f1c73adc3b7dec918d3 Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Wed, 1 Aug 2018 16:50:15 +1000 Subject: [PATCH 2/2] regenerate --- codegen/templates/data.go | 6 +-- example/chat/generated.go | 22 +++++---- example/config/generated.go | 12 +++-- example/dataloader/generated.go | 12 +++-- example/scalars/generated.go | 24 +++++----- example/selection/generated.go | 9 ++-- example/starwars/generated.go | 80 ++++++++++++++------------------- example/todo/generated.go | 30 ++++++------- test/generated.go | 12 +++-- 9 files changed, 106 insertions(+), 101 deletions(-) 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 {