diff --git a/.gometalinter.json b/.gometalinter.json index 71b1eb26e66..ab1c96e4fbd 100644 --- a/.gometalinter.json +++ b/.gometalinter.json @@ -1,5 +1,6 @@ { "sort": ["path"], + "Deadline": "2m", "Linters": { "errcheck": { "Command": "errcheck -abspath -ignore '[rR]ead|[wW]rite|Close'", diff --git a/Gopkg.lock b/Gopkg.lock index 2a378d5a6f8..0480a7363e8 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -7,6 +7,33 @@ revision = "346938d642f2ec3594ed81d874461961cd0faa76" version = "v1.1.0" +[[projects]] + name = "github.com/go-chi/chi" + packages = ["."] + revision = "e83ac2304db3c50cf03d96a2fcd39009d458bc35" + version = "v3.3.2" + +[[projects]] + name = "github.com/gogo/protobuf" + packages = [ + "io", + "proto" + ] + revision = "1adfc126b41513cc696b209667c8656ea7aac67c" + version = "v1.0.0" + +[[projects]] + name = "github.com/gorilla/context" + packages = ["."] + revision = "1ea25387ff6f684839d82767c1733ff4d4d15d0a" + version = "v1.1" + +[[projects]] + name = "github.com/gorilla/mux" + packages = ["."] + revision = "53c1911da2b537f792e7cafcb446b05ffe33b996" + version = "v1.6.1" + [[projects]] name = "github.com/gorilla/websocket" packages = ["."] @@ -19,6 +46,31 @@ packages = ["."] revision = "a4e142e9c047c904fa2f1e144d9a84e6133024bc" +[[projects]] + branch = "master" + name = "github.com/opentracing-contrib/go-stdlib" + packages = ["nethttp"] + revision = "36723135187404d2f4002f4f189938565e64cc5c" + +[[projects]] + name = "github.com/opentracing/basictracer-go" + packages = [ + ".", + "wire" + ] + revision = "1b32af207119a14b1b231d451df3ed04a72efebf" + version = "v1.0.0" + +[[projects]] + name = "github.com/opentracing/opentracing-go" + packages = [ + ".", + "ext", + "log" + ] + revision = "1949ddbfd147afd4d964a9f00b24eb291e0e7c38" + version = "v1.0.2" + [[projects]] name = "github.com/pkg/errors" packages = ["."] @@ -31,6 +83,18 @@ revision = "792786c7400a136282c1664665ae0a8db921c6c2" version = "v1.0.0" +[[projects]] + branch = "master" + name = "github.com/shurcooL/httpfs" + packages = ["vfsutil"] + revision = "809beceb23714880abc4a382a00c05f89d13b1cc" + +[[projects]] + branch = "master" + name = "github.com/shurcooL/vfsgen" + packages = ["."] + revision = "ffb13db8def02f545acc58bd288ec6057c2bbfb9" + [[projects]] name = "github.com/stretchr/testify" packages = [ @@ -46,6 +110,12 @@ packages = ["."] revision = "92d08f61dc2b9f5c37f5eea31a8558d64c2ed6a7" +[[projects]] + branch = "master" + name = "golang.org/x/net" + packages = ["context"] + revision = "b3c676e531a6dc479fa1b35ac961c13f5e2b4d2e" + [[projects]] branch = "master" name = "golang.org/x/tools" @@ -57,9 +127,29 @@ ] revision = "ce871d178848e3eea1e8795e5cfb74053dde4bb9" +[[projects]] + branch = "master" + name = "sourcegraph.com/sourcegraph/appdash" + packages = [ + ".", + "httptrace", + "internal/wire", + "opentracing", + "sqltrace", + "traceapp", + "traceapp/tmpl" + ] + revision = "2cc67fd647551af94593ecaaa89fe4e5b2940a3e" + +[[projects]] + branch = "master" + name = "sourcegraph.com/sourcegraph/appdash-data" + packages = ["."] + revision = "73f23eafcf67cad684fba328dd545a116ac273ff" + [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "6459bea7b3bbce31e060ddb28812c3125daed57efd28be0dcf708ec492fac823" + inputs-digest = "5275b6a5c88fd233faf5afa8f59f3a36ae9fe6538ee6331fac3c1078fecd6df5" solver-name = "gps-cdcl" solver-version = 1 diff --git a/codegen/object.go b/codegen/object.go index 4751e5b7801..3fd1f63ddad 100644 --- a/codegen/object.go +++ b/codegen/object.go @@ -89,8 +89,8 @@ func (f *Field) CallArgs() string { } } - for i := range f.Args { - args = append(args, "arg"+strconv.Itoa(i)) + for _, arg := range f.Args { + args = append(args, "args["+strconv.Quote(arg.GQLName)+"].("+arg.Signature()+")") } return strings.Join(args, ", ") diff --git a/codegen/templates/args.gotpl b/codegen/templates/args.gotpl index 4e809a4850c..af0f5829b69 100644 --- a/codegen/templates/args.gotpl +++ b/codegen/templates/args.gotpl @@ -1,3 +1,4 @@ + {{- if . }}args := map[string]interface{}{} {{end}} {{- range $i, $arg := . }} var arg{{$i}} {{$arg.Signature }} if tmp, ok := field.Args[{{$arg.GQLName|quote}}]; ok { @@ -25,4 +26,5 @@ } } {{end }} + args[{{$arg.GQLName|quote}}] = arg{{$i}} {{- end -}} diff --git a/codegen/templates/data.go b/codegen/templates/data.go index f03929a6d2d..69c49f59ac1 100644 --- a/codegen/templates/data.go +++ b/codegen/templates/data.go @@ -1,8 +1,8 @@ package templates var data = map[string]string{ - "args.gotpl": "\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(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(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{{- 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\trctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field})\n\t\tresults, err := ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }})\n\t\tif err != nil {\n\t\t\tec.Error(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\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(r)\n\t\t\t\t\t\tec.Error(userErr)\n\t\t\t\t\t\tret = graphql.Null\n\t\t\t\t\t}\n\t\t\t\t}()\n\t\t{{- end }}\n\n\t\t\t{{- if $field.GoVarName }}\n\t\t\t\tres := obj.{{$field.GoVarName}}\n\t\t\t{{- else if $field.GoMethodName }}\n\t\t\t\t{{- if $field.NoErr }}\n\t\t\t\t\tres := {{$field.GoMethodName}}({{ $field.CallArgs }})\n\t\t\t\t{{- else }}\n\t\t\t\t\tres, err := {{$field.GoMethodName}}({{ $field.CallArgs }})\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tec.Error(err)\n\t\t\t\t\t\treturn graphql.Null\n\t\t\t\t\t}\n\t\t\t\t{{- end }}\n\t\t\t{{- else }}\n\t\t\t\trctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field})\n\t\t\t\tres, err := ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }})\n\t\t\t\tif err != nil {\n\t\t\t\t\tec.Error(err)\n\t\t\t\t\treturn graphql.Null\n\t\t\t\t}\n\t\t\t{{- end }}\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", + "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(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(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\trctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field})\n\t\tresults, err := ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }})\n\t\tif err != nil {\n\t\t\tec.Error(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\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(r)\n\t\t\t\t\t\tec.Error(userErr)\n\t\t\t\t\t\tret = graphql.Null\n\t\t\t\t\t}\n\t\t\t\t}()\n\t\t{{- end }}\n\n\t\t\t{{- if $field.GoVarName }}\n\t\t\t\tres := obj.{{$field.GoVarName}}\n\t\t\t{{- else if $field.GoMethodName }}\n\t\t\t\t{{- if $field.NoErr }}\n\t\t\t\t\tres := {{$field.GoMethodName}}({{ $field.CallArgs }})\n\t\t\t\t{{- else }}\n\t\t\t\t\tres, err := {{$field.GoMethodName}}({{ $field.CallArgs }})\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tec.Error(err)\n\t\t\t\t\t\treturn graphql.Null\n\t\t\t\t\t}\n\t\t\t\t{{- end }}\n\t\t\t{{- else }}\n\t\t\t\trctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\t\t\t\tObject: {{$object.GQLType|quote}},\n\t\t\t\t\tArgs: {{if $field.Args }}args{{else}}nil{{end}},\n\t\t\t\t\tField: field,\n\t\t\t\t})\n\t\t\t\tresTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) {\n\t\t\t\t\treturn ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }})\n\t\t\t\t})\n\t\t\t\tif err != nil {\n\t\t\t\t\tec.Error(err)\n\t\t\t\t\treturn graphql.Null\n\t\t\t\t}\n\t\t\t\tif resTmp == nil {\n\t\t\t\t\treturn graphql.Null\n\t\t\t\t}\n\t\t\t\tres := resTmp.({{$field.Signature}})\n\t\t\t{{- end }}\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": "// This file was 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\nfunc MakeExecutableSchema(resolvers Resolvers) graphql.ExecutableSchema {\n\treturn &executableSchema{resolvers: resolvers}\n}\n\ntype Resolvers interface {\n{{- range $object := .Objects -}}\n\t{{ range $field := $object.Fields -}}\n\t\t{{ $field.ResolverDeclaration }}\n\t{{ end }}\n{{- end }}\n}\n\ntype executableSchema struct {\n\tresolvers Resolvers\n}\n\nfunc (e *executableSchema) Schema() *schema.Schema {\n\treturn parsedSchema\n}\n\nfunc (e *executableSchema) Query(ctx context.Context, op *query.Operation) *graphql.Response {\n\t{{- if .QueryRoot }}\n\t\tec := executionContext{graphql.GetRequestContext(ctx), e.resolvers}\n\n\t\tdata := ec._{{.QueryRoot.GQLType}}(ctx, op.Selections)\n\t\tvar buf bytes.Buffer\n\t\tdata.MarshalGQL(&buf)\n\n\t\treturn &graphql.Response{\n\t\t\tData: buf.Bytes(),\n\t\t\tErrors: ec.Errors,\n\t\t}\n\t{{- else }}\n\t\treturn &graphql.Response{Errors: []*errors.QueryError{ {Message: \"queries are not supported\"} }}\n\t{{- end }}\n}\n\nfunc (e *executableSchema) Mutation(ctx context.Context, op *query.Operation) *graphql.Response {\n\t{{- if .MutationRoot }}\n\t\tec := executionContext{graphql.GetRequestContext(ctx), e.resolvers}\n\n\t\tdata := ec._{{.MutationRoot.GQLType}}(ctx, op.Selections)\n\t\tvar buf bytes.Buffer\n\t\tdata.MarshalGQL(&buf)\n\n\t\treturn &graphql.Response{\n\t\t\tData: buf.Bytes(),\n\t\t\tErrors: ec.Errors,\n\t\t}\n\t{{- else }}\n\t\treturn &graphql.Response{Errors: []*errors.QueryError{ {Message: \"mutations are not supported\"} }}\n\t{{- end }}\n}\n\nfunc (e *executableSchema) Subscription(ctx context.Context, op *query.Operation) func() *graphql.Response {\n\t{{- if .SubscriptionRoot }}\n\t\tec := executionContext{graphql.GetRequestContext(ctx), e.resolvers}\n\n\t\tnext := ec._{{.SubscriptionRoot.GQLType}}(ctx, op.Selections)\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.Reset()\n\t\t\tdata := next()\n\t\t\tif data == nil {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\tdata.MarshalGQL(&buf)\n\n\t\t\terrs := ec.Errors\n\t\t\tec.Errors = nil\n\t\t\treturn &graphql.Response{\n\t\t\t\tData: buf.Bytes(),\n\t\t\t\tErrors: errs,\n\t\t\t}\n\t\t}\n\t{{- else }}\n\t\treturn graphql.OneShot(&graphql.Response{Errors: []*errors.QueryError{ {Message: \"subscriptions are not supported\"} }})\n\t{{- end }}\n}\n\ntype executionContext struct {\n\t*graphql.RequestContext\n\n\tresolvers Resolvers\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) introspectSchema() *introspection.Schema {\n\treturn introspection.WrapSchema(parsedSchema)\n}\n\nfunc (ec *executionContext) introspectType(name string) *introspection.Type {\n\tt := parsedSchema.Resolve(name)\n\tif t == nil {\n\t\treturn nil\n\t}\n\treturn introspection.WrapType(t)\n}\n\nvar parsedSchema = schema.MustParse({{.SchemaRaw|rawQuote}})\n", "input.gotpl": "\t{{- if .IsMarshaled }}\n\tfunc Unmarshal{{ .GQLType }}(v interface{}) ({{.FullName}}, error) {\n\t\tvar it {{.FullName}}\n\n\t\tfor k, v := range v.(map[string]interface{}) {\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.GoVarName) \"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 []query.Selection, 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", diff --git a/codegen/templates/field.gotpl b/codegen/templates/field.gotpl index 2f6bb87438a..9ab270b572e 100644 --- a/codegen/templates/field.gotpl +++ b/codegen/templates/field.gotpl @@ -48,12 +48,22 @@ } {{- end }} {{- else }} - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }}) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: {{$object.GQLType|quote}}, + Args: {{if $field.Args }}args{{else}}nil{{end}}, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }}) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.({{$field.Signature}}) {{- end }} {{ $field.WriteJson }} {{- if $field.IsConcurrent }} diff --git a/example/chat/generated.go b/example/chat/generated.go index c022e2c2101..6bf8922d3b1 100644 --- a/example/chat/generated.go +++ b/example/chat/generated.go @@ -199,6 +199,7 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel []query.Selection } func (ec *executionContext) _Mutation_post(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 string if tmp, ok := field.Args["text"]; ok { var err error @@ -208,6 +209,7 @@ func (ec *executionContext) _Mutation_post(ctx context.Context, field graphql.Co return graphql.Null } } + args["text"] = arg0 var arg1 string if tmp, ok := field.Args["username"]; ok { var err error @@ -217,6 +219,7 @@ func (ec *executionContext) _Mutation_post(ctx context.Context, field graphql.Co return graphql.Null } } + args["username"] = arg1 var arg2 string if tmp, ok := field.Args["roomName"]; ok { var err error @@ -226,12 +229,23 @@ func (ec *executionContext) _Mutation_post(ctx context.Context, field graphql.Co return graphql.Null } } - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Mutation_post(rctx, arg0, arg1, arg2) + args["roomName"] = arg2 + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Mutation", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Mutation_post(rctx, args["text"].(string), args["username"].(string), args["roomName"].(string)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(Message) return ec._Message(ctx, field.Selections, &res) } @@ -262,6 +276,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel []query.Selection) g } func (ec *executionContext) _Query_room(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 string if tmp, ok := field.Args["name"]; ok { var err error @@ -271,6 +286,7 @@ func (ec *executionContext) _Query_room(ctx context.Context, field graphql.Colle return graphql.Null } } + args["name"] = arg0 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -279,12 +295,22 @@ func (ec *executionContext) _Query_room(ctx context.Context, field graphql.Colle ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_room(rctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_room(rctx, args["name"].(string)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Chatroom) if res == nil { return graphql.Null } @@ -301,6 +327,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 string if tmp, ok := field.Args["name"]; ok { var err error @@ -310,7 +337,8 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col return graphql.Null } } - res := ec.introspectType(arg0) + args["name"] = arg0 + res := ec.introspectType(args["name"].(string)) if res == nil { return graphql.Null } @@ -337,6 +365,7 @@ func (ec *executionContext) _Subscription(ctx context.Context, sel []query.Selec } func (ec *executionContext) _Subscription_messageAdded(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { + args := map[string]interface{}{} var arg0 string if tmp, ok := field.Args["roomName"]; ok { var err error @@ -346,8 +375,9 @@ func (ec *executionContext) _Subscription_messageAdded(ctx context.Context, fiel return nil } } + args["roomName"] = arg0 rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - results, err := ec.resolvers.Subscription_messageAdded(rctx, arg0) + results, err := ec.resolvers.Subscription_messageAdded(rctx, args["roomName"].(string)) if err != nil { ec.Error(err) return nil @@ -760,6 +790,7 @@ 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 { + args := map[string]interface{}{} var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -769,7 +800,8 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co return graphql.Null } } - res := obj.Fields(arg0) + args["includeDeprecated"] = arg0 + res := obj.Fields(args["includeDeprecated"].(bool)) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { @@ -811,6 +843,7 @@ 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 { + args := map[string]interface{}{} var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -820,7 +853,8 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq return graphql.Null } } - res := obj.EnumValues(arg0) + args["includeDeprecated"] = arg0 + res := obj.EnumValues(args["includeDeprecated"].(bool)) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { diff --git a/example/dataloader/generated.go b/example/dataloader/generated.go index ac1e4e32551..b54d6524e7f 100644 --- a/example/dataloader/generated.go +++ b/example/dataloader/generated.go @@ -150,12 +150,22 @@ func (ec *executionContext) _Customer_address(ctx context.Context, field graphql ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Customer_address(rctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Customer", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Customer_address(rctx, obj) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Address) if res == nil { return graphql.Null } @@ -172,12 +182,22 @@ func (ec *executionContext) _Customer_orders(ctx context.Context, field graphql. ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Customer_orders(rctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Customer", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Customer_orders(rctx, obj) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]Order) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { return ec._Order(ctx, field.Selections, &res[idx1]) }()) @@ -265,12 +285,22 @@ func (ec *executionContext) _Order_items(ctx context.Context, field graphql.Coll ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Order_items(rctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Order", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Order_items(rctx, obj) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]Item) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { return ec._Item(ctx, field.Selections, &res[idx1]) }()) @@ -316,12 +346,22 @@ func (ec *executionContext) _Query_customers(ctx context.Context, field graphql. ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_customers(rctx) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_customers(rctx) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]Customer) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { return ec._Customer(ctx, field.Selections, &res[idx1]) }()) @@ -331,6 +371,7 @@ func (ec *executionContext) _Query_customers(ctx context.Context, field graphql. } func (ec *executionContext) _Query_torture(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 [][]int if tmp, ok := field.Args["customerIds"]; ok { var err error @@ -348,6 +389,7 @@ func (ec *executionContext) _Query_torture(ctx context.Context, field graphql.Co return graphql.Null } } + args["customerIds"] = arg0 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -356,12 +398,22 @@ func (ec *executionContext) _Query_torture(ctx context.Context, field graphql.Co ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_torture(rctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_torture(rctx, args["customerIds"].([][]int)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([][]Customer) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { @@ -385,6 +437,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 string if tmp, ok := field.Args["name"]; ok { var err error @@ -394,7 +447,8 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col return graphql.Null } } - res := ec.introspectType(arg0) + args["name"] = arg0 + res := ec.introspectType(args["name"].(string)) if res == nil { return graphql.Null } @@ -798,6 +852,7 @@ 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 { + args := map[string]interface{}{} var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -807,7 +862,8 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co return graphql.Null } } - res := obj.Fields(arg0) + args["includeDeprecated"] = arg0 + res := obj.Fields(args["includeDeprecated"].(bool)) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { @@ -849,6 +905,7 @@ 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 { + args := map[string]interface{}{} var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -858,7 +915,8 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq return graphql.Null } } - res := obj.EnumValues(arg0) + args["includeDeprecated"] = arg0 + res := obj.EnumValues(args["includeDeprecated"].(bool)) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { diff --git a/example/dataloader/server/server.go b/example/dataloader/server/server.go index 1f128c6ff27..c016c5aebb7 100644 --- a/example/dataloader/server/server.go +++ b/example/dataloader/server/server.go @@ -3,15 +3,68 @@ package main import ( "log" "net/http" + "net/url" + "time" + "github.com/go-chi/chi" + "github.com/opentracing-contrib/go-stdlib/nethttp" + "github.com/opentracing/opentracing-go" "github.com/vektah/gqlgen/example/dataloader" "github.com/vektah/gqlgen/handler" + gqlopentracing "github.com/vektah/gqlgen/opentracing" + "sourcegraph.com/sourcegraph/appdash" + appdashtracer "sourcegraph.com/sourcegraph/appdash/opentracing" + "sourcegraph.com/sourcegraph/appdash/traceapp" ) func main() { - http.Handle("/", handler.Playground("Dataloader", "/query")) + tracer := startAppdashServer() - http.Handle("/query", dataloader.LoaderMiddleware(handler.GraphQL(dataloader.MakeExecutableSchema(&dataloader.Resolver{})))) + router := chi.NewRouter() + router.Use(Opentracing(tracer)) + router.Use(dataloader.LoaderMiddleware) - log.Fatal(http.ListenAndServe(":8082", nil)) + router.Handle("/", handler.Playground("Dataloader", "/query")) + router.Handle("/query", handler.GraphQL(dataloader.MakeExecutableSchema(&dataloader.Resolver{}), handler.Use(gqlopentracing.Middleware()))) + + log.Println("connect to http://localhost:8082/ for graphql playground") + log.Fatal(http.ListenAndServe(":8082", router)) +} + +func Opentracing(tracer opentracing.Tracer) func(next http.Handler) http.Handler { + return func(next http.Handler) http.Handler { + return nethttp.Middleware(tracer, next) + } +} + +func startAppdashServer() opentracing.Tracer { + memStore := appdash.NewMemoryStore() + store := &appdash.RecentStore{ + MinEvictAge: 5 * time.Minute, + DeleteStore: memStore, + } + + url, err := url.Parse("http://localhost:8700") + if err != nil { + log.Fatal(err) + } + tapp, err := traceapp.New(nil, url) + if err != nil { + log.Fatal(err) + } + tapp.Store = store + tapp.Queryer = memStore + + go func() { + log.Fatal(http.ListenAndServe(":8700", tapp)) + }() + tapp.Store = store + tapp.Queryer = memStore + + collector := appdash.NewLocalCollector(store) + tracer := appdashtracer.NewTracer(collector) + opentracing.InitGlobalTracer(tracer) + + log.Println("Appdash web UI running on HTTP :8700") + return tracer } diff --git a/example/scalars/generated.go b/example/scalars/generated.go index f521b7700fb..d49ad2b1b26 100644 --- a/example/scalars/generated.go +++ b/example/scalars/generated.go @@ -129,6 +129,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel []query.Selection) g } func (ec *executionContext) _Query_user(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 external.ObjectID if tmp, ok := field.Args["id"]; ok { var err error @@ -138,6 +139,7 @@ func (ec *executionContext) _Query_user(ctx context.Context, field graphql.Colle return graphql.Null } } + args["id"] = arg0 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -146,12 +148,22 @@ func (ec *executionContext) _Query_user(ctx context.Context, field graphql.Colle ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_user(rctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_user(rctx, args["id"].(external.ObjectID)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*User) if res == nil { return graphql.Null } @@ -160,6 +172,7 @@ func (ec *executionContext) _Query_user(ctx context.Context, field graphql.Colle } func (ec *executionContext) _Query_search(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 SearchArgs if tmp, ok := field.Args["input"]; ok { var err error @@ -178,6 +191,7 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col } } + args["input"] = arg0 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -186,12 +200,22 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_search(rctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_search(rctx, args["input"].(SearchArgs)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]User) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { return ec._User(ctx, field.Selections, &res[idx1]) }()) @@ -209,6 +233,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 string if tmp, ok := field.Args["name"]; ok { var err error @@ -218,7 +243,8 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col return graphql.Null } } - res := ec.introspectType(arg0) + args["name"] = arg0 + res := ec.introspectType(args["name"].(string)) if res == nil { return graphql.Null } @@ -290,12 +316,22 @@ func (ec *executionContext) _User_primitiveResolver(ctx context.Context, field g ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.User_primitiveResolver(rctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "User", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.User_primitiveResolver(rctx, obj) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) return graphql.MarshalString(res) }) } @@ -309,12 +345,22 @@ func (ec *executionContext) _User_customResolver(ctx context.Context, field grap ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.User_customResolver(rctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "User", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.User_customResolver(rctx, obj) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(Point) return res }) } @@ -726,6 +772,7 @@ 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 { + args := map[string]interface{}{} var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -735,7 +782,8 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co return graphql.Null } } - res := obj.Fields(arg0) + args["includeDeprecated"] = arg0 + res := obj.Fields(args["includeDeprecated"].(bool)) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { @@ -777,6 +825,7 @@ 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 { + args := map[string]interface{}{} var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -786,7 +835,8 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq return graphql.Null } } - res := obj.EnumValues(arg0) + args["includeDeprecated"] = arg0 + res := obj.EnumValues(args["includeDeprecated"].(bool)) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { diff --git a/example/selection/generated.go b/example/selection/generated.go index fe9967658f3..16951bd8e9e 100644 --- a/example/selection/generated.go +++ b/example/selection/generated.go @@ -205,12 +205,22 @@ func (ec *executionContext) _Query_events(ctx context.Context, field graphql.Col ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_events(rctx) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_events(rctx) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]Event) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { return ec._Event(ctx, field.Selections, &res[idx1]) }()) @@ -228,6 +238,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 string if tmp, ok := field.Args["name"]; ok { var err error @@ -237,7 +248,8 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col return graphql.Null } } - res := ec.introspectType(arg0) + args["name"] = arg0 + res := ec.introspectType(args["name"].(string)) if res == nil { return graphql.Null } @@ -641,6 +653,7 @@ 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 { + args := map[string]interface{}{} var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -650,7 +663,8 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co return graphql.Null } } - res := obj.Fields(arg0) + args["includeDeprecated"] = arg0 + res := obj.Fields(args["includeDeprecated"].(bool)) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { @@ -692,6 +706,7 @@ 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 { + args := map[string]interface{}{} var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -701,7 +716,8 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq return graphql.Null } } - res := obj.EnumValues(arg0) + args["includeDeprecated"] = arg0 + res := obj.EnumValues(args["includeDeprecated"].(bool)) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { diff --git a/example/starwars/generated.go b/example/starwars/generated.go index 7c9a84c0609..6b2d115e11e 100644 --- a/example/starwars/generated.go +++ b/example/starwars/generated.go @@ -137,12 +137,22 @@ func (ec *executionContext) _Droid_friends(ctx context.Context, field graphql.Co ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Droid_friends(rctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Droid", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Droid_friends(rctx, obj) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]Character) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { return ec._Character(ctx, field.Selections, &res[idx1]) }()) @@ -152,6 +162,7 @@ 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 { + args := map[string]interface{}{} var arg0 *int if tmp, ok := field.Args["first"]; ok { var err error @@ -166,6 +177,7 @@ func (ec *executionContext) _Droid_friendsConnection(ctx context.Context, field return graphql.Null } } + args["first"] = arg0 var arg1 *string if tmp, ok := field.Args["after"]; ok { var err error @@ -180,6 +192,7 @@ func (ec *executionContext) _Droid_friendsConnection(ctx context.Context, field return graphql.Null } } + args["after"] = arg1 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -188,12 +201,22 @@ func (ec *executionContext) _Droid_friendsConnection(ctx context.Context, field ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Droid_friendsConnection(rctx, obj, arg0, arg1) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Droid", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Droid_friendsConnection(rctx, obj, args["first"].(*int), args["after"].(*string)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(FriendsConnection) return ec._FriendsConnection(ctx, field.Selections, &res) }) } @@ -254,12 +277,22 @@ func (ec *executionContext) _FriendsConnection_edges(ctx context.Context, field ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.FriendsConnection_edges(rctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "FriendsConnection", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.FriendsConnection_edges(rctx, obj) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]FriendsEdge) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { return ec._FriendsEdge(ctx, field.Selections, &res[idx1]) }()) @@ -277,12 +310,22 @@ func (ec *executionContext) _FriendsConnection_friends(ctx context.Context, fiel ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.FriendsConnection_friends(rctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "FriendsConnection", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.FriendsConnection_friends(rctx, obj) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]Character) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { return ec._Character(ctx, field.Selections, &res[idx1]) }()) @@ -377,6 +420,7 @@ 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 { + args := map[string]interface{}{} var arg0 LengthUnit if tmp, ok := field.Args["unit"]; ok { var err error @@ -395,7 +439,8 @@ func (ec *executionContext) _Human_height(ctx context.Context, field graphql.Col } } - res := obj.Height(arg0) + args["unit"] = arg0 + res := obj.Height(args["unit"].(LengthUnit)) return graphql.MarshalFloat(res) } @@ -413,12 +458,22 @@ func (ec *executionContext) _Human_friends(ctx context.Context, field graphql.Co ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Human_friends(rctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Human", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Human_friends(rctx, obj) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]Character) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { return ec._Character(ctx, field.Selections, &res[idx1]) }()) @@ -428,6 +483,7 @@ 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 { + args := map[string]interface{}{} var arg0 *int if tmp, ok := field.Args["first"]; ok { var err error @@ -442,6 +498,7 @@ func (ec *executionContext) _Human_friendsConnection(ctx context.Context, field return graphql.Null } } + args["first"] = arg0 var arg1 *string if tmp, ok := field.Args["after"]; ok { var err error @@ -456,6 +513,7 @@ func (ec *executionContext) _Human_friendsConnection(ctx context.Context, field return graphql.Null } } + args["after"] = arg1 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -464,12 +522,22 @@ func (ec *executionContext) _Human_friendsConnection(ctx context.Context, field ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Human_friendsConnection(rctx, obj, arg0, arg1) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Human", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Human_friendsConnection(rctx, obj, args["first"].(*int), args["after"].(*string)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(FriendsConnection) return ec._FriendsConnection(ctx, field.Selections, &res) }) } @@ -492,12 +560,22 @@ func (ec *executionContext) _Human_starships(ctx context.Context, field graphql. ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Human_starships(rctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Human", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Human_starships(rctx, obj) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]Starship) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { return ec._Starship(ctx, field.Selections, &res[idx1]) }()) @@ -529,6 +607,7 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel []query.Selection } func (ec *executionContext) _Mutation_createReview(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 Episode if tmp, ok := field.Args["episode"]; ok { var err error @@ -538,6 +617,7 @@ func (ec *executionContext) _Mutation_createReview(ctx context.Context, field gr return graphql.Null } } + args["episode"] = arg0 var arg1 Review if tmp, ok := field.Args["review"]; ok { var err error @@ -547,12 +627,23 @@ func (ec *executionContext) _Mutation_createReview(ctx context.Context, field gr return graphql.Null } } - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Mutation_createReview(rctx, arg0, arg1) + args["review"] = arg1 + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Mutation", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Mutation_createReview(rctx, args["episode"].(Episode), args["review"].(Review)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Review) if res == nil { return graphql.Null } @@ -639,6 +730,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel []query.Selection) g } func (ec *executionContext) _Query_hero(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 Episode if tmp, ok := field.Args["episode"]; ok { var err error @@ -657,6 +749,7 @@ func (ec *executionContext) _Query_hero(ctx context.Context, field graphql.Colle } } + args["episode"] = arg0 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -665,17 +758,28 @@ func (ec *executionContext) _Query_hero(ctx context.Context, field graphql.Colle ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_hero(rctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_hero(rctx, args["episode"].(Episode)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(Character) return ec._Character(ctx, field.Selections, &res) }) } func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 Episode if tmp, ok := field.Args["episode"]; ok { var err error @@ -685,6 +789,7 @@ func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.Co return graphql.Null } } + args["episode"] = arg0 var arg1 *time.Time if tmp, ok := field.Args["since"]; ok { var err error @@ -699,6 +804,7 @@ func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.Co return graphql.Null } } + args["since"] = arg1 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -707,12 +813,22 @@ func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.Co ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_reviews(rctx, arg0, arg1) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_reviews(rctx, args["episode"].(Episode), args["since"].(*time.Time)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]Review) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { return ec._Review(ctx, field.Selections, &res[idx1]) }()) @@ -722,6 +838,7 @@ func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.Co } func (ec *executionContext) _Query_search(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 string if tmp, ok := field.Args["text"]; ok { var err error @@ -731,6 +848,7 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col return graphql.Null } } + args["text"] = arg0 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -739,12 +857,22 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_search(rctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_search(rctx, args["text"].(string)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]SearchResult) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { return ec._SearchResult(ctx, field.Selections, &res[idx1]) }()) @@ -754,6 +882,7 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col } func (ec *executionContext) _Query_character(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 string if tmp, ok := field.Args["id"]; ok { var err error @@ -763,6 +892,7 @@ func (ec *executionContext) _Query_character(ctx context.Context, field graphql. return graphql.Null } } + args["id"] = arg0 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -771,17 +901,28 @@ func (ec *executionContext) _Query_character(ctx context.Context, field graphql. ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_character(rctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_character(rctx, args["id"].(string)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(Character) return ec._Character(ctx, field.Selections, &res) }) } func (ec *executionContext) _Query_droid(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 string if tmp, ok := field.Args["id"]; ok { var err error @@ -791,6 +932,7 @@ func (ec *executionContext) _Query_droid(ctx context.Context, field graphql.Coll return graphql.Null } } + args["id"] = arg0 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -799,12 +941,22 @@ func (ec *executionContext) _Query_droid(ctx context.Context, field graphql.Coll ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_droid(rctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_droid(rctx, args["id"].(string)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Droid) if res == nil { return graphql.Null } @@ -813,6 +965,7 @@ func (ec *executionContext) _Query_droid(ctx context.Context, field graphql.Coll } func (ec *executionContext) _Query_human(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 string if tmp, ok := field.Args["id"]; ok { var err error @@ -822,6 +975,7 @@ func (ec *executionContext) _Query_human(ctx context.Context, field graphql.Coll return graphql.Null } } + args["id"] = arg0 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -830,12 +984,22 @@ func (ec *executionContext) _Query_human(ctx context.Context, field graphql.Coll ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_human(rctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_human(rctx, args["id"].(string)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Human) if res == nil { return graphql.Null } @@ -844,6 +1008,7 @@ func (ec *executionContext) _Query_human(ctx context.Context, field graphql.Coll } func (ec *executionContext) _Query_starship(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 string if tmp, ok := field.Args["id"]; ok { var err error @@ -853,6 +1018,7 @@ func (ec *executionContext) _Query_starship(ctx context.Context, field graphql.C return graphql.Null } } + args["id"] = arg0 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -861,12 +1027,22 @@ func (ec *executionContext) _Query_starship(ctx context.Context, field graphql.C ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_starship(rctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_starship(rctx, args["id"].(string)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Starship) if res == nil { return graphql.Null } @@ -883,6 +1059,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 string if tmp, ok := field.Args["name"]; ok { var err error @@ -892,7 +1069,8 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col return graphql.Null } } - res := ec.introspectType(arg0) + args["name"] = arg0 + res := ec.introspectType(args["name"].(string)) if res == nil { return graphql.Null } @@ -982,6 +1160,7 @@ 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 { + args := map[string]interface{}{} var arg0 LengthUnit if tmp, ok := field.Args["unit"]; ok { var err error @@ -1000,7 +1179,8 @@ func (ec *executionContext) _Starship_length(ctx context.Context, field graphql. } } - res := obj.Length(arg0) + args["unit"] = arg0 + res := obj.Length(args["unit"].(LengthUnit)) return graphql.MarshalFloat(res) } @@ -1416,6 +1596,7 @@ 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 { + args := map[string]interface{}{} var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -1425,7 +1606,8 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co return graphql.Null } } - res := obj.Fields(arg0) + args["includeDeprecated"] = arg0 + res := obj.Fields(args["includeDeprecated"].(bool)) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { @@ -1467,6 +1649,7 @@ 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 { + args := map[string]interface{}{} var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -1476,7 +1659,8 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq return graphql.Null } } - res := obj.EnumValues(arg0) + args["includeDeprecated"] = arg0 + res := obj.EnumValues(args["includeDeprecated"].(bool)) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { diff --git a/example/starwars/server/server.go b/example/starwars/server/server.go index 01f591728aa..dc2c57d2ae4 100644 --- a/example/starwars/server/server.go +++ b/example/starwars/server/server.go @@ -1,16 +1,27 @@ package main import ( + "context" + "fmt" "log" "net/http" "github.com/vektah/gqlgen/example/starwars" + "github.com/vektah/gqlgen/graphql" "github.com/vektah/gqlgen/handler" ) func main() { http.Handle("/", handler.Playground("Starwars", "/query")) - http.Handle("/query", handler.GraphQL(starwars.MakeExecutableSchema(starwars.NewResolver()))) + http.Handle("/query", handler.GraphQL(starwars.MakeExecutableSchema(starwars.NewResolver()), + handler.Use(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { + rc := graphql.GetResolverContext(ctx) + fmt.Println("Entered", rc.Object, rc.Field.Name) + res, err = next(ctx) + fmt.Println("Left", rc.Object, rc.Field.Name, "=>", res, err) + return res, err + }), + )) log.Fatal(http.ListenAndServe(":8080", nil)) } diff --git a/example/todo/generated.go b/example/todo/generated.go index 42c84511cd8..8b815211d0f 100644 --- a/example/todo/generated.go +++ b/example/todo/generated.go @@ -95,6 +95,7 @@ func (ec *executionContext) _MyMutation(ctx context.Context, sel []query.Selecti } func (ec *executionContext) _MyMutation_createTodo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 TodoInput if tmp, ok := field.Args["todo"]; ok { var err error @@ -104,16 +105,28 @@ func (ec *executionContext) _MyMutation_createTodo(ctx context.Context, field gr return graphql.Null } } - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.MyMutation_createTodo(rctx, arg0) + args["todo"] = arg0 + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "MyMutation", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.MyMutation_createTodo(rctx, args["todo"].(TodoInput)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(Todo) return ec._Todo(ctx, field.Selections, &res) } func (ec *executionContext) _MyMutation_updateTodo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 int if tmp, ok := field.Args["id"]; ok { var err error @@ -123,6 +136,7 @@ func (ec *executionContext) _MyMutation_updateTodo(ctx context.Context, field gr return graphql.Null } } + args["id"] = arg0 var arg1 map[string]interface{} if tmp, ok := field.Args["changes"]; ok { var err error @@ -132,12 +146,23 @@ func (ec *executionContext) _MyMutation_updateTodo(ctx context.Context, field gr return graphql.Null } } - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.MyMutation_updateTodo(rctx, arg0, arg1) + args["changes"] = arg1 + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "MyMutation", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.MyMutation_updateTodo(rctx, args["id"].(int), args["changes"].(map[string]interface{})) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Todo) if res == nil { return graphql.Null } @@ -175,6 +200,7 @@ func (ec *executionContext) _MyQuery(ctx context.Context, sel []query.Selection) } func (ec *executionContext) _MyQuery_todo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 int if tmp, ok := field.Args["id"]; ok { var err error @@ -184,6 +210,7 @@ func (ec *executionContext) _MyQuery_todo(ctx context.Context, field graphql.Col return graphql.Null } } + args["id"] = arg0 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -192,12 +219,22 @@ func (ec *executionContext) _MyQuery_todo(ctx context.Context, field graphql.Col ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.MyQuery_todo(rctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "MyQuery", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.MyQuery_todo(rctx, args["id"].(int)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Todo) if res == nil { return graphql.Null } @@ -214,12 +251,22 @@ func (ec *executionContext) _MyQuery_lastTodo(ctx context.Context, field graphql ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.MyQuery_lastTodo(rctx) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "MyQuery", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.MyQuery_lastTodo(rctx) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Todo) if res == nil { return graphql.Null } @@ -236,12 +283,22 @@ func (ec *executionContext) _MyQuery_todos(ctx context.Context, field graphql.Co ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.MyQuery_todos(rctx) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "MyQuery", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.MyQuery_todos(rctx) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]Todo) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { return ec._Todo(ctx, field.Selections, &res[idx1]) }()) @@ -259,6 +316,7 @@ func (ec *executionContext) _MyQuery___schema(ctx context.Context, field graphql } func (ec *executionContext) _MyQuery___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 string if tmp, ok := field.Args["name"]; ok { var err error @@ -268,7 +326,8 @@ func (ec *executionContext) _MyQuery___type(ctx context.Context, field graphql.C return graphql.Null } } - res := ec.introspectType(arg0) + args["name"] = arg0 + res := ec.introspectType(args["name"].(string)) if res == nil { return graphql.Null } @@ -713,6 +772,7 @@ 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 { + args := map[string]interface{}{} var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -722,7 +782,8 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co return graphql.Null } } - res := obj.Fields(arg0) + args["includeDeprecated"] = arg0 + res := obj.Fields(args["includeDeprecated"].(bool)) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { @@ -764,6 +825,7 @@ 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 { + args := map[string]interface{}{} var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -773,7 +835,8 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq return graphql.Null } } - res := obj.EnumValues(arg0) + args["includeDeprecated"] = arg0 + res := obj.EnumValues(args["includeDeprecated"].(bool)) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { diff --git a/graphql/context.go b/graphql/context.go index a1abec5dc5d..4f2dcfcef7c 100644 --- a/graphql/context.go +++ b/graphql/context.go @@ -7,12 +7,16 @@ import ( "github.com/vektah/gqlgen/neelance/query" ) +type Resolver func(ctx context.Context) (res interface{}, err error) +type ResolverMiddleware func(ctx context.Context, next Resolver) (res interface{}, err error) + type RequestContext struct { errors.Builder - Variables map[string]interface{} - Doc *query.Document - Recover RecoverFunc + Variables map[string]interface{} + Doc *query.Document + Recover RecoverFunc + Middleware ResolverMiddleware } type key string @@ -36,6 +40,11 @@ func WithRequestContext(ctx context.Context, rc *RequestContext) context.Context } type ResolverContext struct { + // The name of the type this field belongs to + Object string + // These are the args after processing, they can be mutated in middleware to change what the resolver will get. + Args map[string]interface{} + // The raw field Field CollectedField } diff --git a/handler/graphql.go b/handler/graphql.go index af1f6117dab..e15c47f35ac 100644 --- a/handler/graphql.go +++ b/handler/graphql.go @@ -1,10 +1,10 @@ package handler import ( + "context" "encoding/json" "fmt" "net/http" - "strings" "github.com/gorilla/websocket" @@ -21,9 +21,10 @@ type params struct { } type Config struct { - upgrader websocket.Upgrader - recover graphql.RecoverFunc - formatError func(error) string + upgrader websocket.Upgrader + recover graphql.RecoverFunc + formatError func(error) string + resolverHook graphql.ResolverMiddleware } type Option func(cfg *Config) @@ -46,6 +47,22 @@ func FormatErrorFunc(f func(error) string) Option { } } +func Use(middleware graphql.ResolverMiddleware) Option { + return func(cfg *Config) { + if cfg.resolverHook == nil { + cfg.resolverHook = middleware + return + } + + lastResolve := cfg.resolverHook + cfg.resolverHook = func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { + return lastResolve(ctx, func(ctx context.Context) (res interface{}, err error) { + return middleware(ctx, next) + }) + } + } +} + func GraphQL(exec graphql.ExecutableSchema, options ...Option) http.HandlerFunc { cfg := Config{ recover: graphql.DefaultRecoverFunc, @@ -59,6 +76,12 @@ func GraphQL(exec graphql.ExecutableSchema, options ...Option) http.HandlerFunc option(&cfg) } + if cfg.resolverHook == nil { + cfg.resolverHook = func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { + return next(ctx) + } + } + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodOptions { w.Header().Set("Allow", "OPTIONS, GET, POST") @@ -67,7 +90,7 @@ func GraphQL(exec graphql.ExecutableSchema, options ...Option) http.HandlerFunc } if strings.Contains(r.Header.Get("Upgrade"), "websocket") { - connectWs(exec, w, r, cfg.upgrader, cfg.recover) + connectWs(exec, w, r, &cfg) return } @@ -113,9 +136,10 @@ func GraphQL(exec graphql.ExecutableSchema, options ...Option) http.HandlerFunc } ctx := graphql.WithRequestContext(r.Context(), &graphql.RequestContext{ - Doc: doc, - Variables: reqParams.Variables, - Recover: cfg.recover, + Doc: doc, + Variables: reqParams.Variables, + Recover: cfg.recover, + Middleware: cfg.resolverHook, Builder: errors.Builder{ ErrorMessageFn: cfg.formatError, }, diff --git a/handler/websocket.go b/handler/websocket.go index a5214aeb986..5275e0ba54c 100644 --- a/handler/websocket.go +++ b/handler/websocket.go @@ -26,7 +26,7 @@ const ( dataMsg = "data" // Server -> Client errorMsg = "error" // Server -> Client completeMsg = "complete" // Server -> Client - //connectionKeepAliveMsg = "ka" // Server -> Client TODO: keepalives + //connectionKeepAliveMsg = "ka" // Server -> Client TODO: keepalives ) type operationMessage struct { @@ -36,17 +36,16 @@ type operationMessage struct { } type wsConnection struct { - ctx context.Context - conn *websocket.Conn - exec graphql.ExecutableSchema - active map[string]context.CancelFunc - mu sync.Mutex - recover graphql.RecoverFunc - formatError func(err error) string + ctx context.Context + conn *websocket.Conn + exec graphql.ExecutableSchema + active map[string]context.CancelFunc + mu sync.Mutex + cfg *Config } -func connectWs(exec graphql.ExecutableSchema, w http.ResponseWriter, r *http.Request, upgrader websocket.Upgrader, recover graphql.RecoverFunc) { - ws, err := upgrader.Upgrade(w, r, http.Header{ +func connectWs(exec graphql.ExecutableSchema, w http.ResponseWriter, r *http.Request, cfg *Config) { + ws, err := cfg.upgrader.Upgrade(w, r, http.Header{ "Sec-Websocket-Protocol": []string{"graphql-ws"}, }) if err != nil { @@ -56,11 +55,11 @@ func connectWs(exec graphql.ExecutableSchema, w http.ResponseWriter, r *http.Req } conn := wsConnection{ - active: map[string]context.CancelFunc{}, - exec: exec, - conn: ws, - ctx: r.Context(), - recover: recover, + active: map[string]context.CancelFunc{}, + exec: exec, + conn: ws, + ctx: r.Context(), + cfg: cfg, } if !conn.init() { @@ -157,11 +156,12 @@ func (c *wsConnection) subscribe(message *operationMessage) bool { } ctx := graphql.WithRequestContext(c.ctx, &graphql.RequestContext{ - Doc: doc, - Variables: reqParams.Variables, - Recover: c.recover, + Doc: doc, + Variables: reqParams.Variables, + Recover: c.cfg.recover, + Middleware: c.cfg.resolverHook, Builder: errors.Builder{ - ErrorMessageFn: c.formatError, + ErrorMessageFn: c.cfg.formatError, }, }) @@ -185,7 +185,7 @@ func (c *wsConnection) subscribe(message *operationMessage) bool { go func() { defer func() { if r := recover(); r != nil { - userErr := c.recover(r) + userErr := c.cfg.recover(r) c.sendError(message.ID, &errors.QueryError{Message: userErr.Error()}) } }() diff --git a/opentracing/opentracing.go b/opentracing/opentracing.go new file mode 100644 index 00000000000..d7699547c18 --- /dev/null +++ b/opentracing/opentracing.go @@ -0,0 +1,39 @@ +package opentracing + +import ( + "context" + "fmt" + + "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go/ext" + "github.com/opentracing/opentracing-go/log" + "github.com/vektah/gqlgen/graphql" +) + +func Middleware() graphql.ResolverMiddleware { + return func(ctx context.Context, next graphql.Resolver) (interface{}, error) { + rctx := graphql.GetResolverContext(ctx) + + span, ctx := opentracing.StartSpanFromContext(ctx, rctx.Object+"_"+rctx.Field.Name, + opentracing.Tag{Key: "resolver.object", Value: rctx.Object}, + opentracing.Tag{Key: "resolver.field", Value: rctx.Field.Name}, + ) + defer span.Finish() + + ext.SpanKind.Set(span, "server") + ext.Component.Set(span, "gqlgen") + + res, err := next(ctx) + + if err != nil { + ext.Error.Set(span, true) + span.LogFields( + log.String("event", "error"), + log.String("message", err.Error()), + log.String("error.kind", fmt.Sprintf("%T", err)), + ) + } + + return res, err + } +} diff --git a/test/generated.go b/test/generated.go index c2427e537a4..73771099c41 100644 --- a/test/generated.go +++ b/test/generated.go @@ -214,12 +214,22 @@ func (ec *executionContext) _OuterObject_inner(ctx context.Context, field graphq ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.OuterObject_inner(rctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "OuterObject", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.OuterObject_inner(rctx, obj) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(models.InnerObject) return ec._InnerObject(ctx, field.Selections, &res) }) } @@ -263,6 +273,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel []query.Selection) g } func (ec *executionContext) _Query_nestedInputs(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 [][]models.OuterInput if tmp, ok := field.Args["input"]; ok { var err error @@ -297,6 +308,7 @@ func (ec *executionContext) _Query_nestedInputs(ctx context.Context, field graph } } + args["input"] = arg0 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -305,12 +317,22 @@ func (ec *executionContext) _Query_nestedInputs(ctx context.Context, field graph ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_nestedInputs(rctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_nestedInputs(rctx, args["input"].([][]models.OuterInput)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*bool) if res == nil { return graphql.Null } @@ -327,12 +349,22 @@ func (ec *executionContext) _Query_nestedOutputs(ctx context.Context, field grap ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_nestedOutputs(rctx) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_nestedOutputs(rctx) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([][]models.OuterObject) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { @@ -356,12 +388,22 @@ func (ec *executionContext) _Query_shapes(ctx context.Context, field graphql.Col ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_shapes(rctx) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_shapes(rctx) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]Shape) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { return ec._Shape(ctx, field.Selections, &res[idx1]) }()) @@ -371,6 +413,7 @@ func (ec *executionContext) _Query_shapes(ctx context.Context, field graphql.Col } func (ec *executionContext) _Query_recursive(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 *RecursiveInputSlice if tmp, ok := field.Args["input"]; ok { var err error @@ -385,6 +428,7 @@ func (ec *executionContext) _Query_recursive(ctx context.Context, field graphql. return graphql.Null } } + args["input"] = arg0 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -393,12 +437,22 @@ func (ec *executionContext) _Query_recursive(ctx context.Context, field graphql. ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_recursive(rctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_recursive(rctx, args["input"].(*RecursiveInputSlice)) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*bool) if res == nil { return graphql.Null } @@ -407,6 +461,7 @@ func (ec *executionContext) _Query_recursive(ctx context.Context, field graphql. } func (ec *executionContext) _Query_mapInput(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 *map[string]interface{} if tmp, ok := field.Args["input"]; ok { var err error @@ -421,6 +476,7 @@ func (ec *executionContext) _Query_mapInput(ctx context.Context, field graphql.C return graphql.Null } } + args["input"] = arg0 return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -429,12 +485,22 @@ func (ec *executionContext) _Query_mapInput(ctx context.Context, field graphql.C ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_mapInput(rctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: args, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_mapInput(rctx, args["input"].(*map[string]interface{})) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*bool) if res == nil { return graphql.Null } @@ -451,12 +517,22 @@ func (ec *executionContext) _Query_collision(ctx context.Context, field graphql. ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_collision(rctx) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_collision(rctx) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection1.It) if res == nil { return graphql.Null } @@ -473,12 +549,22 @@ func (ec *executionContext) _Query_invalidIdentifier(ctx context.Context, field ret = graphql.Null } }() - rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) - res, err := ec.resolvers.Query_invalidIdentifier(rctx) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + Args: nil, + Field: field, + }) + resTmp, err := ec.Middleware(rctx, func(rctx context.Context) (interface{}, error) { + return ec.resolvers.Query_invalidIdentifier(rctx) + }) if err != nil { ec.Error(err) return graphql.Null } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*invalid_identifier.InvalidIdentifier) if res == nil { return graphql.Null } @@ -495,6 +581,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} var arg0 string if tmp, ok := field.Args["name"]; ok { var err error @@ -504,7 +591,8 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col return graphql.Null } } - res := ec.introspectType(arg0) + args["name"] = arg0 + res := ec.introspectType(args["name"].(string)) if res == nil { return graphql.Null } @@ -949,6 +1037,7 @@ 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 { + args := map[string]interface{}{} var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -958,7 +1047,8 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co return graphql.Null } } - res := obj.Fields(arg0) + args["includeDeprecated"] = arg0 + res := obj.Fields(args["includeDeprecated"].(bool)) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { @@ -1000,6 +1090,7 @@ 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 { + args := map[string]interface{}{} var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -1009,7 +1100,8 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq return graphql.Null } } - res := obj.EnumValues(arg0) + args["includeDeprecated"] = arg0 + res := obj.EnumValues(args["includeDeprecated"].(bool)) arr1 := graphql.Array{} for idx1 := range res { arr1 = append(arr1, func() graphql.Marshaler { diff --git a/test/resolvers_test.go b/test/resolvers_test.go index 1a8bd226aed..06fffd3fd9e 100644 --- a/test/resolvers_test.go +++ b/test/resolvers_test.go @@ -71,6 +71,9 @@ func TestErrorConverter(t *testing.T) { func mkctx(doc *query.Document, errFn func(e error) string) context.Context { return graphql.WithRequestContext(context.Background(), &graphql.RequestContext{ Doc: doc, + Middleware: func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { + return next(ctx) + }, Builder: gqlerrors.Builder{ ErrorMessageFn: errFn, },