From 40918d52d4f222f7d89bd09bdee6c0d2963a6720 Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Tue, 27 Mar 2018 22:50:24 +1100 Subject: [PATCH 1/4] move request scoped data into context --- codegen/object.go | 4 +- codegen/templates/field.gotpl | 6 +- codegen/templates/generated.gotpl | 49 ++-- codegen/templates/interface.gotpl | 6 +- codegen/templates/object.gotpl | 12 +- graphql/context.go | 33 +++ graphql/exec.go | 6 +- handler/graphql.go | 24 +- handler/stub.go | 6 +- handler/websocket.go | 30 ++- test/generated.go | 365 ++++++++++++++---------------- test/resolvers_test.go | 59 ++--- 12 files changed, 307 insertions(+), 293 deletions(-) create mode 100644 graphql/context.go diff --git a/codegen/object.go b/codegen/object.go index 67ded3532b..30c2bfa28c 100644 --- a/codegen/object.go +++ b/codegen/object.go @@ -82,7 +82,7 @@ func (f *Field) CallArgs() string { var args []string if f.GoMethodName == "" { - args = append(args, "ec.ctx") + args = append(args, "ctx") if !f.Object.Root { args = append(args, "obj") @@ -134,7 +134,7 @@ func (f *Field) doWriteJson(val string, remainingMods []string, isPtr bool, dept if !isPtr { val = "&" + val } - return fmt.Sprintf("return ec._%s(field.Selections, %s)", f.GQLType, val) + return fmt.Sprintf("return ec._%s(ctx, field.Selections, %s)", f.GQLType, val) } } diff --git a/codegen/templates/field.gotpl b/codegen/templates/field.gotpl index f9a5e7bd3d..40acb311c3 100644 --- a/codegen/templates/field.gotpl +++ b/codegen/templates/field.gotpl @@ -2,7 +2,7 @@ {{ $object := $field.Object }} {{- if $object.Stream }} - func (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(field graphql.CollectedField) func() graphql.Marshaler { + func (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { {{- template "args.gotpl" $field.Args }} results, err := ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }}) if err != nil { @@ -20,14 +20,14 @@ } } {{ else }} - func (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(field graphql.CollectedField, {{if not $object.Root}}obj *{{$object.FullName}}{{end}}) graphql.Marshaler { + 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.IsConcurrent }} return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } diff --git a/codegen/templates/generated.gotpl b/codegen/templates/generated.gotpl index 4babc19e21..3e29d31562 100644 --- a/codegen/templates/generated.gotpl +++ b/codegen/templates/generated.gotpl @@ -8,12 +8,8 @@ import ( {{ end }} ) -func MakeExecutableSchema(resolvers Resolvers, opts ...ExecutableOption) graphql.ExecutableSchema { - ret := &executableSchema{resolvers: resolvers} - for _, opt := range opts { - opt(ret) - } - return ret +func MakeExecutableSchema(resolvers Resolvers) graphql.ExecutableSchema { + return &executableSchema{resolvers: resolvers} } type Resolvers interface { @@ -24,28 +20,19 @@ type Resolvers interface { {{- end }} } -type ExecutableOption func(*executableSchema) - -func WithErrorConverter(fn func(error) string) ExecutableOption { - return func(s *executableSchema) { - s.errorMessageFn = fn - } -} - type executableSchema struct { resolvers Resolvers - errorMessageFn func(error) string } func (e *executableSchema) Schema() *schema.Schema { return parsedSchema } -func (e *executableSchema) Query(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { +func (e *executableSchema) Query(ctx context.Context, op *query.Operation) *graphql.Response { {{- if .QueryRoot }} - ec := e.makeExecutionContext(ctx, doc, variables, recover) + ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers} - data := ec._{{.QueryRoot.GQLType}}(op.Selections) + data := ec._{{.QueryRoot.GQLType}}(ctx, op.Selections) var buf bytes.Buffer data.MarshalGQL(&buf) @@ -58,11 +45,11 @@ func (e *executableSchema) Query(ctx context.Context, doc *query.Document, varia {{- end }} } -func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { +func (e *executableSchema) Mutation(ctx context.Context, op *query.Operation) *graphql.Response { {{- if .MutationRoot }} - ec := e.makeExecutionContext(ctx, doc, variables, recover) + ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers} - data := ec._{{.MutationRoot.GQLType}}(op.Selections) + data := ec._{{.MutationRoot.GQLType}}(ctx, op.Selections) var buf bytes.Buffer data.MarshalGQL(&buf) @@ -75,11 +62,11 @@ func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, va {{- end }} } -func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) func() *graphql.Response { +func (e *executableSchema) Subscription(ctx context.Context, op *query.Operation) func() *graphql.Response { {{- if .SubscriptionRoot }} - ec := e.makeExecutionContext(ctx, doc, variables, recover) + ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers} - next := ec._{{.SubscriptionRoot.GQLType}}(op.Selections) + next := ec._{{.SubscriptionRoot.GQLType}}(ctx, op.Selections) if ec.Errors != nil { return graphql.OneShot(&graphql.Response{Data: []byte("null"), Errors: ec.Errors}) } @@ -105,20 +92,10 @@ func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document {{- end }} } -func (e *executableSchema) makeExecutionContext(ctx context.Context, doc *query.Document, variables map[string]interface{}, recover graphql.RecoverFunc) *executionContext { - errBuilder := errors.Builder{ErrorMessageFn: e.errorMessageFn} - return &executionContext{ - Builder: errBuilder, resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx, recover: recover, - } -} - type executionContext struct { - errors.Builder + *graphql.RequestContext + resolvers Resolvers - variables map[string]interface{} - doc *query.Document - ctx context.Context - recover graphql.RecoverFunc } {{- range $object := .Objects }} diff --git a/codegen/templates/interface.gotpl b/codegen/templates/interface.gotpl index 0392a98b69..817d0abe54 100644 --- a/codegen/templates/interface.gotpl +++ b/codegen/templates/interface.gotpl @@ -1,16 +1,16 @@ {{- $interface := . }} -func (ec *executionContext) _{{$interface.GQLType}}(sel []query.Selection, obj *{{$interface.FullName}}) graphql.Marshaler { +func (ec *executionContext) _{{$interface.GQLType}}(ctx context.Context, sel []query.Selection, obj *{{$interface.FullName}}) graphql.Marshaler { switch obj := (*obj).(type) { case nil: return graphql.Null {{- range $implementor := $interface.Implementors }} {{- if $implementor.ValueReceiver }} case {{$implementor.FullName}}: - return ec._{{$implementor.GQLType}}(sel, &obj) + return ec._{{$implementor.GQLType}}(ctx, sel, &obj) {{- end}} case *{{$implementor.FullName}}: - return ec._{{$implementor.GQLType}}(sel, obj) + return ec._{{$implementor.GQLType}}(ctx, sel, obj) {{- end }} default: panic(fmt.Errorf("unexpected type %T", obj)) diff --git a/codegen/templates/object.gotpl b/codegen/templates/object.gotpl index 28b56a1c68..f8c3daea5d 100644 --- a/codegen/templates/object.gotpl +++ b/codegen/templates/object.gotpl @@ -4,8 +4,8 @@ var {{ $object.GQLType|lcFirst}}Implementors = {{$object.Implementors}} // nolint: gocyclo, errcheck, gas, goconst {{- if .Stream }} -func (ec *executionContext) _{{$object.GQLType}}(sel []query.Selection) func() graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, {{$object.GQLType|lcFirst}}Implementors, ec.variables) +func (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel []query.Selection) func() graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, {{$object.GQLType|lcFirst}}Implementors, ec.Variables) if len(fields) != 1 { ec.Errorf("must subscribe to exactly one stream") @@ -15,15 +15,15 @@ func (ec *executionContext) _{{$object.GQLType}}(sel []query.Selection) func() g switch fields[0].Name { {{- range $field := $object.Fields }} case "{{$field.GQLName}}": - return ec._{{$object.GQLType}}_{{$field.GQLName}}(fields[0]) + return ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, fields[0]) {{- end }} default: panic("unknown field " + strconv.Quote(fields[0].Name)) } } {{- else }} -func (ec *executionContext) _{{$object.GQLType}}(sel []query.Selection{{if not $object.Root}}, obj *{{$object.FullName}} {{end}}) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, {{$object.GQLType|lcFirst}}Implementors, ec.variables) +func (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel []query.Selection{{if not $object.Root}}, obj *{{$object.FullName}} {{end}}) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, {{$object.GQLType|lcFirst}}Implementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -33,7 +33,7 @@ func (ec *executionContext) _{{$object.GQLType}}(sel []query.Selection{{if not $ out.Values[i] = graphql.MarshalString({{$object.GQLType|quote}}) {{- range $field := $object.Fields }} case "{{$field.GQLName}}": - out.Values[i] = ec._{{$object.GQLType}}_{{$field.GQLName}}(field{{if not $object.Root}}, obj{{end}}) + out.Values[i] = ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}}) {{- end }} default: panic("unknown field " + strconv.Quote(field.Name)) diff --git a/graphql/context.go b/graphql/context.go new file mode 100644 index 0000000000..efb91d5dab --- /dev/null +++ b/graphql/context.go @@ -0,0 +1,33 @@ +package graphql + +import ( + "context" + + "github.com/vektah/gqlgen/neelance/errors" + "github.com/vektah/gqlgen/neelance/query" +) + +type RequestContext struct { + errors.Builder + + Variables map[string]interface{} + Doc *query.Document + Recover RecoverFunc +} + +type key string + +const rcKey key = "request_context" + +func GetRequestContext(ctx context.Context) *RequestContext { + val := ctx.Value(rcKey) + if val == nil { + return nil + } + + return val.(*RequestContext) +} + +func WithRequestContext(ctx context.Context, rc *RequestContext) context.Context { + return context.WithValue(ctx, rcKey, rc) +} diff --git a/graphql/exec.go b/graphql/exec.go index dafc28b37a..37615ba7b3 100644 --- a/graphql/exec.go +++ b/graphql/exec.go @@ -12,9 +12,9 @@ import ( type ExecutableSchema interface { Schema() *schema.Schema - Query(ctx context.Context, document *query.Document, variables map[string]interface{}, op *query.Operation, recover RecoverFunc) *Response - Mutation(ctx context.Context, document *query.Document, variables map[string]interface{}, op *query.Operation, recover RecoverFunc) *Response - Subscription(ctx context.Context, document *query.Document, variables map[string]interface{}, op *query.Operation, recover RecoverFunc) func() *Response + Query(ctx context.Context, op *query.Operation) *Response + Mutation(ctx context.Context, op *query.Operation) *Response + Subscription(ctx context.Context, op *query.Operation) func() *Response } func CollectFields(doc *query.Document, selSet []query.Selection, satisfies []string, variables map[string]interface{}) []CollectedField { diff --git a/handler/graphql.go b/handler/graphql.go index 4b22a716ea..8dc768f2f6 100644 --- a/handler/graphql.go +++ b/handler/graphql.go @@ -21,8 +21,9 @@ type params struct { } type Config struct { - upgrader websocket.Upgrader - recover graphql.RecoverFunc + upgrader websocket.Upgrader + recover graphql.RecoverFunc + formatError func(error) string } type Option func(cfg *Config) @@ -39,6 +40,12 @@ func RecoverFunc(recover graphql.RecoverFunc) Option { } } +func FormatErrorFunc(f func(error) string) Option { + return func(cfg *Config) { + cfg.formatError = f + } +} + func GraphQL(exec graphql.ExecutableSchema, options ...Option) http.HandlerFunc { cfg := Config{ recover: graphql.DefaultRecoverFunc, @@ -96,15 +103,24 @@ func GraphQL(exec graphql.ExecutableSchema, options ...Option) http.HandlerFunc return } + ctx := graphql.WithRequestContext(r.Context(), &graphql.RequestContext{ + Doc: doc, + Variables: reqParams.Variables, + Recover: cfg.recover, + Builder: errors.Builder{ + ErrorMessageFn: cfg.formatError, + }, + }) + switch op.Type { case query.Query: - b, err := json.Marshal(exec.Query(r.Context(), doc, reqParams.Variables, op, cfg.recover)) + b, err := json.Marshal(exec.Query(ctx, op)) if err != nil { panic(err) } w.Write(b) case query.Mutation: - b, err := json.Marshal(exec.Mutation(r.Context(), doc, reqParams.Variables, op, cfg.recover)) + b, err := json.Marshal(exec.Mutation(ctx, op)) if err != nil { panic(err) } diff --git a/handler/stub.go b/handler/stub.go index 93fe855fba..2c7fcf1873 100644 --- a/handler/stub.go +++ b/handler/stub.go @@ -23,17 +23,17 @@ func (e *executableSchemaStub) Schema() *schema.Schema { `) } -func (e *executableSchemaStub) Query(ctx context.Context, document *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { +func (e *executableSchemaStub) Query(ctx context.Context, op *query.Operation) *graphql.Response { return &graphql.Response{Data: []byte(`{"name":"test"}`)} } -func (e *executableSchemaStub) Mutation(ctx context.Context, document *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { +func (e *executableSchemaStub) Mutation(ctx context.Context, op *query.Operation) *graphql.Response { return &graphql.Response{ Errors: []*errors.QueryError{{Message: "mutations are not supported"}}, } } -func (e *executableSchemaStub) Subscription(ctx context.Context, document *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) func() *graphql.Response { +func (e *executableSchemaStub) Subscription(ctx context.Context, op *query.Operation) func() *graphql.Response { return func() *graphql.Response { time.Sleep(20 * time.Millisecond) select { diff --git a/handler/websocket.go b/handler/websocket.go index ef71a24077..a5214aeb98 100644 --- a/handler/websocket.go +++ b/handler/websocket.go @@ -36,12 +36,13 @@ 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 + 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 } func connectWs(exec graphql.ExecutableSchema, w http.ResponseWriter, r *http.Request, upgrader websocket.Upgrader, recover graphql.RecoverFunc) { @@ -155,12 +156,21 @@ func (c *wsConnection) subscribe(message *operationMessage) bool { return true } + ctx := graphql.WithRequestContext(c.ctx, &graphql.RequestContext{ + Doc: doc, + Variables: reqParams.Variables, + Recover: c.recover, + Builder: errors.Builder{ + ErrorMessageFn: c.formatError, + }, + }) + if op.Type != query.Subscription { var result *graphql.Response if op.Type == query.Query { - result = c.exec.Query(c.ctx, doc, reqParams.Variables, op, c.recover) + result = c.exec.Query(ctx, op) } else { - result = c.exec.Mutation(c.ctx, doc, reqParams.Variables, op, c.recover) + result = c.exec.Mutation(ctx, op) } c.sendData(message.ID, result) @@ -168,7 +178,7 @@ func (c *wsConnection) subscribe(message *operationMessage) bool { return true } - ctx, cancel := context.WithCancel(c.ctx) + ctx, cancel := context.WithCancel(ctx) c.mu.Lock() c.active[message.ID] = cancel c.mu.Unlock() @@ -179,7 +189,7 @@ func (c *wsConnection) subscribe(message *operationMessage) bool { c.sendError(message.ID, &errors.QueryError{Message: userErr.Error()}) } }() - next := c.exec.Subscription(ctx, doc, reqParams.Variables, op, c.recover) + next := c.exec.Subscription(ctx, op) for result := next(); result != nil; result = next() { fmt.Println(result) c.sendData(message.ID, result) diff --git a/test/generated.go b/test/generated.go index c31abb01af..8a271be066 100644 --- a/test/generated.go +++ b/test/generated.go @@ -16,12 +16,8 @@ import ( introspection1 "github.com/vektah/gqlgen/test/introspection" ) -func MakeExecutableSchema(resolvers Resolvers, opts ...ExecutableOption) graphql.ExecutableSchema { - ret := &executableSchema{resolvers: resolvers} - for _, opt := range opts { - opt(ret) - } - return ret +func MakeExecutableSchema(resolvers Resolvers) graphql.ExecutableSchema { + return &executableSchema{resolvers: resolvers} } type Resolvers interface { @@ -34,27 +30,18 @@ type Resolvers interface { Query_collision(ctx context.Context) (*introspection1.It, error) } -type ExecutableOption func(*executableSchema) - -func WithErrorConverter(fn func(error) string) ExecutableOption { - return func(s *executableSchema) { - s.errorMessageFn = fn - } -} - type executableSchema struct { - resolvers Resolvers - errorMessageFn func(error) string + resolvers Resolvers } func (e *executableSchema) Schema() *schema.Schema { return parsedSchema } -func (e *executableSchema) Query(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { - ec := e.makeExecutionContext(ctx, doc, variables, recover) +func (e *executableSchema) Query(ctx context.Context, op *query.Operation) *graphql.Response { + ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers} - data := ec._Query(op.Selections) + data := ec._Query(ctx, op.Selections) var buf bytes.Buffer data.MarshalGQL(&buf) @@ -64,35 +51,25 @@ func (e *executableSchema) Query(ctx context.Context, doc *query.Document, varia } } -func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { +func (e *executableSchema) Mutation(ctx context.Context, op *query.Operation) *graphql.Response { return &graphql.Response{Errors: []*errors.QueryError{{Message: "mutations are not supported"}}} } -func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) func() *graphql.Response { +func (e *executableSchema) Subscription(ctx context.Context, op *query.Operation) func() *graphql.Response { return graphql.OneShot(&graphql.Response{Errors: []*errors.QueryError{{Message: "subscriptions are not supported"}}}) } -func (e *executableSchema) makeExecutionContext(ctx context.Context, doc *query.Document, variables map[string]interface{}, recover graphql.RecoverFunc) *executionContext { - errBuilder := errors.Builder{ErrorMessageFn: e.errorMessageFn} - return &executionContext{ - Builder: errBuilder, resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx, recover: recover, - } -} - type executionContext struct { - errors.Builder + *graphql.RequestContext + resolvers Resolvers - variables map[string]interface{} - doc *query.Document - ctx context.Context - recover graphql.RecoverFunc } var circleImplementors = []string{"Circle", "Shape"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Circle(sel []query.Selection, obj *Circle) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, circleImplementors, ec.variables) +func (ec *executionContext) _Circle(ctx context.Context, sel []query.Selection, obj *Circle) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, circleImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -101,9 +78,9 @@ func (ec *executionContext) _Circle(sel []query.Selection, obj *Circle) graphql. case "__typename": out.Values[i] = graphql.MarshalString("Circle") case "radius": - out.Values[i] = ec._Circle_radius(field, obj) + out.Values[i] = ec._Circle_radius(ctx, field, obj) case "area": - out.Values[i] = ec._Circle_area(field, obj) + out.Values[i] = ec._Circle_area(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -112,12 +89,12 @@ func (ec *executionContext) _Circle(sel []query.Selection, obj *Circle) graphql. return out } -func (ec *executionContext) _Circle_radius(field graphql.CollectedField, obj *Circle) graphql.Marshaler { +func (ec *executionContext) _Circle_radius(ctx context.Context, field graphql.CollectedField, obj *Circle) graphql.Marshaler { res := obj.Radius return graphql.MarshalFloat(res) } -func (ec *executionContext) _Circle_area(field graphql.CollectedField, obj *Circle) graphql.Marshaler { +func (ec *executionContext) _Circle_area(ctx context.Context, field graphql.CollectedField, obj *Circle) graphql.Marshaler { res := obj.Area() return graphql.MarshalFloat(res) } @@ -125,8 +102,8 @@ func (ec *executionContext) _Circle_area(field graphql.CollectedField, obj *Circ var innerObjectImplementors = []string{"InnerObject"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _InnerObject(sel []query.Selection, obj *InnerObject) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, innerObjectImplementors, ec.variables) +func (ec *executionContext) _InnerObject(ctx context.Context, sel []query.Selection, obj *InnerObject) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, innerObjectImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -135,7 +112,7 @@ func (ec *executionContext) _InnerObject(sel []query.Selection, obj *InnerObject case "__typename": out.Values[i] = graphql.MarshalString("InnerObject") case "id": - out.Values[i] = ec._InnerObject_id(field, obj) + out.Values[i] = ec._InnerObject_id(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -144,7 +121,7 @@ func (ec *executionContext) _InnerObject(sel []query.Selection, obj *InnerObject return out } -func (ec *executionContext) _InnerObject_id(field graphql.CollectedField, obj *InnerObject) graphql.Marshaler { +func (ec *executionContext) _InnerObject_id(ctx context.Context, field graphql.CollectedField, obj *InnerObject) graphql.Marshaler { res := obj.ID return graphql.MarshalInt(res) } @@ -152,8 +129,8 @@ func (ec *executionContext) _InnerObject_id(field graphql.CollectedField, obj *I var itImplementors = []string{"It"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _It(sel []query.Selection, obj *introspection1.It) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, itImplementors, ec.variables) +func (ec *executionContext) _It(ctx context.Context, sel []query.Selection, obj *introspection1.It) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, itImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -162,7 +139,7 @@ func (ec *executionContext) _It(sel []query.Selection, obj *introspection1.It) g case "__typename": out.Values[i] = graphql.MarshalString("It") case "id": - out.Values[i] = ec._It_id(field, obj) + out.Values[i] = ec._It_id(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -171,7 +148,7 @@ func (ec *executionContext) _It(sel []query.Selection, obj *introspection1.It) g return out } -func (ec *executionContext) _It_id(field graphql.CollectedField, obj *introspection1.It) graphql.Marshaler { +func (ec *executionContext) _It_id(ctx context.Context, field graphql.CollectedField, obj *introspection1.It) graphql.Marshaler { res := obj.ID return graphql.MarshalID(res) } @@ -179,8 +156,8 @@ func (ec *executionContext) _It_id(field graphql.CollectedField, obj *introspect var outerObjectImplementors = []string{"OuterObject"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _OuterObject(sel []query.Selection, obj *OuterObject) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, outerObjectImplementors, ec.variables) +func (ec *executionContext) _OuterObject(ctx context.Context, sel []query.Selection, obj *OuterObject) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, outerObjectImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -189,7 +166,7 @@ func (ec *executionContext) _OuterObject(sel []query.Selection, obj *OuterObject case "__typename": out.Values[i] = graphql.MarshalString("OuterObject") case "inner": - out.Values[i] = ec._OuterObject_inner(field, obj) + out.Values[i] = ec._OuterObject_inner(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -198,29 +175,29 @@ func (ec *executionContext) _OuterObject(sel []query.Selection, obj *OuterObject return out } -func (ec *executionContext) _OuterObject_inner(field graphql.CollectedField, obj *OuterObject) graphql.Marshaler { +func (ec *executionContext) _OuterObject_inner(ctx context.Context, field graphql.CollectedField, obj *OuterObject) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.OuterObject_inner(ec.ctx, obj) + res, err := ec.resolvers.OuterObject_inner(ctx, obj) if err != nil { ec.Error(err) return graphql.Null } - return ec._InnerObject(field.Selections, &res) + return ec._InnerObject(ctx, field.Selections, &res) }) } var queryImplementors = []string{"Query"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, queryImplementors, ec.variables) +func (ec *executionContext) _Query(ctx context.Context, sel []query.Selection) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, queryImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -229,21 +206,21 @@ func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { case "__typename": out.Values[i] = graphql.MarshalString("Query") case "nestedInputs": - out.Values[i] = ec._Query_nestedInputs(field) + out.Values[i] = ec._Query_nestedInputs(ctx, field) case "nestedOutputs": - out.Values[i] = ec._Query_nestedOutputs(field) + out.Values[i] = ec._Query_nestedOutputs(ctx, field) case "shapes": - out.Values[i] = ec._Query_shapes(field) + out.Values[i] = ec._Query_shapes(ctx, field) case "recursive": - out.Values[i] = ec._Query_recursive(field) + out.Values[i] = ec._Query_recursive(ctx, field) case "mapInput": - out.Values[i] = ec._Query_mapInput(field) + out.Values[i] = ec._Query_mapInput(ctx, field) case "collision": - out.Values[i] = ec._Query_collision(field) + out.Values[i] = ec._Query_collision(ctx, field) case "__schema": - out.Values[i] = ec._Query___schema(field) + out.Values[i] = ec._Query___schema(ctx, field) case "__type": - out.Values[i] = ec._Query___type(field) + out.Values[i] = ec._Query___type(ctx, field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -252,7 +229,7 @@ func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { return out } -func (ec *executionContext) _Query_nestedInputs(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_nestedInputs(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 [][]OuterInput if tmp, ok := field.Args["input"]; ok { var err error @@ -290,12 +267,12 @@ func (ec *executionContext) _Query_nestedInputs(field graphql.CollectedField) gr return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_nestedInputs(ec.ctx, arg0) + res, err := ec.resolvers.Query_nestedInputs(ctx, arg0) if err != nil { ec.Error(err) return graphql.Null @@ -307,16 +284,16 @@ func (ec *executionContext) _Query_nestedInputs(field graphql.CollectedField) gr }) } -func (ec *executionContext) _Query_nestedOutputs(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_nestedOutputs(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_nestedOutputs(ec.ctx) + res, err := ec.resolvers.Query_nestedOutputs(ctx) if err != nil { ec.Error(err) return graphql.Null @@ -326,7 +303,7 @@ func (ec *executionContext) _Query_nestedOutputs(field graphql.CollectedField) g arr1 = append(arr1, func() graphql.Marshaler { arr2 := graphql.Array{} for idx2 := range res[idx1] { - arr2 = append(arr2, func() graphql.Marshaler { return ec._OuterObject(field.Selections, &res[idx1][idx2]) }()) + arr2 = append(arr2, func() graphql.Marshaler { return ec._OuterObject(ctx, field.Selections, &res[idx1][idx2]) }()) } return arr2 }()) @@ -335,29 +312,29 @@ func (ec *executionContext) _Query_nestedOutputs(field graphql.CollectedField) g }) } -func (ec *executionContext) _Query_shapes(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_shapes(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_shapes(ec.ctx) + res, err := ec.resolvers.Query_shapes(ctx) if err != nil { ec.Error(err) return graphql.Null } arr1 := graphql.Array{} for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { return ec._Shape(field.Selections, &res[idx1]) }()) + arr1 = append(arr1, func() graphql.Marshaler { return ec._Shape(ctx, field.Selections, &res[idx1]) }()) } return arr1 }) } -func (ec *executionContext) _Query_recursive(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_recursive(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 *RecursiveInputSlice if tmp, ok := field.Args["input"]; ok { var err error @@ -375,12 +352,12 @@ func (ec *executionContext) _Query_recursive(field graphql.CollectedField) graph return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_recursive(ec.ctx, arg0) + res, err := ec.resolvers.Query_recursive(ctx, arg0) if err != nil { ec.Error(err) return graphql.Null @@ -392,7 +369,7 @@ func (ec *executionContext) _Query_recursive(field graphql.CollectedField) graph }) } -func (ec *executionContext) _Query_mapInput(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_mapInput(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 *map[string]interface{} if tmp, ok := field.Args["input"]; ok { var err error @@ -410,12 +387,12 @@ func (ec *executionContext) _Query_mapInput(field graphql.CollectedField) graphq return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_mapInput(ec.ctx, arg0) + res, err := ec.resolvers.Query_mapInput(ctx, arg0) if err != nil { ec.Error(err) return graphql.Null @@ -427,16 +404,16 @@ func (ec *executionContext) _Query_mapInput(field graphql.CollectedField) graphq }) } -func (ec *executionContext) _Query_collision(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_collision(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_collision(ec.ctx) + res, err := ec.resolvers.Query_collision(ctx) if err != nil { ec.Error(err) return graphql.Null @@ -444,19 +421,19 @@ func (ec *executionContext) _Query_collision(field graphql.CollectedField) graph if res == nil { return graphql.Null } - return ec._It(field.Selections, res) + return ec._It(ctx, field.Selections, res) }) } -func (ec *executionContext) _Query___schema(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { res := ec.introspectSchema() if res == nil { return graphql.Null } - return ec.___Schema(field.Selections, res) + return ec.___Schema(ctx, field.Selections, res) } -func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["name"]; ok { var err error @@ -470,14 +447,14 @@ func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql. if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } var rectangleImplementors = []string{"Rectangle", "Shape"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Rectangle(sel []query.Selection, obj *Rectangle) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, rectangleImplementors, ec.variables) +func (ec *executionContext) _Rectangle(ctx context.Context, sel []query.Selection, obj *Rectangle) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, rectangleImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -486,11 +463,11 @@ func (ec *executionContext) _Rectangle(sel []query.Selection, obj *Rectangle) gr case "__typename": out.Values[i] = graphql.MarshalString("Rectangle") case "length": - out.Values[i] = ec._Rectangle_length(field, obj) + out.Values[i] = ec._Rectangle_length(ctx, field, obj) case "width": - out.Values[i] = ec._Rectangle_width(field, obj) + out.Values[i] = ec._Rectangle_width(ctx, field, obj) case "area": - out.Values[i] = ec._Rectangle_area(field, obj) + out.Values[i] = ec._Rectangle_area(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -499,17 +476,17 @@ func (ec *executionContext) _Rectangle(sel []query.Selection, obj *Rectangle) gr return out } -func (ec *executionContext) _Rectangle_length(field graphql.CollectedField, obj *Rectangle) graphql.Marshaler { +func (ec *executionContext) _Rectangle_length(ctx context.Context, field graphql.CollectedField, obj *Rectangle) graphql.Marshaler { res := obj.Length return graphql.MarshalFloat(res) } -func (ec *executionContext) _Rectangle_width(field graphql.CollectedField, obj *Rectangle) graphql.Marshaler { +func (ec *executionContext) _Rectangle_width(ctx context.Context, field graphql.CollectedField, obj *Rectangle) graphql.Marshaler { res := obj.Width return graphql.MarshalFloat(res) } -func (ec *executionContext) _Rectangle_area(field graphql.CollectedField, obj *Rectangle) graphql.Marshaler { +func (ec *executionContext) _Rectangle_area(ctx context.Context, field graphql.CollectedField, obj *Rectangle) graphql.Marshaler { res := obj.Area() return graphql.MarshalFloat(res) } @@ -517,8 +494,8 @@ func (ec *executionContext) _Rectangle_area(field graphql.CollectedField, obj *R var __DirectiveImplementors = []string{"__Directive"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __DirectiveImplementors, ec.variables) +func (ec *executionContext) ___Directive(ctx context.Context, sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __DirectiveImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -527,13 +504,13 @@ func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspecti case "__typename": out.Values[i] = graphql.MarshalString("__Directive") case "name": - out.Values[i] = ec.___Directive_name(field, obj) + out.Values[i] = ec.___Directive_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Directive_description(field, obj) + out.Values[i] = ec.___Directive_description(ctx, field, obj) case "locations": - out.Values[i] = ec.___Directive_locations(field, obj) + out.Values[i] = ec.___Directive_locations(ctx, field, obj) case "args": - out.Values[i] = ec.___Directive_args(field, obj) + out.Values[i] = ec.___Directive_args(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -542,12 +519,12 @@ func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspecti return out } -func (ec *executionContext) ___Directive_name(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___Directive_description(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -555,7 +532,7 @@ func (ec *executionContext) ___Directive_description(field graphql.CollectedFiel return graphql.MarshalString(*res) } -func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Locations() arr1 := graphql.Array{} for idx1 := range res { @@ -564,7 +541,7 @@ func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, return arr1 } -func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Args() arr1 := graphql.Array{} for idx1 := range res { @@ -572,7 +549,7 @@ func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 @@ -581,8 +558,8 @@ func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj var __EnumValueImplementors = []string{"__EnumValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __EnumValueImplementors, ec.variables) +func (ec *executionContext) ___EnumValue(ctx context.Context, sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __EnumValueImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -591,13 +568,13 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspecti case "__typename": out.Values[i] = graphql.MarshalString("__EnumValue") case "name": - out.Values[i] = ec.___EnumValue_name(field, obj) + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) case "description": - out.Values[i] = ec.___EnumValue_description(field, obj) + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(field, obj) + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(field, obj) + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -606,12 +583,12 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspecti return out } -func (ec *executionContext) ___EnumValue_name(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___EnumValue_description(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -619,12 +596,12 @@ func (ec *executionContext) ___EnumValue_description(field graphql.CollectedFiel return graphql.MarshalString(*res) } -func (ec *executionContext) ___EnumValue_isDeprecated(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.IsDeprecated() return graphql.MarshalBoolean(res) } -func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.DeprecationReason() if res == nil { return graphql.Null @@ -635,8 +612,8 @@ func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.Collect var __FieldImplementors = []string{"__Field"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __FieldImplementors, ec.variables) +func (ec *executionContext) ___Field(ctx context.Context, sel []query.Selection, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __FieldImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -645,17 +622,17 @@ func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.F case "__typename": out.Values[i] = graphql.MarshalString("__Field") case "name": - out.Values[i] = ec.___Field_name(field, obj) + out.Values[i] = ec.___Field_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Field_description(field, obj) + out.Values[i] = ec.___Field_description(ctx, field, obj) case "args": - out.Values[i] = ec.___Field_args(field, obj) + out.Values[i] = ec.___Field_args(ctx, field, obj) case "type": - out.Values[i] = ec.___Field_type(field, obj) + out.Values[i] = ec.___Field_type(ctx, field, obj) case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(field, obj) + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(field, obj) + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -664,12 +641,12 @@ func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.F return out } -func (ec *executionContext) ___Field_name(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___Field_description(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -677,7 +654,7 @@ func (ec *executionContext) ___Field_description(field graphql.CollectedField, o return graphql.MarshalString(*res) } -func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Args() arr1 := graphql.Array{} for idx1 := range res { @@ -685,26 +662,26 @@ func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *int if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Field_type(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Type() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Field_isDeprecated(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.IsDeprecated() return graphql.MarshalBoolean(res) } -func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.DeprecationReason() if res == nil { return graphql.Null @@ -715,8 +692,8 @@ func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedFi var __InputValueImplementors = []string{"__InputValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __InputValueImplementors, ec.variables) +func (ec *executionContext) ___InputValue(ctx context.Context, sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __InputValueImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -725,13 +702,13 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspect case "__typename": out.Values[i] = graphql.MarshalString("__InputValue") case "name": - out.Values[i] = ec.___InputValue_name(field, obj) + out.Values[i] = ec.___InputValue_name(ctx, field, obj) case "description": - out.Values[i] = ec.___InputValue_description(field, obj) + out.Values[i] = ec.___InputValue_description(ctx, field, obj) case "type": - out.Values[i] = ec.___InputValue_type(field, obj) + out.Values[i] = ec.___InputValue_type(ctx, field, obj) case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(field, obj) + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -740,12 +717,12 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspect return out } -func (ec *executionContext) ___InputValue_name(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___InputValue_description(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -753,15 +730,15 @@ func (ec *executionContext) ___InputValue_description(field graphql.CollectedFie return graphql.MarshalString(*res) } -func (ec *executionContext) ___InputValue_type(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Type() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.DefaultValue() if res == nil { return graphql.Null @@ -772,8 +749,8 @@ func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedFi var __SchemaImplementors = []string{"__Schema"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __SchemaImplementors, ec.variables) +func (ec *executionContext) ___Schema(ctx context.Context, sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __SchemaImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -782,15 +759,15 @@ func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection. case "__typename": out.Values[i] = graphql.MarshalString("__Schema") case "types": - out.Values[i] = ec.___Schema_types(field, obj) + out.Values[i] = ec.___Schema_types(ctx, field, obj) case "queryType": - out.Values[i] = ec.___Schema_queryType(field, obj) + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) case "mutationType": - out.Values[i] = ec.___Schema_mutationType(field, obj) + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(field, obj) + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) case "directives": - out.Values[i] = ec.___Schema_directives(field, obj) + out.Values[i] = ec.___Schema_directives(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -799,7 +776,7 @@ func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection. return out } -func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.Types() arr1 := graphql.Array{} for idx1 := range res { @@ -807,37 +784,37 @@ func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *i if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Schema_queryType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.QueryType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_mutationType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.MutationType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_subscriptionType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.SubscriptionType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.Directives() arr1 := graphql.Array{} for idx1 := range res { @@ -845,7 +822,7 @@ func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, o if res[idx1] == nil { return graphql.Null } - return ec.___Directive(field.Selections, res[idx1]) + return ec.___Directive(ctx, field.Selections, res[idx1]) }()) } return arr1 @@ -854,8 +831,8 @@ func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, o var __TypeImplementors = []string{"__Type"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __TypeImplementors, ec.variables) +func (ec *executionContext) ___Type(ctx context.Context, sel []query.Selection, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __TypeImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -864,23 +841,23 @@ func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Ty case "__typename": out.Values[i] = graphql.MarshalString("__Type") case "kind": - out.Values[i] = ec.___Type_kind(field, obj) + out.Values[i] = ec.___Type_kind(ctx, field, obj) case "name": - out.Values[i] = ec.___Type_name(field, obj) + out.Values[i] = ec.___Type_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Type_description(field, obj) + out.Values[i] = ec.___Type_description(ctx, field, obj) case "fields": - out.Values[i] = ec.___Type_fields(field, obj) + out.Values[i] = ec.___Type_fields(ctx, field, obj) case "interfaces": - out.Values[i] = ec.___Type_interfaces(field, obj) + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(field, obj) + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) case "enumValues": - out.Values[i] = ec.___Type_enumValues(field, obj) + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) case "inputFields": - out.Values[i] = ec.___Type_inputFields(field, obj) + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) case "ofType": - out.Values[i] = ec.___Type_ofType(field, obj) + out.Values[i] = ec.___Type_ofType(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -889,12 +866,12 @@ func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Ty return out } -func (ec *executionContext) ___Type_kind(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Kind() return graphql.MarshalString(res) } -func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Name() if res == nil { return graphql.Null @@ -902,7 +879,7 @@ func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *intr return graphql.MarshalString(*res) } -func (ec *executionContext) ___Type_description(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -910,7 +887,7 @@ func (ec *executionContext) ___Type_description(field graphql.CollectedField, ob return graphql.MarshalString(*res) } -func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -927,13 +904,13 @@ func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *in if res[idx1] == nil { return graphql.Null } - return ec.___Field(field.Selections, res[idx1]) + return ec.___Field(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Interfaces() arr1 := graphql.Array{} for idx1 := range res { @@ -941,13 +918,13 @@ func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.PossibleTypes() arr1 := graphql.Array{} for idx1 := range res { @@ -955,13 +932,13 @@ func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -978,13 +955,13 @@ func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___EnumValue(field.Selections, res[idx1]) + return ec.___EnumValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.InputFields() arr1 := graphql.Array{} for idx1 := range res { @@ -992,41 +969,41 @@ func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, ob if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_ofType(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.OfType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) _Shape(sel []query.Selection, obj *Shape) graphql.Marshaler { +func (ec *executionContext) _Shape(ctx context.Context, sel []query.Selection, obj *Shape) graphql.Marshaler { switch obj := (*obj).(type) { case nil: return graphql.Null case *Circle: - return ec._Circle(sel, obj) + return ec._Circle(ctx, sel, obj) case *Rectangle: - return ec._Rectangle(sel, obj) + return ec._Rectangle(ctx, sel, obj) default: panic(fmt.Errorf("unexpected type %T", obj)) } } -func (ec *executionContext) _ShapeUnion(sel []query.Selection, obj *ShapeUnion) graphql.Marshaler { +func (ec *executionContext) _ShapeUnion(ctx context.Context, sel []query.Selection, obj *ShapeUnion) graphql.Marshaler { switch obj := (*obj).(type) { case nil: return graphql.Null case *Circle: - return ec._Circle(sel, obj) + return ec._Circle(ctx, sel, obj) case *Rectangle: - return ec._Rectangle(sel, obj) + return ec._Rectangle(ctx, sel, obj) default: panic(fmt.Errorf("unexpected type %T", obj)) } diff --git a/test/resolvers_test.go b/test/resolvers_test.go index 55510566ef..2f8ccec83b 100644 --- a/test/resolvers_test.go +++ b/test/resolvers_test.go @@ -4,12 +4,14 @@ package test import ( "context" - "fmt" + fmt "fmt" "testing" "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/vektah/gqlgen/graphql" + gqlerrors "github.com/vektah/gqlgen/neelance/errors" "github.com/vektah/gqlgen/neelance/query" "github.com/vektah/gqlgen/test/introspection" ) @@ -17,6 +19,12 @@ import ( func TestCompiles(t *testing.T) {} func TestErrorConverter(t *testing.T) { + resolvers := &testResolvers{} + s := MakeExecutableSchema(resolvers) + + doc, errs := query.Parse(`query { nestedOutputs { inner { id } } } `) + require.Nil(t, errs) + t.Run("with", func(t *testing.T) { testConvErr := func(e error) string { if _, ok := errors.Cause(e).(*specialErr); ok { @@ -25,24 +33,16 @@ func TestErrorConverter(t *testing.T) { return e.Error() } t.Run("special error", func(t *testing.T) { - s := MakeExecutableSchema(&testResolvers{ - nestedOutputsErr: &specialErr{}, - }, WithErrorConverter(testConvErr)) - ctx := context.Background() - doc, errs := query.Parse(`query { nestedOutputs { inner { id } } } `) - require.Nil(t, errs) - resp := s.Query(ctx, doc, nil, doc.Operations[0], nil) + resolvers.nestedOutputsErr = &specialErr{} + + resp := s.Query(mkctx(doc, testConvErr), doc.Operations[0]) require.Len(t, resp.Errors, 1) assert.Equal(t, "override special error message", resp.Errors[0].Message) }) t.Run("normal error", func(t *testing.T) { - s := MakeExecutableSchema(&testResolvers{ - nestedOutputsErr: fmt.Errorf("a normal error"), - }, WithErrorConverter(testConvErr)) - ctx := context.Background() - doc, errs := query.Parse(`query { nestedOutputs { inner { id } } } `) - require.Nil(t, errs) - resp := s.Query(ctx, doc, nil, doc.Operations[0], nil) + resolvers.nestedOutputsErr = fmt.Errorf("a normal error") + + resp := s.Query(mkctx(doc, testConvErr), doc.Operations[0]) require.Len(t, resp.Errors, 1) assert.Equal(t, "a normal error", resp.Errors[0].Message) }) @@ -50,30 +50,31 @@ func TestErrorConverter(t *testing.T) { t.Run("without", func(t *testing.T) { t.Run("special error", func(t *testing.T) { - s := MakeExecutableSchema(&testResolvers{ - nestedOutputsErr: &specialErr{}, - }) - ctx := context.Background() - doc, errs := query.Parse(`query { nestedOutputs { inner { id } } } `) - require.Nil(t, errs) - resp := s.Query(ctx, doc, nil, doc.Operations[0], nil) + resolvers.nestedOutputsErr = &specialErr{} + + resp := s.Query(mkctx(doc, nil), doc.Operations[0]) require.Len(t, resp.Errors, 1) assert.Equal(t, "original special error message", resp.Errors[0].Message) }) t.Run("normal error", func(t *testing.T) { - s := MakeExecutableSchema(&testResolvers{ - nestedOutputsErr: fmt.Errorf("a normal error"), - }) - ctx := context.Background() - doc, errs := query.Parse(`query { nestedOutputs { inner { id } } } `) - require.Nil(t, errs) - resp := s.Query(ctx, doc, nil, doc.Operations[0], nil) + resolvers.nestedOutputsErr = fmt.Errorf("a normal error") + + resp := s.Query(mkctx(doc, nil), doc.Operations[0]) require.Len(t, resp.Errors, 1) assert.Equal(t, "a normal error", resp.Errors[0].Message) }) }) } +func mkctx(doc *query.Document, errFn func(e error) string) context.Context { + return graphql.WithRequestContext(context.Background(), &graphql.RequestContext{ + Doc: doc, + Builder: gqlerrors.Builder{ + ErrorMessageFn: errFn, + }, + }) +} + type testResolvers struct { inner InnerObject innerErr error From e7007746dea1694c97a6741fee7ec1351b5ef350 Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Tue, 27 Mar 2018 23:06:39 +1100 Subject: [PATCH 2/4] add fields to resolver context --- codegen/object.go | 2 +- codegen/templates/field.gotpl | 2 ++ graphql/context.go | 26 +++++++++++++++++++++++--- test/generated.go | 21 ++++++++++++++------- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/codegen/object.go b/codegen/object.go index 30c2bfa28c..4751e5b780 100644 --- a/codegen/object.go +++ b/codegen/object.go @@ -82,7 +82,7 @@ func (f *Field) CallArgs() string { var args []string if f.GoMethodName == "" { - args = append(args, "ctx") + args = append(args, "rctx") if !f.Object.Root { args = append(args, "obj") diff --git a/codegen/templates/field.gotpl b/codegen/templates/field.gotpl index 40acb311c3..2f6bb87438 100644 --- a/codegen/templates/field.gotpl +++ b/codegen/templates/field.gotpl @@ -4,6 +4,7 @@ {{- if $object.Stream }} func (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { {{- template "args.gotpl" $field.Args }} + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) results, err := ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }}) if err != nil { ec.Error(err) @@ -47,6 +48,7 @@ } {{- end }} {{- else }} + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) res, err := ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }}) if err != nil { ec.Error(err) diff --git a/graphql/context.go b/graphql/context.go index efb91d5dab..f271298f2a 100644 --- a/graphql/context.go +++ b/graphql/context.go @@ -17,10 +17,13 @@ type RequestContext struct { type key string -const rcKey key = "request_context" +const ( + request key = "request_context" + resolver key = "resolver_context" +) func GetRequestContext(ctx context.Context) *RequestContext { - val := ctx.Value(rcKey) + val := ctx.Value(request) if val == nil { return nil } @@ -29,5 +32,22 @@ func GetRequestContext(ctx context.Context) *RequestContext { } func WithRequestContext(ctx context.Context, rc *RequestContext) context.Context { - return context.WithValue(ctx, rcKey, rc) + return context.WithValue(ctx, request, rc) +} + +type ResolverContext struct { + Field CollectedField +} + +func GetResolverContext(ctx context.Context) *ResolverContext { + val := ctx.Value(resolver) + if val == nil { + return nil + } + + return val.(*ResolverContext) +} + +func WithResolverContext(ctx context.Context, rc *ResolverContext) context.Context { + return context.WithValue(ctx, request, rc) } diff --git a/test/generated.go b/test/generated.go index 8a271be066..49edf4e2ba 100644 --- a/test/generated.go +++ b/test/generated.go @@ -184,7 +184,8 @@ func (ec *executionContext) _OuterObject_inner(ctx context.Context, field graphq ret = graphql.Null } }() - res, err := ec.resolvers.OuterObject_inner(ctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.OuterObject_inner(rctx, obj) if err != nil { ec.Error(err) return graphql.Null @@ -272,7 +273,8 @@ func (ec *executionContext) _Query_nestedInputs(ctx context.Context, field graph ret = graphql.Null } }() - res, err := ec.resolvers.Query_nestedInputs(ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_nestedInputs(rctx, arg0) if err != nil { ec.Error(err) return graphql.Null @@ -293,7 +295,8 @@ func (ec *executionContext) _Query_nestedOutputs(ctx context.Context, field grap ret = graphql.Null } }() - res, err := ec.resolvers.Query_nestedOutputs(ctx) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_nestedOutputs(rctx) if err != nil { ec.Error(err) return graphql.Null @@ -321,7 +324,8 @@ func (ec *executionContext) _Query_shapes(ctx context.Context, field graphql.Col ret = graphql.Null } }() - res, err := ec.resolvers.Query_shapes(ctx) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_shapes(rctx) if err != nil { ec.Error(err) return graphql.Null @@ -357,7 +361,8 @@ func (ec *executionContext) _Query_recursive(ctx context.Context, field graphql. ret = graphql.Null } }() - res, err := ec.resolvers.Query_recursive(ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_recursive(rctx, arg0) if err != nil { ec.Error(err) return graphql.Null @@ -392,7 +397,8 @@ func (ec *executionContext) _Query_mapInput(ctx context.Context, field graphql.C ret = graphql.Null } }() - res, err := ec.resolvers.Query_mapInput(ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_mapInput(rctx, arg0) if err != nil { ec.Error(err) return graphql.Null @@ -413,7 +419,8 @@ func (ec *executionContext) _Query_collision(ctx context.Context, field graphql. ret = graphql.Null } }() - res, err := ec.resolvers.Query_collision(ctx) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_collision(rctx) if err != nil { ec.Error(err) return graphql.Null From c5ccfe4e720b2ece5599ebe3fdf7a0473012acc2 Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Tue, 27 Mar 2018 23:52:41 +1100 Subject: [PATCH 3/4] Add an example for getting the selection sets from ctx --- codegen/templates/data.go | 8 +- example/selection/generated.go | 768 ++++++++++++++++++++++++++++ example/selection/models_gen.go | 21 + example/selection/readme.md | 10 + example/selection/schema.graphql | 24 + example/selection/selection.go | 62 +++ example/selection/selection_test.go | 58 +++ example/selection/server/server.go | 15 + graphql/context.go | 9 +- 9 files changed, 970 insertions(+), 5 deletions(-) create mode 100644 example/selection/generated.go create mode 100644 example/selection/models_gen.go create mode 100644 example/selection/readme.md create mode 100644 example/selection/schema.graphql create mode 100644 example/selection/selection.go create mode 100644 example/selection/selection_test.go create mode 100644 example/selection/server/server.go diff --git a/codegen/templates/data.go b/codegen/templates/data.go index 554a13d77a..339ee0c5c1 100644 --- a/codegen/templates/data.go +++ b/codegen/templates/data.go @@ -2,10 +2,10 @@ 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}}(field graphql.CollectedField) func() graphql.Marshaler {\n\t\t{{- template \"args.gotpl\" $field.Args }}\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}}(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\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", - "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, opts ...ExecutableOption) graphql.ExecutableSchema {\n\tret := &executableSchema{resolvers: resolvers}\n\tfor _, opt := range opts {\n\t\topt(ret)\n\t}\n\treturn ret\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 ExecutableOption func(*executableSchema)\n\nfunc WithErrorConverter(fn func(error) string) ExecutableOption {\n\treturn func(s *executableSchema) {\n\t\ts.errorMessageFn = fn\n\t}\n}\n\ntype executableSchema struct {\n\tresolvers Resolvers\n\terrorMessageFn func(error) string\n}\n\nfunc (e *executableSchema) Schema() *schema.Schema {\n\treturn parsedSchema\n}\n\nfunc (e *executableSchema) Query(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response {\n\t{{- if .QueryRoot }}\n\t\tec := e.makeExecutionContext(ctx, doc, variables, recover)\n\n\t\tdata := ec._{{.QueryRoot.GQLType}}(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, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response {\n\t{{- if .MutationRoot }}\n\t\tec := e.makeExecutionContext(ctx, doc, variables, recover)\n\n\t\tdata := ec._{{.MutationRoot.GQLType}}(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, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) func() *graphql.Response {\n\t{{- if .SubscriptionRoot }}\n\t\tec := e.makeExecutionContext(ctx, doc, variables, recover)\n\n\t\tnext := ec._{{.SubscriptionRoot.GQLType}}(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\nfunc (e *executableSchema) makeExecutionContext(ctx context.Context, doc *query.Document, variables map[string]interface{}, recover graphql.RecoverFunc) *executionContext {\n\terrBuilder := errors.Builder{ErrorMessageFn: e.errorMessageFn}\n\treturn &executionContext{\n\t\tBuilder: errBuilder, resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx, recover: recover,\n\t}\n}\n\ntype executionContext struct {\n\terrors.Builder\n\tresolvers Resolvers\n\tvariables map[string]interface{}\n\tdoc *query.Document\n\tctx context.Context\n\trecover graphql.RecoverFunc\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\nvar parsedSchema = schema.MustParse({{.SchemaRaw|quote}})\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", + "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", + "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\nvar parsedSchema = schema.MustParse({{.SchemaRaw|quote}})\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", "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}}(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}}(sel, &obj)\n\t\t{{- end}}\n\t\tcase *{{$implementor.FullName}}:\n\t\t\treturn ec._{{$implementor.GQLType}}(sel, obj)\n\t{{- end }}\n\tdefault:\n\t\tpanic(fmt.Errorf(\"unexpected type %T\", obj))\n\t}\n}\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", "models.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\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.GoVarName }}\n\t\t\t\t\t{{ $field.GoVarName }} {{$field.Signature}}\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", - "object.gotpl": "{{ $object := . }}\n\nvar {{ $object.GQLType|lcFirst}}Implementors = {{$object.Implementors}}\n\n// nolint: gocyclo, errcheck, gas, goconst\n{{- if .Stream }}\nfunc (ec *executionContext) _{{$object.GQLType}}(sel []query.Selection) func() graphql.Marshaler {\n\tfields := graphql.CollectFields(ec.doc, sel, {{$object.GQLType|lcFirst}}Implementors, ec.variables)\n\n\tif len(fields) != 1 {\n\t\tec.Errorf(\"must subscribe to exactly one stream\")\n\t\treturn nil\n\t}\n\n\tswitch fields[0].Name {\n\t{{- range $field := $object.Fields }}\n\tcase \"{{$field.GQLName}}\":\n\t\treturn ec._{{$object.GQLType}}_{{$field.GQLName}}(fields[0])\n\t{{- end }}\n\tdefault:\n\t\tpanic(\"unknown field \" + strconv.Quote(fields[0].Name))\n\t}\n}\n{{- else }}\nfunc (ec *executionContext) _{{$object.GQLType}}(sel []query.Selection{{if not $object.Root}}, obj *{{$object.FullName}} {{end}}) graphql.Marshaler {\n\tfields := graphql.CollectFields(ec.doc, sel, {{$object.GQLType|lcFirst}}Implementors, ec.variables)\n\tout := graphql.NewOrderedMap(len(fields))\n\tfor i, field := range fields {\n\t\tout.Keys[i] = field.Alias\n\n\t\tswitch field.Name {\n\t\tcase \"__typename\":\n\t\t\tout.Values[i] = graphql.MarshalString({{$object.GQLType|quote}})\n\t\t{{- range $field := $object.Fields }}\n\t\tcase \"{{$field.GQLName}}\":\n\t\t\tout.Values[i] = ec._{{$object.GQLType}}_{{$field.GQLName}}(field{{if not $object.Root}}, obj{{end}})\n\t\t{{- end }}\n\t\tdefault:\n\t\t\tpanic(\"unknown field \" + strconv.Quote(field.Name))\n\t\t}\n\t}\n\n\treturn out\n}\n{{- end }}\n", + "object.gotpl": "{{ $object := . }}\n\nvar {{ $object.GQLType|lcFirst}}Implementors = {{$object.Implementors}}\n\n// nolint: gocyclo, errcheck, gas, goconst\n{{- if .Stream }}\nfunc (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel []query.Selection) func() graphql.Marshaler {\n\tfields := graphql.CollectFields(ec.Doc, sel, {{$object.GQLType|lcFirst}}Implementors, ec.Variables)\n\n\tif len(fields) != 1 {\n\t\tec.Errorf(\"must subscribe to exactly one stream\")\n\t\treturn nil\n\t}\n\n\tswitch fields[0].Name {\n\t{{- range $field := $object.Fields }}\n\tcase \"{{$field.GQLName}}\":\n\t\treturn ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, fields[0])\n\t{{- end }}\n\tdefault:\n\t\tpanic(\"unknown field \" + strconv.Quote(fields[0].Name))\n\t}\n}\n{{- else }}\nfunc (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel []query.Selection{{if not $object.Root}}, obj *{{$object.FullName}} {{end}}) graphql.Marshaler {\n\tfields := graphql.CollectFields(ec.Doc, sel, {{$object.GQLType|lcFirst}}Implementors, ec.Variables)\n\tout := graphql.NewOrderedMap(len(fields))\n\tfor i, field := range fields {\n\t\tout.Keys[i] = field.Alias\n\n\t\tswitch field.Name {\n\t\tcase \"__typename\":\n\t\t\tout.Values[i] = graphql.MarshalString({{$object.GQLType|quote}})\n\t\t{{- range $field := $object.Fields }}\n\t\tcase \"{{$field.GQLName}}\":\n\t\t\tout.Values[i] = ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}})\n\t\t{{- end }}\n\t\tdefault:\n\t\t\tpanic(\"unknown field \" + strconv.Quote(field.Name))\n\t\t}\n\t}\n\n\treturn out\n}\n{{- end }}\n", } diff --git a/example/selection/generated.go b/example/selection/generated.go new file mode 100644 index 0000000000..0d22f06f1d --- /dev/null +++ b/example/selection/generated.go @@ -0,0 +1,768 @@ +// This file was generated by github.com/vektah/gqlgen, DO NOT EDIT + +package selection + +import ( + "bytes" + context "context" + fmt "fmt" + strconv "strconv" + + graphql "github.com/vektah/gqlgen/graphql" + errors "github.com/vektah/gqlgen/neelance/errors" + introspection "github.com/vektah/gqlgen/neelance/introspection" + query "github.com/vektah/gqlgen/neelance/query" + schema "github.com/vektah/gqlgen/neelance/schema" +) + +func MakeExecutableSchema(resolvers Resolvers) graphql.ExecutableSchema { + return &executableSchema{resolvers: resolvers} +} + +type Resolvers interface { + Query_events(ctx context.Context) ([]Event, error) +} + +type executableSchema struct { + resolvers Resolvers +} + +func (e *executableSchema) Schema() *schema.Schema { + return parsedSchema +} + +func (e *executableSchema) Query(ctx context.Context, op *query.Operation) *graphql.Response { + ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers} + + data := ec._Query(ctx, op.Selections) + var buf bytes.Buffer + data.MarshalGQL(&buf) + + return &graphql.Response{ + Data: buf.Bytes(), + Errors: ec.Errors, + } +} + +func (e *executableSchema) Mutation(ctx context.Context, op *query.Operation) *graphql.Response { + return &graphql.Response{Errors: []*errors.QueryError{{Message: "mutations are not supported"}}} +} + +func (e *executableSchema) Subscription(ctx context.Context, op *query.Operation) func() *graphql.Response { + return graphql.OneShot(&graphql.Response{Errors: []*errors.QueryError{{Message: "subscriptions are not supported"}}}) +} + +type executionContext struct { + *graphql.RequestContext + + resolvers Resolvers +} + +var likeImplementors = []string{"Like", "Event"} + +// nolint: gocyclo, errcheck, gas, goconst +func (ec *executionContext) _Like(ctx context.Context, sel []query.Selection, obj *Like) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, likeImplementors, ec.Variables) + out := graphql.NewOrderedMap(len(fields)) + for i, field := range fields { + out.Keys[i] = field.Alias + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Like") + case "reaction": + out.Values[i] = ec._Like_reaction(ctx, field, obj) + case "sent": + out.Values[i] = ec._Like_sent(ctx, field, obj) + case "selection": + out.Values[i] = ec._Like_selection(ctx, field, obj) + case "collected": + out.Values[i] = ec._Like_collected(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + + return out +} + +func (ec *executionContext) _Like_reaction(ctx context.Context, field graphql.CollectedField, obj *Like) graphql.Marshaler { + res := obj.Reaction + return graphql.MarshalString(res) +} + +func (ec *executionContext) _Like_sent(ctx context.Context, field graphql.CollectedField, obj *Like) graphql.Marshaler { + res := obj.Sent + return graphql.MarshalTime(res) +} + +func (ec *executionContext) _Like_selection(ctx context.Context, field graphql.CollectedField, obj *Like) graphql.Marshaler { + res := obj.Selection + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return graphql.MarshalString(res[idx1]) }()) + } + return arr1 +} + +func (ec *executionContext) _Like_collected(ctx context.Context, field graphql.CollectedField, obj *Like) graphql.Marshaler { + res := obj.Collected + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return graphql.MarshalString(res[idx1]) }()) + } + return arr1 +} + +var postImplementors = []string{"Post", "Event"} + +// nolint: gocyclo, errcheck, gas, goconst +func (ec *executionContext) _Post(ctx context.Context, sel []query.Selection, obj *Post) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, postImplementors, ec.Variables) + out := graphql.NewOrderedMap(len(fields)) + for i, field := range fields { + out.Keys[i] = field.Alias + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Post") + case "message": + out.Values[i] = ec._Post_message(ctx, field, obj) + case "sent": + out.Values[i] = ec._Post_sent(ctx, field, obj) + case "selection": + out.Values[i] = ec._Post_selection(ctx, field, obj) + case "collected": + out.Values[i] = ec._Post_collected(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + + return out +} + +func (ec *executionContext) _Post_message(ctx context.Context, field graphql.CollectedField, obj *Post) graphql.Marshaler { + res := obj.Message + return graphql.MarshalString(res) +} + +func (ec *executionContext) _Post_sent(ctx context.Context, field graphql.CollectedField, obj *Post) graphql.Marshaler { + res := obj.Sent + return graphql.MarshalTime(res) +} + +func (ec *executionContext) _Post_selection(ctx context.Context, field graphql.CollectedField, obj *Post) graphql.Marshaler { + res := obj.Selection + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return graphql.MarshalString(res[idx1]) }()) + } + return arr1 +} + +func (ec *executionContext) _Post_collected(ctx context.Context, field graphql.CollectedField, obj *Post) graphql.Marshaler { + res := obj.Collected + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return graphql.MarshalString(res[idx1]) }()) + } + return arr1 +} + +var queryImplementors = []string{"Query"} + +// nolint: gocyclo, errcheck, gas, goconst +func (ec *executionContext) _Query(ctx context.Context, sel []query.Selection) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, queryImplementors, ec.Variables) + out := graphql.NewOrderedMap(len(fields)) + for i, field := range fields { + out.Keys[i] = field.Alias + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Query") + case "events": + out.Values[i] = ec._Query_events(ctx, field) + case "__schema": + out.Values[i] = ec._Query___schema(ctx, field) + case "__type": + out.Values[i] = ec._Query___type(ctx, field) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + + return out +} + +func (ec *executionContext) _Query_events(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + return graphql.Defer(func() (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + userErr := ec.Recover(r) + ec.Error(userErr) + ret = graphql.Null + } + }() + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_events(rctx) + if err != nil { + ec.Error(err) + return graphql.Null + } + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return ec._Event(ctx, field.Selections, &res[idx1]) }()) + } + return arr1 + }) +} + +func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + res := ec.introspectSchema() + if res == nil { + return graphql.Null + } + return ec.___Schema(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["name"]; ok { + var err error + arg0, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := ec.introspectType(arg0) + if res == nil { + return graphql.Null + } + return ec.___Type(ctx, field.Selections, res) +} + +var __DirectiveImplementors = []string{"__Directive"} + +// nolint: gocyclo, errcheck, gas, goconst +func (ec *executionContext) ___Directive(ctx context.Context, sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __DirectiveImplementors, ec.Variables) + out := graphql.NewOrderedMap(len(fields)) + for i, field := range fields { + out.Keys[i] = field.Alias + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Directive") + case "name": + out.Values[i] = ec.___Directive_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___Directive_description(ctx, field, obj) + case "locations": + out.Values[i] = ec.___Directive_locations(ctx, field, obj) + case "args": + out.Values[i] = ec.___Directive_args(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + + return out +} + +func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Locations() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return graphql.MarshalString(res[idx1]) }()) + } + return arr1 +} + +func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Args() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(ctx, field.Selections, res[idx1]) + }()) + } + return arr1 +} + +var __EnumValueImplementors = []string{"__EnumValue"} + +// nolint: gocyclo, errcheck, gas, goconst +func (ec *executionContext) ___EnumValue(ctx context.Context, sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __EnumValueImplementors, ec.Variables) + out := graphql.NewOrderedMap(len(fields)) + for i, field := range fields { + out.Keys[i] = field.Alias + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__EnumValue") + case "name": + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) + case "isDeprecated": + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + case "deprecationReason": + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + + return out +} + +func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.IsDeprecated() + return graphql.MarshalBoolean(res) +} + +func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.DeprecationReason() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +var __FieldImplementors = []string{"__Field"} + +// nolint: gocyclo, errcheck, gas, goconst +func (ec *executionContext) ___Field(ctx context.Context, sel []query.Selection, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __FieldImplementors, ec.Variables) + out := graphql.NewOrderedMap(len(fields)) + for i, field := range fields { + out.Keys[i] = field.Alias + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Field") + case "name": + out.Values[i] = ec.___Field_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___Field_description(ctx, field, obj) + case "args": + out.Values[i] = ec.___Field_args(ctx, field, obj) + case "type": + out.Values[i] = ec.___Field_type(ctx, field, obj) + case "isDeprecated": + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + case "deprecationReason": + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + + return out +} + +func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Args() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(ctx, field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Type() + if res == nil { + return graphql.Null + } + return ec.___Type(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.IsDeprecated() + return graphql.MarshalBoolean(res) +} + +func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.DeprecationReason() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +var __InputValueImplementors = []string{"__InputValue"} + +// nolint: gocyclo, errcheck, gas, goconst +func (ec *executionContext) ___InputValue(ctx context.Context, sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __InputValueImplementors, ec.Variables) + out := graphql.NewOrderedMap(len(fields)) + for i, field := range fields { + out.Keys[i] = field.Alias + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__InputValue") + case "name": + out.Values[i] = ec.___InputValue_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___InputValue_description(ctx, field, obj) + case "type": + out.Values[i] = ec.___InputValue_type(ctx, field, obj) + case "defaultValue": + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + + return out +} + +func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Type() + if res == nil { + return graphql.Null + } + return ec.___Type(ctx, field.Selections, res) +} + +func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.DefaultValue() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +var __SchemaImplementors = []string{"__Schema"} + +// nolint: gocyclo, errcheck, gas, goconst +func (ec *executionContext) ___Schema(ctx context.Context, sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __SchemaImplementors, ec.Variables) + out := graphql.NewOrderedMap(len(fields)) + for i, field := range fields { + out.Keys[i] = field.Alias + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Schema") + case "types": + out.Values[i] = ec.___Schema_types(ctx, field, obj) + case "queryType": + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + case "mutationType": + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + case "subscriptionType": + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + case "directives": + out.Values[i] = ec.___Schema_directives(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + + return out +} + +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.Types() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(ctx, field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.QueryType() + if res == nil { + return graphql.Null + } + return ec.___Type(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.MutationType() + if res == nil { + return graphql.Null + } + return ec.___Type(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.SubscriptionType() + if res == nil { + return graphql.Null + } + return ec.___Type(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.Directives() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Directive(ctx, field.Selections, res[idx1]) + }()) + } + return arr1 +} + +var __TypeImplementors = []string{"__Type"} + +// nolint: gocyclo, errcheck, gas, goconst +func (ec *executionContext) ___Type(ctx context.Context, sel []query.Selection, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __TypeImplementors, ec.Variables) + out := graphql.NewOrderedMap(len(fields)) + for i, field := range fields { + out.Keys[i] = field.Alias + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + out.Values[i] = ec.___Type_kind(ctx, field, obj) + case "name": + out.Values[i] = ec.___Type_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___Type_description(ctx, field, obj) + case "fields": + out.Values[i] = ec.___Type_fields(ctx, field, obj) + case "interfaces": + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + case "possibleTypes": + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + case "enumValues": + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + case "inputFields": + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + case "ofType": + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + + return out +} + +func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Kind() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Name() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + var arg0 bool + if tmp, ok := field.Args["includeDeprecated"]; ok { + var err error + arg0, err = graphql.UnmarshalBoolean(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := obj.Fields(arg0) + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Field(ctx, field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Interfaces() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(ctx, field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.PossibleTypes() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(ctx, field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + var arg0 bool + if tmp, ok := field.Args["includeDeprecated"]; ok { + var err error + arg0, err = graphql.UnmarshalBoolean(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := obj.EnumValues(arg0) + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___EnumValue(ctx, field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.InputFields() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(ctx, field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.OfType() + if res == nil { + return graphql.Null + } + return ec.___Type(ctx, field.Selections, res) +} + +func (ec *executionContext) _Event(ctx context.Context, sel []query.Selection, obj *Event) graphql.Marshaler { + switch obj := (*obj).(type) { + case nil: + return graphql.Null + case Post: + return ec._Post(ctx, sel, &obj) + case *Post: + return ec._Post(ctx, sel, obj) + case Like: + return ec._Like(ctx, sel, &obj) + case *Like: + return ec._Like(ctx, sel, obj) + default: + panic(fmt.Errorf("unexpected type %T", obj)) + } +} + +var parsedSchema = schema.MustParse("interface Event {\n selection: [String!]\n collected: [String!]\n}\n\ntype Post implements Event {\n message: String!\n sent: Time!\n selection: [String!]\n collected: [String!]\n}\n\ntype Like implements Event {\n reaction: String!\n sent: Time!\n selection: [String!]\n collected: [String!]\n}\n\ntype Query {\n events: [Event]\n}\n\nscalar Time\n") + +func (ec *executionContext) introspectSchema() *introspection.Schema { + return introspection.WrapSchema(parsedSchema) +} + +func (ec *executionContext) introspectType(name string) *introspection.Type { + t := parsedSchema.Resolve(name) + if t == nil { + return nil + } + return introspection.WrapType(t) +} diff --git a/example/selection/models_gen.go b/example/selection/models_gen.go new file mode 100644 index 0000000000..8eab610b45 --- /dev/null +++ b/example/selection/models_gen.go @@ -0,0 +1,21 @@ +// This file was generated by github.com/vektah/gqlgen, DO NOT EDIT + +package selection + +import ( + time "time" +) + +type Event interface{} +type Like struct { + Reaction string + Sent time.Time + Selection []string + Collected []string +} +type Post struct { + Message string + Sent time.Time + Selection []string + Collected []string +} diff --git a/example/selection/readme.md b/example/selection/readme.md new file mode 100644 index 0000000000..e8dc2e8e18 --- /dev/null +++ b/example/selection/readme.md @@ -0,0 +1,10 @@ +### todo app + +This is the simplest example of a graphql server. + +to run this server +```bash +go run ./example/todo/server/server.go +``` + +and open http://localhost:8081 in your browser diff --git a/example/selection/schema.graphql b/example/selection/schema.graphql new file mode 100644 index 0000000000..85a14b4de8 --- /dev/null +++ b/example/selection/schema.graphql @@ -0,0 +1,24 @@ +interface Event { + selection: [String!] + collected: [String!] +} + +type Post implements Event { + message: String! + sent: Time! + selection: [String!] + collected: [String!] +} + +type Like implements Event { + reaction: String! + sent: Time! + selection: [String!] + collected: [String!] +} + +type Query { + events: [Event] +} + +scalar Time diff --git a/example/selection/selection.go b/example/selection/selection.go new file mode 100644 index 0000000000..0da2a39e30 --- /dev/null +++ b/example/selection/selection.go @@ -0,0 +1,62 @@ +//go:generate gorunpkg github.com/vektah/gqlgen -out generated.go + +package selection + +import ( + context "context" + "fmt" + "time" + + "github.com/vektah/gqlgen/graphql" + query "github.com/vektah/gqlgen/neelance/query" +) + +type SelectionResolver struct{} + +func (r *SelectionResolver) Query_events(ctx context.Context) ([]Event, error) { + var sels []string + + reqCtx := graphql.GetRequestContext(ctx) + fieldSelections := graphql.GetResolverContext(ctx).Field.Selections + for _, sel := range fieldSelections { + switch sel := sel.(type) { + case *query.Field: + sels = append(sels, fmt.Sprintf("%s as %s", sel.Name.Name, sel.Alias.Name)) + case *query.InlineFragment: + sels = append(sels, fmt.Sprintf("inline fragment on %s", sel.On.Name)) + case *query.FragmentSpread: + fragment := reqCtx.Doc.Fragments.Get(sel.Name.Name) + sels = append(sels, fmt.Sprintf("named fragment %s on %s", sel.Name.Name, fragment.On.Name)) + } + } + + var events []Event + for i := 0; i < 10; i++ { + if i%2 == 0 { + events = append(events, &Like{ + Selection: sels, + Collected: formatCollected(graphql.CollectFieldsCtx(ctx, []string{"Like"})), + Reaction: ":=)", + Sent: time.Now(), + }) + } else { + events = append(events, &Post{ + Selection: sels, + Collected: formatCollected(graphql.CollectFieldsCtx(ctx, []string{"Post"})), + Message: "Hey", + Sent: time.Now(), + }) + } + } + + return events, nil +} + +func formatCollected(cf []graphql.CollectedField) []string { + var res []string + + for _, f := range cf { + res = append(res, fmt.Sprintf("%s as %s", f.Name, f.Alias)) + } + return res +} diff --git a/example/selection/selection_test.go b/example/selection/selection_test.go new file mode 100644 index 0000000000..4c1829a3aa --- /dev/null +++ b/example/selection/selection_test.go @@ -0,0 +1,58 @@ +package selection + +import ( + "net/http/httptest" + "testing" + + "github.com/vektah/gqlgen/client" + + "github.com/stretchr/testify/require" + "github.com/vektah/gqlgen/handler" +) + +func TestSelection(t *testing.T) { + srv := httptest.NewServer(handler.GraphQL(MakeExecutableSchema(&SelectionResolver{}))) + c := client.New(srv.URL) + + query := `{ + events { + selection + collected + + ... on Post { + message + sent + } + + ...LikeFragment + } + } + fragment LikeFragment on Like { reaction sent } + ` + + var resp struct { + Events []struct { + Selection []string + Collected []string + + Message string + Reaction string + Sent string + } + } + c.MustPost(query, &resp) + + require.Equal(t, []string{ + "selection as selection", + "collected as collected", + "inline fragment on Post", + "named fragment LikeFragment on Like", + }, resp.Events[0].Selection) + + require.Equal(t, []string{ + "selection as selection", + "collected as collected", + "reaction as reaction", + "sent as sent", + }, resp.Events[0].Collected) +} diff --git a/example/selection/server/server.go b/example/selection/server/server.go new file mode 100644 index 0000000000..e8982e8bd1 --- /dev/null +++ b/example/selection/server/server.go @@ -0,0 +1,15 @@ +package main + +import ( + "log" + "net/http" + + "github.com/vektah/gqlgen/example/selection" + "github.com/vektah/gqlgen/handler" +) + +func main() { + http.Handle("/", handler.Playground("Selection Demo", "/query")) + http.Handle("/query", handler.GraphQL(selection.MakeExecutableSchema(&selection.SelectionResolver{}))) + log.Fatal(http.ListenAndServe(":8086", nil)) +} diff --git a/graphql/context.go b/graphql/context.go index f271298f2a..a1abec5dc5 100644 --- a/graphql/context.go +++ b/graphql/context.go @@ -49,5 +49,12 @@ func GetResolverContext(ctx context.Context) *ResolverContext { } func WithResolverContext(ctx context.Context, rc *ResolverContext) context.Context { - return context.WithValue(ctx, request, rc) + return context.WithValue(ctx, resolver, rc) +} + +// This is just a convenient wrapper method for CollectFields +func CollectFieldsCtx(ctx context.Context, satisfies []string) []CollectedField { + reqctx := GetRequestContext(ctx) + resctx := GetResolverContext(ctx) + return CollectFields(reqctx.Doc, resctx.Field.Selections, satisfies, reqctx.Variables) } From c60336bff6e6367f71d48279bceaeb7cbd331299 Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Tue, 27 Mar 2018 23:53:19 +1100 Subject: [PATCH 4/4] regenerate --- example/chat/generated.go | 321 +++++++++--------- example/dataloader/generated.go | 348 ++++++++++---------- example/scalars/generated.go | 319 +++++++++--------- example/starwars/generated.go | 560 ++++++++++++++++---------------- example/todo/generated.go | 316 +++++++++--------- 5 files changed, 890 insertions(+), 974 deletions(-) diff --git a/example/chat/generated.go b/example/chat/generated.go index 59e916d67d..38bb27213d 100644 --- a/example/chat/generated.go +++ b/example/chat/generated.go @@ -8,18 +8,13 @@ import ( strconv "strconv" graphql "github.com/vektah/gqlgen/graphql" - errors "github.com/vektah/gqlgen/neelance/errors" introspection "github.com/vektah/gqlgen/neelance/introspection" query "github.com/vektah/gqlgen/neelance/query" schema "github.com/vektah/gqlgen/neelance/schema" ) -func MakeExecutableSchema(resolvers Resolvers, opts ...ExecutableOption) graphql.ExecutableSchema { - ret := &executableSchema{resolvers: resolvers} - for _, opt := range opts { - opt(ret) - } - return ret +func MakeExecutableSchema(resolvers Resolvers) graphql.ExecutableSchema { + return &executableSchema{resolvers: resolvers} } type Resolvers interface { @@ -29,27 +24,18 @@ type Resolvers interface { Subscription_messageAdded(ctx context.Context, roomName string) (<-chan Message, error) } -type ExecutableOption func(*executableSchema) - -func WithErrorConverter(fn func(error) string) ExecutableOption { - return func(s *executableSchema) { - s.errorMessageFn = fn - } -} - type executableSchema struct { - resolvers Resolvers - errorMessageFn func(error) string + resolvers Resolvers } func (e *executableSchema) Schema() *schema.Schema { return parsedSchema } -func (e *executableSchema) Query(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { - ec := e.makeExecutionContext(ctx, doc, variables, recover) +func (e *executableSchema) Query(ctx context.Context, op *query.Operation) *graphql.Response { + ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers} - data := ec._Query(op.Selections) + data := ec._Query(ctx, op.Selections) var buf bytes.Buffer data.MarshalGQL(&buf) @@ -59,10 +45,10 @@ func (e *executableSchema) Query(ctx context.Context, doc *query.Document, varia } } -func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { - ec := e.makeExecutionContext(ctx, doc, variables, recover) +func (e *executableSchema) Mutation(ctx context.Context, op *query.Operation) *graphql.Response { + ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers} - data := ec._Mutation(op.Selections) + data := ec._Mutation(ctx, op.Selections) var buf bytes.Buffer data.MarshalGQL(&buf) @@ -72,10 +58,10 @@ func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, va } } -func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) func() *graphql.Response { - ec := e.makeExecutionContext(ctx, doc, variables, recover) +func (e *executableSchema) Subscription(ctx context.Context, op *query.Operation) func() *graphql.Response { + ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers} - next := ec._Subscription(op.Selections) + next := ec._Subscription(ctx, op.Selections) if ec.Errors != nil { return graphql.OneShot(&graphql.Response{Data: []byte("null"), Errors: ec.Errors}) } @@ -98,27 +84,17 @@ func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document } } -func (e *executableSchema) makeExecutionContext(ctx context.Context, doc *query.Document, variables map[string]interface{}, recover graphql.RecoverFunc) *executionContext { - errBuilder := errors.Builder{ErrorMessageFn: e.errorMessageFn} - return &executionContext{ - Builder: errBuilder, resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx, recover: recover, - } -} - type executionContext struct { - errors.Builder + *graphql.RequestContext + resolvers Resolvers - variables map[string]interface{} - doc *query.Document - ctx context.Context - recover graphql.RecoverFunc } var chatroomImplementors = []string{"Chatroom"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Chatroom(sel []query.Selection, obj *Chatroom) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, chatroomImplementors, ec.variables) +func (ec *executionContext) _Chatroom(ctx context.Context, sel []query.Selection, obj *Chatroom) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, chatroomImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -127,9 +103,9 @@ func (ec *executionContext) _Chatroom(sel []query.Selection, obj *Chatroom) grap case "__typename": out.Values[i] = graphql.MarshalString("Chatroom") case "name": - out.Values[i] = ec._Chatroom_name(field, obj) + out.Values[i] = ec._Chatroom_name(ctx, field, obj) case "messages": - out.Values[i] = ec._Chatroom_messages(field, obj) + out.Values[i] = ec._Chatroom_messages(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -138,16 +114,16 @@ func (ec *executionContext) _Chatroom(sel []query.Selection, obj *Chatroom) grap return out } -func (ec *executionContext) _Chatroom_name(field graphql.CollectedField, obj *Chatroom) graphql.Marshaler { +func (ec *executionContext) _Chatroom_name(ctx context.Context, field graphql.CollectedField, obj *Chatroom) graphql.Marshaler { res := obj.Name return graphql.MarshalString(res) } -func (ec *executionContext) _Chatroom_messages(field graphql.CollectedField, obj *Chatroom) graphql.Marshaler { +func (ec *executionContext) _Chatroom_messages(ctx context.Context, field graphql.CollectedField, obj *Chatroom) graphql.Marshaler { res := obj.Messages arr1 := graphql.Array{} for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { return ec._Message(field.Selections, &res[idx1]) }()) + arr1 = append(arr1, func() graphql.Marshaler { return ec._Message(ctx, field.Selections, &res[idx1]) }()) } return arr1 } @@ -155,8 +131,8 @@ func (ec *executionContext) _Chatroom_messages(field graphql.CollectedField, obj var messageImplementors = []string{"Message"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Message(sel []query.Selection, obj *Message) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, messageImplementors, ec.variables) +func (ec *executionContext) _Message(ctx context.Context, sel []query.Selection, obj *Message) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, messageImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -165,13 +141,13 @@ func (ec *executionContext) _Message(sel []query.Selection, obj *Message) graphq case "__typename": out.Values[i] = graphql.MarshalString("Message") case "id": - out.Values[i] = ec._Message_id(field, obj) + out.Values[i] = ec._Message_id(ctx, field, obj) case "text": - out.Values[i] = ec._Message_text(field, obj) + out.Values[i] = ec._Message_text(ctx, field, obj) case "createdBy": - out.Values[i] = ec._Message_createdBy(field, obj) + out.Values[i] = ec._Message_createdBy(ctx, field, obj) case "createdAt": - out.Values[i] = ec._Message_createdAt(field, obj) + out.Values[i] = ec._Message_createdAt(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -180,22 +156,22 @@ func (ec *executionContext) _Message(sel []query.Selection, obj *Message) graphq return out } -func (ec *executionContext) _Message_id(field graphql.CollectedField, obj *Message) graphql.Marshaler { +func (ec *executionContext) _Message_id(ctx context.Context, field graphql.CollectedField, obj *Message) graphql.Marshaler { res := obj.ID return graphql.MarshalID(res) } -func (ec *executionContext) _Message_text(field graphql.CollectedField, obj *Message) graphql.Marshaler { +func (ec *executionContext) _Message_text(ctx context.Context, field graphql.CollectedField, obj *Message) graphql.Marshaler { res := obj.Text return graphql.MarshalString(res) } -func (ec *executionContext) _Message_createdBy(field graphql.CollectedField, obj *Message) graphql.Marshaler { +func (ec *executionContext) _Message_createdBy(ctx context.Context, field graphql.CollectedField, obj *Message) graphql.Marshaler { res := obj.CreatedBy return graphql.MarshalString(res) } -func (ec *executionContext) _Message_createdAt(field graphql.CollectedField, obj *Message) graphql.Marshaler { +func (ec *executionContext) _Message_createdAt(ctx context.Context, field graphql.CollectedField, obj *Message) graphql.Marshaler { res := obj.CreatedAt return graphql.MarshalTime(res) } @@ -203,8 +179,8 @@ func (ec *executionContext) _Message_createdAt(field graphql.CollectedField, obj var mutationImplementors = []string{"Mutation"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Mutation(sel []query.Selection) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, mutationImplementors, ec.variables) +func (ec *executionContext) _Mutation(ctx context.Context, sel []query.Selection) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, mutationImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -213,7 +189,7 @@ func (ec *executionContext) _Mutation(sel []query.Selection) graphql.Marshaler { case "__typename": out.Values[i] = graphql.MarshalString("Mutation") case "post": - out.Values[i] = ec._Mutation_post(field) + out.Values[i] = ec._Mutation_post(ctx, field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -222,7 +198,7 @@ func (ec *executionContext) _Mutation(sel []query.Selection) graphql.Marshaler { return out } -func (ec *executionContext) _Mutation_post(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Mutation_post(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["text"]; ok { var err error @@ -250,19 +226,20 @@ func (ec *executionContext) _Mutation_post(field graphql.CollectedField) graphql return graphql.Null } } - res, err := ec.resolvers.Mutation_post(ec.ctx, arg0, arg1, arg2) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Mutation_post(rctx, arg0, arg1, arg2) if err != nil { ec.Error(err) return graphql.Null } - return ec._Message(field.Selections, &res) + return ec._Message(ctx, field.Selections, &res) } var queryImplementors = []string{"Query"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, queryImplementors, ec.variables) +func (ec *executionContext) _Query(ctx context.Context, sel []query.Selection) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, queryImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -271,11 +248,11 @@ func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { case "__typename": out.Values[i] = graphql.MarshalString("Query") case "room": - out.Values[i] = ec._Query_room(field) + out.Values[i] = ec._Query_room(ctx, field) case "__schema": - out.Values[i] = ec._Query___schema(field) + out.Values[i] = ec._Query___schema(ctx, field) case "__type": - out.Values[i] = ec._Query___type(field) + out.Values[i] = ec._Query___type(ctx, field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -284,7 +261,7 @@ func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { return out } -func (ec *executionContext) _Query_room(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_room(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["name"]; ok { var err error @@ -297,12 +274,13 @@ func (ec *executionContext) _Query_room(field graphql.CollectedField) graphql.Ma return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_room(ec.ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_room(rctx, arg0) if err != nil { ec.Error(err) return graphql.Null @@ -310,19 +288,19 @@ func (ec *executionContext) _Query_room(field graphql.CollectedField) graphql.Ma if res == nil { return graphql.Null } - return ec._Chatroom(field.Selections, res) + return ec._Chatroom(ctx, field.Selections, res) }) } -func (ec *executionContext) _Query___schema(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { res := ec.introspectSchema() if res == nil { return graphql.Null } - return ec.___Schema(field.Selections, res) + return ec.___Schema(ctx, field.Selections, res) } -func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["name"]; ok { var err error @@ -336,14 +314,14 @@ func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql. if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } var subscriptionImplementors = []string{"Subscription"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Subscription(sel []query.Selection) func() graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, subscriptionImplementors, ec.variables) +func (ec *executionContext) _Subscription(ctx context.Context, sel []query.Selection) func() graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, subscriptionImplementors, ec.Variables) if len(fields) != 1 { ec.Errorf("must subscribe to exactly one stream") @@ -352,13 +330,13 @@ func (ec *executionContext) _Subscription(sel []query.Selection) func() graphql. switch fields[0].Name { case "messageAdded": - return ec._Subscription_messageAdded(fields[0]) + return ec._Subscription_messageAdded(ctx, fields[0]) default: panic("unknown field " + strconv.Quote(fields[0].Name)) } } -func (ec *executionContext) _Subscription_messageAdded(field graphql.CollectedField) func() graphql.Marshaler { +func (ec *executionContext) _Subscription_messageAdded(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { var arg0 string if tmp, ok := field.Args["roomName"]; ok { var err error @@ -368,7 +346,8 @@ func (ec *executionContext) _Subscription_messageAdded(field graphql.CollectedFi return nil } } - results, err := ec.resolvers.Subscription_messageAdded(ec.ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + results, err := ec.resolvers.Subscription_messageAdded(rctx, arg0) if err != nil { ec.Error(err) return nil @@ -379,7 +358,7 @@ func (ec *executionContext) _Subscription_messageAdded(field graphql.CollectedFi return nil } var out graphql.OrderedMap - out.Add(field.Alias, func() graphql.Marshaler { return ec._Message(field.Selections, &res) }()) + out.Add(field.Alias, func() graphql.Marshaler { return ec._Message(ctx, field.Selections, &res) }()) return &out } } @@ -387,8 +366,8 @@ func (ec *executionContext) _Subscription_messageAdded(field graphql.CollectedFi var __DirectiveImplementors = []string{"__Directive"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __DirectiveImplementors, ec.variables) +func (ec *executionContext) ___Directive(ctx context.Context, sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __DirectiveImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -397,13 +376,13 @@ func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspecti case "__typename": out.Values[i] = graphql.MarshalString("__Directive") case "name": - out.Values[i] = ec.___Directive_name(field, obj) + out.Values[i] = ec.___Directive_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Directive_description(field, obj) + out.Values[i] = ec.___Directive_description(ctx, field, obj) case "locations": - out.Values[i] = ec.___Directive_locations(field, obj) + out.Values[i] = ec.___Directive_locations(ctx, field, obj) case "args": - out.Values[i] = ec.___Directive_args(field, obj) + out.Values[i] = ec.___Directive_args(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -412,12 +391,12 @@ func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspecti return out } -func (ec *executionContext) ___Directive_name(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___Directive_description(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -425,7 +404,7 @@ func (ec *executionContext) ___Directive_description(field graphql.CollectedFiel return graphql.MarshalString(*res) } -func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Locations() arr1 := graphql.Array{} for idx1 := range res { @@ -434,7 +413,7 @@ func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, return arr1 } -func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Args() arr1 := graphql.Array{} for idx1 := range res { @@ -442,7 +421,7 @@ func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 @@ -451,8 +430,8 @@ func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj var __EnumValueImplementors = []string{"__EnumValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __EnumValueImplementors, ec.variables) +func (ec *executionContext) ___EnumValue(ctx context.Context, sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __EnumValueImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -461,13 +440,13 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspecti case "__typename": out.Values[i] = graphql.MarshalString("__EnumValue") case "name": - out.Values[i] = ec.___EnumValue_name(field, obj) + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) case "description": - out.Values[i] = ec.___EnumValue_description(field, obj) + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(field, obj) + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(field, obj) + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -476,12 +455,12 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspecti return out } -func (ec *executionContext) ___EnumValue_name(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___EnumValue_description(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -489,12 +468,12 @@ func (ec *executionContext) ___EnumValue_description(field graphql.CollectedFiel return graphql.MarshalString(*res) } -func (ec *executionContext) ___EnumValue_isDeprecated(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.IsDeprecated() return graphql.MarshalBoolean(res) } -func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.DeprecationReason() if res == nil { return graphql.Null @@ -505,8 +484,8 @@ func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.Collect var __FieldImplementors = []string{"__Field"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __FieldImplementors, ec.variables) +func (ec *executionContext) ___Field(ctx context.Context, sel []query.Selection, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __FieldImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -515,17 +494,17 @@ func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.F case "__typename": out.Values[i] = graphql.MarshalString("__Field") case "name": - out.Values[i] = ec.___Field_name(field, obj) + out.Values[i] = ec.___Field_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Field_description(field, obj) + out.Values[i] = ec.___Field_description(ctx, field, obj) case "args": - out.Values[i] = ec.___Field_args(field, obj) + out.Values[i] = ec.___Field_args(ctx, field, obj) case "type": - out.Values[i] = ec.___Field_type(field, obj) + out.Values[i] = ec.___Field_type(ctx, field, obj) case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(field, obj) + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(field, obj) + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -534,12 +513,12 @@ func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.F return out } -func (ec *executionContext) ___Field_name(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___Field_description(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -547,7 +526,7 @@ func (ec *executionContext) ___Field_description(field graphql.CollectedField, o return graphql.MarshalString(*res) } -func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Args() arr1 := graphql.Array{} for idx1 := range res { @@ -555,26 +534,26 @@ func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *int if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Field_type(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Type() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Field_isDeprecated(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.IsDeprecated() return graphql.MarshalBoolean(res) } -func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.DeprecationReason() if res == nil { return graphql.Null @@ -585,8 +564,8 @@ func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedFi var __InputValueImplementors = []string{"__InputValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __InputValueImplementors, ec.variables) +func (ec *executionContext) ___InputValue(ctx context.Context, sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __InputValueImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -595,13 +574,13 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspect case "__typename": out.Values[i] = graphql.MarshalString("__InputValue") case "name": - out.Values[i] = ec.___InputValue_name(field, obj) + out.Values[i] = ec.___InputValue_name(ctx, field, obj) case "description": - out.Values[i] = ec.___InputValue_description(field, obj) + out.Values[i] = ec.___InputValue_description(ctx, field, obj) case "type": - out.Values[i] = ec.___InputValue_type(field, obj) + out.Values[i] = ec.___InputValue_type(ctx, field, obj) case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(field, obj) + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -610,12 +589,12 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspect return out } -func (ec *executionContext) ___InputValue_name(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___InputValue_description(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -623,15 +602,15 @@ func (ec *executionContext) ___InputValue_description(field graphql.CollectedFie return graphql.MarshalString(*res) } -func (ec *executionContext) ___InputValue_type(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Type() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.DefaultValue() if res == nil { return graphql.Null @@ -642,8 +621,8 @@ func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedFi var __SchemaImplementors = []string{"__Schema"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __SchemaImplementors, ec.variables) +func (ec *executionContext) ___Schema(ctx context.Context, sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __SchemaImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -652,15 +631,15 @@ func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection. case "__typename": out.Values[i] = graphql.MarshalString("__Schema") case "types": - out.Values[i] = ec.___Schema_types(field, obj) + out.Values[i] = ec.___Schema_types(ctx, field, obj) case "queryType": - out.Values[i] = ec.___Schema_queryType(field, obj) + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) case "mutationType": - out.Values[i] = ec.___Schema_mutationType(field, obj) + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(field, obj) + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) case "directives": - out.Values[i] = ec.___Schema_directives(field, obj) + out.Values[i] = ec.___Schema_directives(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -669,7 +648,7 @@ func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection. return out } -func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.Types() arr1 := graphql.Array{} for idx1 := range res { @@ -677,37 +656,37 @@ func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *i if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Schema_queryType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.QueryType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_mutationType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.MutationType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_subscriptionType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.SubscriptionType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.Directives() arr1 := graphql.Array{} for idx1 := range res { @@ -715,7 +694,7 @@ func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, o if res[idx1] == nil { return graphql.Null } - return ec.___Directive(field.Selections, res[idx1]) + return ec.___Directive(ctx, field.Selections, res[idx1]) }()) } return arr1 @@ -724,8 +703,8 @@ func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, o var __TypeImplementors = []string{"__Type"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __TypeImplementors, ec.variables) +func (ec *executionContext) ___Type(ctx context.Context, sel []query.Selection, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __TypeImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -734,23 +713,23 @@ func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Ty case "__typename": out.Values[i] = graphql.MarshalString("__Type") case "kind": - out.Values[i] = ec.___Type_kind(field, obj) + out.Values[i] = ec.___Type_kind(ctx, field, obj) case "name": - out.Values[i] = ec.___Type_name(field, obj) + out.Values[i] = ec.___Type_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Type_description(field, obj) + out.Values[i] = ec.___Type_description(ctx, field, obj) case "fields": - out.Values[i] = ec.___Type_fields(field, obj) + out.Values[i] = ec.___Type_fields(ctx, field, obj) case "interfaces": - out.Values[i] = ec.___Type_interfaces(field, obj) + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(field, obj) + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) case "enumValues": - out.Values[i] = ec.___Type_enumValues(field, obj) + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) case "inputFields": - out.Values[i] = ec.___Type_inputFields(field, obj) + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) case "ofType": - out.Values[i] = ec.___Type_ofType(field, obj) + out.Values[i] = ec.___Type_ofType(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -759,12 +738,12 @@ func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Ty return out } -func (ec *executionContext) ___Type_kind(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Kind() return graphql.MarshalString(res) } -func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Name() if res == nil { return graphql.Null @@ -772,7 +751,7 @@ func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *intr return graphql.MarshalString(*res) } -func (ec *executionContext) ___Type_description(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -780,7 +759,7 @@ func (ec *executionContext) ___Type_description(field graphql.CollectedField, ob return graphql.MarshalString(*res) } -func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -797,13 +776,13 @@ func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *in if res[idx1] == nil { return graphql.Null } - return ec.___Field(field.Selections, res[idx1]) + return ec.___Field(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Interfaces() arr1 := graphql.Array{} for idx1 := range res { @@ -811,13 +790,13 @@ func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.PossibleTypes() arr1 := graphql.Array{} for idx1 := range res { @@ -825,13 +804,13 @@ func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -848,13 +827,13 @@ func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___EnumValue(field.Selections, res[idx1]) + return ec.___EnumValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.InputFields() arr1 := graphql.Array{} for idx1 := range res { @@ -862,18 +841,18 @@ func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, ob if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_ofType(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.OfType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } var parsedSchema = schema.MustParse("type Chatroom {\n name: String!\n messages: [Message!]!\n}\n\ntype Message {\n id: ID!\n text: String!\n createdBy: String!\n createdAt: Time!\n}\n\ntype Query {\n room(name:String!): Chatroom\n}\n\ntype Mutation {\n post(text: String!, username: String!, roomName: String!): Message!\n}\n\ntype Subscription {\n messageAdded(roomName: String!): Message!\n}\n\nscalar Time\n") diff --git a/example/dataloader/generated.go b/example/dataloader/generated.go index 6cf544453c..2e028b307f 100644 --- a/example/dataloader/generated.go +++ b/example/dataloader/generated.go @@ -14,12 +14,8 @@ import ( schema "github.com/vektah/gqlgen/neelance/schema" ) -func MakeExecutableSchema(resolvers Resolvers, opts ...ExecutableOption) graphql.ExecutableSchema { - ret := &executableSchema{resolvers: resolvers} - for _, opt := range opts { - opt(ret) - } - return ret +func MakeExecutableSchema(resolvers Resolvers) graphql.ExecutableSchema { + return &executableSchema{resolvers: resolvers} } type Resolvers interface { @@ -31,27 +27,18 @@ type Resolvers interface { Query_torture(ctx context.Context, customerIds [][]int) ([][]Customer, error) } -type ExecutableOption func(*executableSchema) - -func WithErrorConverter(fn func(error) string) ExecutableOption { - return func(s *executableSchema) { - s.errorMessageFn = fn - } -} - type executableSchema struct { - resolvers Resolvers - errorMessageFn func(error) string + resolvers Resolvers } func (e *executableSchema) Schema() *schema.Schema { return parsedSchema } -func (e *executableSchema) Query(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { - ec := e.makeExecutionContext(ctx, doc, variables, recover) +func (e *executableSchema) Query(ctx context.Context, op *query.Operation) *graphql.Response { + ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers} - data := ec._Query(op.Selections) + data := ec._Query(ctx, op.Selections) var buf bytes.Buffer data.MarshalGQL(&buf) @@ -61,35 +48,25 @@ func (e *executableSchema) Query(ctx context.Context, doc *query.Document, varia } } -func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { +func (e *executableSchema) Mutation(ctx context.Context, op *query.Operation) *graphql.Response { return &graphql.Response{Errors: []*errors.QueryError{{Message: "mutations are not supported"}}} } -func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) func() *graphql.Response { +func (e *executableSchema) Subscription(ctx context.Context, op *query.Operation) func() *graphql.Response { return graphql.OneShot(&graphql.Response{Errors: []*errors.QueryError{{Message: "subscriptions are not supported"}}}) } -func (e *executableSchema) makeExecutionContext(ctx context.Context, doc *query.Document, variables map[string]interface{}, recover graphql.RecoverFunc) *executionContext { - errBuilder := errors.Builder{ErrorMessageFn: e.errorMessageFn} - return &executionContext{ - Builder: errBuilder, resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx, recover: recover, - } -} - type executionContext struct { - errors.Builder + *graphql.RequestContext + resolvers Resolvers - variables map[string]interface{} - doc *query.Document - ctx context.Context - recover graphql.RecoverFunc } var addressImplementors = []string{"Address"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Address(sel []query.Selection, obj *Address) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, addressImplementors, ec.variables) +func (ec *executionContext) _Address(ctx context.Context, sel []query.Selection, obj *Address) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, addressImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -98,11 +75,11 @@ func (ec *executionContext) _Address(sel []query.Selection, obj *Address) graphq case "__typename": out.Values[i] = graphql.MarshalString("Address") case "id": - out.Values[i] = ec._Address_id(field, obj) + out.Values[i] = ec._Address_id(ctx, field, obj) case "street": - out.Values[i] = ec._Address_street(field, obj) + out.Values[i] = ec._Address_street(ctx, field, obj) case "country": - out.Values[i] = ec._Address_country(field, obj) + out.Values[i] = ec._Address_country(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -111,17 +88,17 @@ func (ec *executionContext) _Address(sel []query.Selection, obj *Address) graphq return out } -func (ec *executionContext) _Address_id(field graphql.CollectedField, obj *Address) graphql.Marshaler { +func (ec *executionContext) _Address_id(ctx context.Context, field graphql.CollectedField, obj *Address) graphql.Marshaler { res := obj.ID return graphql.MarshalInt(res) } -func (ec *executionContext) _Address_street(field graphql.CollectedField, obj *Address) graphql.Marshaler { +func (ec *executionContext) _Address_street(ctx context.Context, field graphql.CollectedField, obj *Address) graphql.Marshaler { res := obj.Street return graphql.MarshalString(res) } -func (ec *executionContext) _Address_country(field graphql.CollectedField, obj *Address) graphql.Marshaler { +func (ec *executionContext) _Address_country(ctx context.Context, field graphql.CollectedField, obj *Address) graphql.Marshaler { res := obj.Country return graphql.MarshalString(res) } @@ -129,8 +106,8 @@ func (ec *executionContext) _Address_country(field graphql.CollectedField, obj * var customerImplementors = []string{"Customer"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Customer(sel []query.Selection, obj *Customer) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, customerImplementors, ec.variables) +func (ec *executionContext) _Customer(ctx context.Context, sel []query.Selection, obj *Customer) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, customerImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -139,13 +116,13 @@ func (ec *executionContext) _Customer(sel []query.Selection, obj *Customer) grap case "__typename": out.Values[i] = graphql.MarshalString("Customer") case "id": - out.Values[i] = ec._Customer_id(field, obj) + out.Values[i] = ec._Customer_id(ctx, field, obj) case "name": - out.Values[i] = ec._Customer_name(field, obj) + out.Values[i] = ec._Customer_name(ctx, field, obj) case "address": - out.Values[i] = ec._Customer_address(field, obj) + out.Values[i] = ec._Customer_address(ctx, field, obj) case "orders": - out.Values[i] = ec._Customer_orders(field, obj) + out.Values[i] = ec._Customer_orders(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -154,26 +131,27 @@ func (ec *executionContext) _Customer(sel []query.Selection, obj *Customer) grap return out } -func (ec *executionContext) _Customer_id(field graphql.CollectedField, obj *Customer) graphql.Marshaler { +func (ec *executionContext) _Customer_id(ctx context.Context, field graphql.CollectedField, obj *Customer) graphql.Marshaler { res := obj.ID return graphql.MarshalInt(res) } -func (ec *executionContext) _Customer_name(field graphql.CollectedField, obj *Customer) graphql.Marshaler { +func (ec *executionContext) _Customer_name(ctx context.Context, field graphql.CollectedField, obj *Customer) graphql.Marshaler { res := obj.Name return graphql.MarshalString(res) } -func (ec *executionContext) _Customer_address(field graphql.CollectedField, obj *Customer) graphql.Marshaler { +func (ec *executionContext) _Customer_address(ctx context.Context, field graphql.CollectedField, obj *Customer) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Customer_address(ec.ctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Customer_address(rctx, obj) if err != nil { ec.Error(err) return graphql.Null @@ -181,27 +159,28 @@ func (ec *executionContext) _Customer_address(field graphql.CollectedField, obj if res == nil { return graphql.Null } - return ec._Address(field.Selections, res) + return ec._Address(ctx, field.Selections, res) }) } -func (ec *executionContext) _Customer_orders(field graphql.CollectedField, obj *Customer) graphql.Marshaler { +func (ec *executionContext) _Customer_orders(ctx context.Context, field graphql.CollectedField, obj *Customer) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Customer_orders(ec.ctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Customer_orders(rctx, obj) if err != nil { ec.Error(err) return graphql.Null } arr1 := graphql.Array{} for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { return ec._Order(field.Selections, &res[idx1]) }()) + arr1 = append(arr1, func() graphql.Marshaler { return ec._Order(ctx, field.Selections, &res[idx1]) }()) } return arr1 }) @@ -210,8 +189,8 @@ func (ec *executionContext) _Customer_orders(field graphql.CollectedField, obj * var itemImplementors = []string{"Item"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Item(sel []query.Selection, obj *Item) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, itemImplementors, ec.variables) +func (ec *executionContext) _Item(ctx context.Context, sel []query.Selection, obj *Item) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, itemImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -220,7 +199,7 @@ func (ec *executionContext) _Item(sel []query.Selection, obj *Item) graphql.Mars case "__typename": out.Values[i] = graphql.MarshalString("Item") case "name": - out.Values[i] = ec._Item_name(field, obj) + out.Values[i] = ec._Item_name(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -229,7 +208,7 @@ func (ec *executionContext) _Item(sel []query.Selection, obj *Item) graphql.Mars return out } -func (ec *executionContext) _Item_name(field graphql.CollectedField, obj *Item) graphql.Marshaler { +func (ec *executionContext) _Item_name(ctx context.Context, field graphql.CollectedField, obj *Item) graphql.Marshaler { res := obj.Name return graphql.MarshalString(res) } @@ -237,8 +216,8 @@ func (ec *executionContext) _Item_name(field graphql.CollectedField, obj *Item) var orderImplementors = []string{"Order"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Order(sel []query.Selection, obj *Order) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, orderImplementors, ec.variables) +func (ec *executionContext) _Order(ctx context.Context, sel []query.Selection, obj *Order) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, orderImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -247,13 +226,13 @@ func (ec *executionContext) _Order(sel []query.Selection, obj *Order) graphql.Ma case "__typename": out.Values[i] = graphql.MarshalString("Order") case "id": - out.Values[i] = ec._Order_id(field, obj) + out.Values[i] = ec._Order_id(ctx, field, obj) case "date": - out.Values[i] = ec._Order_date(field, obj) + out.Values[i] = ec._Order_date(ctx, field, obj) case "amount": - out.Values[i] = ec._Order_amount(field, obj) + out.Values[i] = ec._Order_amount(ctx, field, obj) case "items": - out.Values[i] = ec._Order_items(field, obj) + out.Values[i] = ec._Order_items(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -262,38 +241,39 @@ func (ec *executionContext) _Order(sel []query.Selection, obj *Order) graphql.Ma return out } -func (ec *executionContext) _Order_id(field graphql.CollectedField, obj *Order) graphql.Marshaler { +func (ec *executionContext) _Order_id(ctx context.Context, field graphql.CollectedField, obj *Order) graphql.Marshaler { res := obj.ID return graphql.MarshalInt(res) } -func (ec *executionContext) _Order_date(field graphql.CollectedField, obj *Order) graphql.Marshaler { +func (ec *executionContext) _Order_date(ctx context.Context, field graphql.CollectedField, obj *Order) graphql.Marshaler { res := obj.Date return graphql.MarshalTime(res) } -func (ec *executionContext) _Order_amount(field graphql.CollectedField, obj *Order) graphql.Marshaler { +func (ec *executionContext) _Order_amount(ctx context.Context, field graphql.CollectedField, obj *Order) graphql.Marshaler { res := obj.Amount return graphql.MarshalFloat(res) } -func (ec *executionContext) _Order_items(field graphql.CollectedField, obj *Order) graphql.Marshaler { +func (ec *executionContext) _Order_items(ctx context.Context, field graphql.CollectedField, obj *Order) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Order_items(ec.ctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Order_items(rctx, obj) if err != nil { ec.Error(err) return graphql.Null } arr1 := graphql.Array{} for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { return ec._Item(field.Selections, &res[idx1]) }()) + arr1 = append(arr1, func() graphql.Marshaler { return ec._Item(ctx, field.Selections, &res[idx1]) }()) } return arr1 }) @@ -302,8 +282,8 @@ func (ec *executionContext) _Order_items(field graphql.CollectedField, obj *Orde var queryImplementors = []string{"Query"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, queryImplementors, ec.variables) +func (ec *executionContext) _Query(ctx context.Context, sel []query.Selection) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, queryImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -312,13 +292,13 @@ func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { case "__typename": out.Values[i] = graphql.MarshalString("Query") case "customers": - out.Values[i] = ec._Query_customers(field) + out.Values[i] = ec._Query_customers(ctx, field) case "torture": - out.Values[i] = ec._Query_torture(field) + out.Values[i] = ec._Query_torture(ctx, field) case "__schema": - out.Values[i] = ec._Query___schema(field) + out.Values[i] = ec._Query___schema(ctx, field) case "__type": - out.Values[i] = ec._Query___type(field) + out.Values[i] = ec._Query___type(ctx, field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -327,29 +307,30 @@ func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { return out } -func (ec *executionContext) _Query_customers(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_customers(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_customers(ec.ctx) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_customers(rctx) if err != nil { ec.Error(err) return graphql.Null } arr1 := graphql.Array{} for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { return ec._Customer(field.Selections, &res[idx1]) }()) + arr1 = append(arr1, func() graphql.Marshaler { return ec._Customer(ctx, field.Selections, &res[idx1]) }()) } return arr1 }) } -func (ec *executionContext) _Query_torture(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_torture(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 [][]int if tmp, ok := field.Args["customerIds"]; ok { var err error @@ -370,12 +351,13 @@ func (ec *executionContext) _Query_torture(field graphql.CollectedField) graphql return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_torture(ec.ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_torture(rctx, arg0) if err != nil { ec.Error(err) return graphql.Null @@ -385,7 +367,7 @@ func (ec *executionContext) _Query_torture(field graphql.CollectedField) graphql arr1 = append(arr1, func() graphql.Marshaler { arr2 := graphql.Array{} for idx2 := range res[idx1] { - arr2 = append(arr2, func() graphql.Marshaler { return ec._Customer(field.Selections, &res[idx1][idx2]) }()) + arr2 = append(arr2, func() graphql.Marshaler { return ec._Customer(ctx, field.Selections, &res[idx1][idx2]) }()) } return arr2 }()) @@ -394,15 +376,15 @@ func (ec *executionContext) _Query_torture(field graphql.CollectedField) graphql }) } -func (ec *executionContext) _Query___schema(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { res := ec.introspectSchema() if res == nil { return graphql.Null } - return ec.___Schema(field.Selections, res) + return ec.___Schema(ctx, field.Selections, res) } -func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["name"]; ok { var err error @@ -416,14 +398,14 @@ func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql. if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } var __DirectiveImplementors = []string{"__Directive"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __DirectiveImplementors, ec.variables) +func (ec *executionContext) ___Directive(ctx context.Context, sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __DirectiveImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -432,13 +414,13 @@ func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspecti case "__typename": out.Values[i] = graphql.MarshalString("__Directive") case "name": - out.Values[i] = ec.___Directive_name(field, obj) + out.Values[i] = ec.___Directive_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Directive_description(field, obj) + out.Values[i] = ec.___Directive_description(ctx, field, obj) case "locations": - out.Values[i] = ec.___Directive_locations(field, obj) + out.Values[i] = ec.___Directive_locations(ctx, field, obj) case "args": - out.Values[i] = ec.___Directive_args(field, obj) + out.Values[i] = ec.___Directive_args(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -447,12 +429,12 @@ func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspecti return out } -func (ec *executionContext) ___Directive_name(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___Directive_description(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -460,7 +442,7 @@ func (ec *executionContext) ___Directive_description(field graphql.CollectedFiel return graphql.MarshalString(*res) } -func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Locations() arr1 := graphql.Array{} for idx1 := range res { @@ -469,7 +451,7 @@ func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, return arr1 } -func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Args() arr1 := graphql.Array{} for idx1 := range res { @@ -477,7 +459,7 @@ func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 @@ -486,8 +468,8 @@ func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj var __EnumValueImplementors = []string{"__EnumValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __EnumValueImplementors, ec.variables) +func (ec *executionContext) ___EnumValue(ctx context.Context, sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __EnumValueImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -496,13 +478,13 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspecti case "__typename": out.Values[i] = graphql.MarshalString("__EnumValue") case "name": - out.Values[i] = ec.___EnumValue_name(field, obj) + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) case "description": - out.Values[i] = ec.___EnumValue_description(field, obj) + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(field, obj) + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(field, obj) + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -511,12 +493,12 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspecti return out } -func (ec *executionContext) ___EnumValue_name(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___EnumValue_description(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -524,12 +506,12 @@ func (ec *executionContext) ___EnumValue_description(field graphql.CollectedFiel return graphql.MarshalString(*res) } -func (ec *executionContext) ___EnumValue_isDeprecated(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.IsDeprecated() return graphql.MarshalBoolean(res) } -func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.DeprecationReason() if res == nil { return graphql.Null @@ -540,8 +522,8 @@ func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.Collect var __FieldImplementors = []string{"__Field"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __FieldImplementors, ec.variables) +func (ec *executionContext) ___Field(ctx context.Context, sel []query.Selection, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __FieldImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -550,17 +532,17 @@ func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.F case "__typename": out.Values[i] = graphql.MarshalString("__Field") case "name": - out.Values[i] = ec.___Field_name(field, obj) + out.Values[i] = ec.___Field_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Field_description(field, obj) + out.Values[i] = ec.___Field_description(ctx, field, obj) case "args": - out.Values[i] = ec.___Field_args(field, obj) + out.Values[i] = ec.___Field_args(ctx, field, obj) case "type": - out.Values[i] = ec.___Field_type(field, obj) + out.Values[i] = ec.___Field_type(ctx, field, obj) case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(field, obj) + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(field, obj) + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -569,12 +551,12 @@ func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.F return out } -func (ec *executionContext) ___Field_name(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___Field_description(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -582,7 +564,7 @@ func (ec *executionContext) ___Field_description(field graphql.CollectedField, o return graphql.MarshalString(*res) } -func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Args() arr1 := graphql.Array{} for idx1 := range res { @@ -590,26 +572,26 @@ func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *int if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Field_type(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Type() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Field_isDeprecated(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.IsDeprecated() return graphql.MarshalBoolean(res) } -func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.DeprecationReason() if res == nil { return graphql.Null @@ -620,8 +602,8 @@ func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedFi var __InputValueImplementors = []string{"__InputValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __InputValueImplementors, ec.variables) +func (ec *executionContext) ___InputValue(ctx context.Context, sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __InputValueImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -630,13 +612,13 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspect case "__typename": out.Values[i] = graphql.MarshalString("__InputValue") case "name": - out.Values[i] = ec.___InputValue_name(field, obj) + out.Values[i] = ec.___InputValue_name(ctx, field, obj) case "description": - out.Values[i] = ec.___InputValue_description(field, obj) + out.Values[i] = ec.___InputValue_description(ctx, field, obj) case "type": - out.Values[i] = ec.___InputValue_type(field, obj) + out.Values[i] = ec.___InputValue_type(ctx, field, obj) case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(field, obj) + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -645,12 +627,12 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspect return out } -func (ec *executionContext) ___InputValue_name(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___InputValue_description(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -658,15 +640,15 @@ func (ec *executionContext) ___InputValue_description(field graphql.CollectedFie return graphql.MarshalString(*res) } -func (ec *executionContext) ___InputValue_type(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Type() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.DefaultValue() if res == nil { return graphql.Null @@ -677,8 +659,8 @@ func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedFi var __SchemaImplementors = []string{"__Schema"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __SchemaImplementors, ec.variables) +func (ec *executionContext) ___Schema(ctx context.Context, sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __SchemaImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -687,15 +669,15 @@ func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection. case "__typename": out.Values[i] = graphql.MarshalString("__Schema") case "types": - out.Values[i] = ec.___Schema_types(field, obj) + out.Values[i] = ec.___Schema_types(ctx, field, obj) case "queryType": - out.Values[i] = ec.___Schema_queryType(field, obj) + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) case "mutationType": - out.Values[i] = ec.___Schema_mutationType(field, obj) + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(field, obj) + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) case "directives": - out.Values[i] = ec.___Schema_directives(field, obj) + out.Values[i] = ec.___Schema_directives(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -704,7 +686,7 @@ func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection. return out } -func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.Types() arr1 := graphql.Array{} for idx1 := range res { @@ -712,37 +694,37 @@ func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *i if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Schema_queryType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.QueryType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_mutationType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.MutationType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_subscriptionType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.SubscriptionType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.Directives() arr1 := graphql.Array{} for idx1 := range res { @@ -750,7 +732,7 @@ func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, o if res[idx1] == nil { return graphql.Null } - return ec.___Directive(field.Selections, res[idx1]) + return ec.___Directive(ctx, field.Selections, res[idx1]) }()) } return arr1 @@ -759,8 +741,8 @@ func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, o var __TypeImplementors = []string{"__Type"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __TypeImplementors, ec.variables) +func (ec *executionContext) ___Type(ctx context.Context, sel []query.Selection, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __TypeImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -769,23 +751,23 @@ func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Ty case "__typename": out.Values[i] = graphql.MarshalString("__Type") case "kind": - out.Values[i] = ec.___Type_kind(field, obj) + out.Values[i] = ec.___Type_kind(ctx, field, obj) case "name": - out.Values[i] = ec.___Type_name(field, obj) + out.Values[i] = ec.___Type_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Type_description(field, obj) + out.Values[i] = ec.___Type_description(ctx, field, obj) case "fields": - out.Values[i] = ec.___Type_fields(field, obj) + out.Values[i] = ec.___Type_fields(ctx, field, obj) case "interfaces": - out.Values[i] = ec.___Type_interfaces(field, obj) + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(field, obj) + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) case "enumValues": - out.Values[i] = ec.___Type_enumValues(field, obj) + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) case "inputFields": - out.Values[i] = ec.___Type_inputFields(field, obj) + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) case "ofType": - out.Values[i] = ec.___Type_ofType(field, obj) + out.Values[i] = ec.___Type_ofType(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -794,12 +776,12 @@ func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Ty return out } -func (ec *executionContext) ___Type_kind(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Kind() return graphql.MarshalString(res) } -func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Name() if res == nil { return graphql.Null @@ -807,7 +789,7 @@ func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *intr return graphql.MarshalString(*res) } -func (ec *executionContext) ___Type_description(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -815,7 +797,7 @@ func (ec *executionContext) ___Type_description(field graphql.CollectedField, ob return graphql.MarshalString(*res) } -func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -832,13 +814,13 @@ func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *in if res[idx1] == nil { return graphql.Null } - return ec.___Field(field.Selections, res[idx1]) + return ec.___Field(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Interfaces() arr1 := graphql.Array{} for idx1 := range res { @@ -846,13 +828,13 @@ func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.PossibleTypes() arr1 := graphql.Array{} for idx1 := range res { @@ -860,13 +842,13 @@ func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -883,13 +865,13 @@ func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___EnumValue(field.Selections, res[idx1]) + return ec.___EnumValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.InputFields() arr1 := graphql.Array{} for idx1 := range res { @@ -897,18 +879,18 @@ func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, ob if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_ofType(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.OfType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } var parsedSchema = schema.MustParse("type Query {\n customers: [Customer!]\n\n # this method is here to test code generation of nested arrays\n torture(customerIds: [[Int]]): [[Customer!]]\n}\n\ntype Customer {\n id: Int!\n name: String!\n address: Address\n orders: [Order!]\n}\n\ntype Address {\n id: Int!\n street: String!\n country: String!\n}\n\ntype Order {\n id: Int!\n date: Time!\n amount: Float!\n items: [Item!]\n}\n\ntype Item {\n name: String!\n}\nscalar Time\n") diff --git a/example/scalars/generated.go b/example/scalars/generated.go index 353924ba12..f46947f100 100644 --- a/example/scalars/generated.go +++ b/example/scalars/generated.go @@ -16,12 +16,8 @@ import ( schema "github.com/vektah/gqlgen/neelance/schema" ) -func MakeExecutableSchema(resolvers Resolvers, opts ...ExecutableOption) graphql.ExecutableSchema { - ret := &executableSchema{resolvers: resolvers} - for _, opt := range opts { - opt(ret) - } - return ret +func MakeExecutableSchema(resolvers Resolvers) graphql.ExecutableSchema { + return &executableSchema{resolvers: resolvers} } type Resolvers interface { @@ -32,27 +28,18 @@ type Resolvers interface { User_customResolver(ctx context.Context, obj *User) (Point, error) } -type ExecutableOption func(*executableSchema) - -func WithErrorConverter(fn func(error) string) ExecutableOption { - return func(s *executableSchema) { - s.errorMessageFn = fn - } -} - type executableSchema struct { - resolvers Resolvers - errorMessageFn func(error) string + resolvers Resolvers } func (e *executableSchema) Schema() *schema.Schema { return parsedSchema } -func (e *executableSchema) Query(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { - ec := e.makeExecutionContext(ctx, doc, variables, recover) +func (e *executableSchema) Query(ctx context.Context, op *query.Operation) *graphql.Response { + ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers} - data := ec._Query(op.Selections) + data := ec._Query(ctx, op.Selections) var buf bytes.Buffer data.MarshalGQL(&buf) @@ -62,35 +49,25 @@ func (e *executableSchema) Query(ctx context.Context, doc *query.Document, varia } } -func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { +func (e *executableSchema) Mutation(ctx context.Context, op *query.Operation) *graphql.Response { return &graphql.Response{Errors: []*errors.QueryError{{Message: "mutations are not supported"}}} } -func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) func() *graphql.Response { +func (e *executableSchema) Subscription(ctx context.Context, op *query.Operation) func() *graphql.Response { return graphql.OneShot(&graphql.Response{Errors: []*errors.QueryError{{Message: "subscriptions are not supported"}}}) } -func (e *executableSchema) makeExecutionContext(ctx context.Context, doc *query.Document, variables map[string]interface{}, recover graphql.RecoverFunc) *executionContext { - errBuilder := errors.Builder{ErrorMessageFn: e.errorMessageFn} - return &executionContext{ - Builder: errBuilder, resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx, recover: recover, - } -} - type executionContext struct { - errors.Builder + *graphql.RequestContext + resolvers Resolvers - variables map[string]interface{} - doc *query.Document - ctx context.Context - recover graphql.RecoverFunc } var addressImplementors = []string{"Address"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Address(sel []query.Selection, obj *Address) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, addressImplementors, ec.variables) +func (ec *executionContext) _Address(ctx context.Context, sel []query.Selection, obj *Address) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, addressImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -99,9 +76,9 @@ func (ec *executionContext) _Address(sel []query.Selection, obj *Address) graphq case "__typename": out.Values[i] = graphql.MarshalString("Address") case "id": - out.Values[i] = ec._Address_id(field, obj) + out.Values[i] = ec._Address_id(ctx, field, obj) case "location": - out.Values[i] = ec._Address_location(field, obj) + out.Values[i] = ec._Address_location(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -110,12 +87,12 @@ func (ec *executionContext) _Address(sel []query.Selection, obj *Address) graphq return out } -func (ec *executionContext) _Address_id(field graphql.CollectedField, obj *Address) graphql.Marshaler { +func (ec *executionContext) _Address_id(ctx context.Context, field graphql.CollectedField, obj *Address) graphql.Marshaler { res := obj.ID return MarshalID(res) } -func (ec *executionContext) _Address_location(field graphql.CollectedField, obj *Address) graphql.Marshaler { +func (ec *executionContext) _Address_location(ctx context.Context, field graphql.CollectedField, obj *Address) graphql.Marshaler { res := obj.Location if res == nil { return graphql.Null @@ -126,8 +103,8 @@ func (ec *executionContext) _Address_location(field graphql.CollectedField, obj var queryImplementors = []string{"Query"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, queryImplementors, ec.variables) +func (ec *executionContext) _Query(ctx context.Context, sel []query.Selection) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, queryImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -136,13 +113,13 @@ func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { case "__typename": out.Values[i] = graphql.MarshalString("Query") case "user": - out.Values[i] = ec._Query_user(field) + out.Values[i] = ec._Query_user(ctx, field) case "search": - out.Values[i] = ec._Query_search(field) + out.Values[i] = ec._Query_search(ctx, field) case "__schema": - out.Values[i] = ec._Query___schema(field) + out.Values[i] = ec._Query___schema(ctx, field) case "__type": - out.Values[i] = ec._Query___type(field) + out.Values[i] = ec._Query___type(ctx, field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -151,7 +128,7 @@ func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { return out } -func (ec *executionContext) _Query_user(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_user(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 external.ObjectID if tmp, ok := field.Args["id"]; ok { var err error @@ -164,12 +141,13 @@ func (ec *executionContext) _Query_user(field graphql.CollectedField) graphql.Ma return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_user(ec.ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_user(rctx, arg0) if err != nil { ec.Error(err) return graphql.Null @@ -177,11 +155,11 @@ func (ec *executionContext) _Query_user(field graphql.CollectedField) graphql.Ma if res == nil { return graphql.Null } - return ec._User(field.Selections, res) + return ec._User(ctx, field.Selections, res) }) } -func (ec *executionContext) _Query_search(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_search(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 SearchArgs if tmp, ok := field.Args["input"]; ok { var err error @@ -203,33 +181,34 @@ func (ec *executionContext) _Query_search(field graphql.CollectedField) graphql. return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_search(ec.ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_search(rctx, arg0) if err != nil { ec.Error(err) return graphql.Null } arr1 := graphql.Array{} for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { return ec._User(field.Selections, &res[idx1]) }()) + arr1 = append(arr1, func() graphql.Marshaler { return ec._User(ctx, field.Selections, &res[idx1]) }()) } return arr1 }) } -func (ec *executionContext) _Query___schema(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { res := ec.introspectSchema() if res == nil { return graphql.Null } - return ec.___Schema(field.Selections, res) + return ec.___Schema(ctx, field.Selections, res) } -func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["name"]; ok { var err error @@ -243,14 +222,14 @@ func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql. if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } var userImplementors = []string{"User"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _User(sel []query.Selection, obj *User) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, userImplementors, ec.variables) +func (ec *executionContext) _User(ctx context.Context, sel []query.Selection, obj *User) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, userImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -259,19 +238,19 @@ func (ec *executionContext) _User(sel []query.Selection, obj *User) graphql.Mars case "__typename": out.Values[i] = graphql.MarshalString("User") case "id": - out.Values[i] = ec._User_id(field, obj) + out.Values[i] = ec._User_id(ctx, field, obj) case "name": - out.Values[i] = ec._User_name(field, obj) + out.Values[i] = ec._User_name(ctx, field, obj) case "created": - out.Values[i] = ec._User_created(field, obj) + out.Values[i] = ec._User_created(ctx, field, obj) case "isBanned": - out.Values[i] = ec._User_isBanned(field, obj) + out.Values[i] = ec._User_isBanned(ctx, field, obj) case "primitiveResolver": - out.Values[i] = ec._User_primitiveResolver(field, obj) + out.Values[i] = ec._User_primitiveResolver(ctx, field, obj) case "customResolver": - out.Values[i] = ec._User_customResolver(field, obj) + out.Values[i] = ec._User_customResolver(ctx, field, obj) case "address": - out.Values[i] = ec._User_address(field, obj) + out.Values[i] = ec._User_address(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -280,36 +259,37 @@ func (ec *executionContext) _User(sel []query.Selection, obj *User) graphql.Mars return out } -func (ec *executionContext) _User_id(field graphql.CollectedField, obj *User) graphql.Marshaler { +func (ec *executionContext) _User_id(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { res := obj.ID return MarshalID(res) } -func (ec *executionContext) _User_name(field graphql.CollectedField, obj *User) graphql.Marshaler { +func (ec *executionContext) _User_name(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { res := obj.Name return graphql.MarshalString(res) } -func (ec *executionContext) _User_created(field graphql.CollectedField, obj *User) graphql.Marshaler { +func (ec *executionContext) _User_created(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { res := obj.Created return MarshalTimestamp(res) } -func (ec *executionContext) _User_isBanned(field graphql.CollectedField, obj *User) graphql.Marshaler { +func (ec *executionContext) _User_isBanned(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { res := obj.IsBanned return graphql.MarshalBoolean(bool(res)) } -func (ec *executionContext) _User_primitiveResolver(field graphql.CollectedField, obj *User) graphql.Marshaler { +func (ec *executionContext) _User_primitiveResolver(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.User_primitiveResolver(ec.ctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.User_primitiveResolver(rctx, obj) if err != nil { ec.Error(err) return graphql.Null @@ -318,16 +298,17 @@ func (ec *executionContext) _User_primitiveResolver(field graphql.CollectedField }) } -func (ec *executionContext) _User_customResolver(field graphql.CollectedField, obj *User) graphql.Marshaler { +func (ec *executionContext) _User_customResolver(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.User_customResolver(ec.ctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.User_customResolver(rctx, obj) if err != nil { ec.Error(err) return graphql.Null @@ -336,16 +317,16 @@ func (ec *executionContext) _User_customResolver(field graphql.CollectedField, o }) } -func (ec *executionContext) _User_address(field graphql.CollectedField, obj *User) graphql.Marshaler { +func (ec *executionContext) _User_address(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { res := obj.Address - return ec._Address(field.Selections, &res) + return ec._Address(ctx, field.Selections, &res) } var __DirectiveImplementors = []string{"__Directive"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __DirectiveImplementors, ec.variables) +func (ec *executionContext) ___Directive(ctx context.Context, sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __DirectiveImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -354,13 +335,13 @@ func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspecti case "__typename": out.Values[i] = graphql.MarshalString("__Directive") case "name": - out.Values[i] = ec.___Directive_name(field, obj) + out.Values[i] = ec.___Directive_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Directive_description(field, obj) + out.Values[i] = ec.___Directive_description(ctx, field, obj) case "locations": - out.Values[i] = ec.___Directive_locations(field, obj) + out.Values[i] = ec.___Directive_locations(ctx, field, obj) case "args": - out.Values[i] = ec.___Directive_args(field, obj) + out.Values[i] = ec.___Directive_args(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -369,12 +350,12 @@ func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspecti return out } -func (ec *executionContext) ___Directive_name(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___Directive_description(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -382,7 +363,7 @@ func (ec *executionContext) ___Directive_description(field graphql.CollectedFiel return graphql.MarshalString(*res) } -func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Locations() arr1 := graphql.Array{} for idx1 := range res { @@ -391,7 +372,7 @@ func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, return arr1 } -func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Args() arr1 := graphql.Array{} for idx1 := range res { @@ -399,7 +380,7 @@ func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 @@ -408,8 +389,8 @@ func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj var __EnumValueImplementors = []string{"__EnumValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __EnumValueImplementors, ec.variables) +func (ec *executionContext) ___EnumValue(ctx context.Context, sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __EnumValueImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -418,13 +399,13 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspecti case "__typename": out.Values[i] = graphql.MarshalString("__EnumValue") case "name": - out.Values[i] = ec.___EnumValue_name(field, obj) + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) case "description": - out.Values[i] = ec.___EnumValue_description(field, obj) + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(field, obj) + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(field, obj) + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -433,12 +414,12 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspecti return out } -func (ec *executionContext) ___EnumValue_name(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___EnumValue_description(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -446,12 +427,12 @@ func (ec *executionContext) ___EnumValue_description(field graphql.CollectedFiel return graphql.MarshalString(*res) } -func (ec *executionContext) ___EnumValue_isDeprecated(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.IsDeprecated() return graphql.MarshalBoolean(res) } -func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.DeprecationReason() if res == nil { return graphql.Null @@ -462,8 +443,8 @@ func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.Collect var __FieldImplementors = []string{"__Field"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __FieldImplementors, ec.variables) +func (ec *executionContext) ___Field(ctx context.Context, sel []query.Selection, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __FieldImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -472,17 +453,17 @@ func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.F case "__typename": out.Values[i] = graphql.MarshalString("__Field") case "name": - out.Values[i] = ec.___Field_name(field, obj) + out.Values[i] = ec.___Field_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Field_description(field, obj) + out.Values[i] = ec.___Field_description(ctx, field, obj) case "args": - out.Values[i] = ec.___Field_args(field, obj) + out.Values[i] = ec.___Field_args(ctx, field, obj) case "type": - out.Values[i] = ec.___Field_type(field, obj) + out.Values[i] = ec.___Field_type(ctx, field, obj) case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(field, obj) + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(field, obj) + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -491,12 +472,12 @@ func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.F return out } -func (ec *executionContext) ___Field_name(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___Field_description(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -504,7 +485,7 @@ func (ec *executionContext) ___Field_description(field graphql.CollectedField, o return graphql.MarshalString(*res) } -func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Args() arr1 := graphql.Array{} for idx1 := range res { @@ -512,26 +493,26 @@ func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *int if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Field_type(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Type() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Field_isDeprecated(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.IsDeprecated() return graphql.MarshalBoolean(res) } -func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.DeprecationReason() if res == nil { return graphql.Null @@ -542,8 +523,8 @@ func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedFi var __InputValueImplementors = []string{"__InputValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __InputValueImplementors, ec.variables) +func (ec *executionContext) ___InputValue(ctx context.Context, sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __InputValueImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -552,13 +533,13 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspect case "__typename": out.Values[i] = graphql.MarshalString("__InputValue") case "name": - out.Values[i] = ec.___InputValue_name(field, obj) + out.Values[i] = ec.___InputValue_name(ctx, field, obj) case "description": - out.Values[i] = ec.___InputValue_description(field, obj) + out.Values[i] = ec.___InputValue_description(ctx, field, obj) case "type": - out.Values[i] = ec.___InputValue_type(field, obj) + out.Values[i] = ec.___InputValue_type(ctx, field, obj) case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(field, obj) + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -567,12 +548,12 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspect return out } -func (ec *executionContext) ___InputValue_name(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___InputValue_description(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -580,15 +561,15 @@ func (ec *executionContext) ___InputValue_description(field graphql.CollectedFie return graphql.MarshalString(*res) } -func (ec *executionContext) ___InputValue_type(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Type() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.DefaultValue() if res == nil { return graphql.Null @@ -599,8 +580,8 @@ func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedFi var __SchemaImplementors = []string{"__Schema"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __SchemaImplementors, ec.variables) +func (ec *executionContext) ___Schema(ctx context.Context, sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __SchemaImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -609,15 +590,15 @@ func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection. case "__typename": out.Values[i] = graphql.MarshalString("__Schema") case "types": - out.Values[i] = ec.___Schema_types(field, obj) + out.Values[i] = ec.___Schema_types(ctx, field, obj) case "queryType": - out.Values[i] = ec.___Schema_queryType(field, obj) + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) case "mutationType": - out.Values[i] = ec.___Schema_mutationType(field, obj) + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(field, obj) + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) case "directives": - out.Values[i] = ec.___Schema_directives(field, obj) + out.Values[i] = ec.___Schema_directives(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -626,7 +607,7 @@ func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection. return out } -func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.Types() arr1 := graphql.Array{} for idx1 := range res { @@ -634,37 +615,37 @@ func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *i if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Schema_queryType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.QueryType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_mutationType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.MutationType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_subscriptionType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.SubscriptionType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.Directives() arr1 := graphql.Array{} for idx1 := range res { @@ -672,7 +653,7 @@ func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, o if res[idx1] == nil { return graphql.Null } - return ec.___Directive(field.Selections, res[idx1]) + return ec.___Directive(ctx, field.Selections, res[idx1]) }()) } return arr1 @@ -681,8 +662,8 @@ func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, o var __TypeImplementors = []string{"__Type"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __TypeImplementors, ec.variables) +func (ec *executionContext) ___Type(ctx context.Context, sel []query.Selection, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __TypeImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -691,23 +672,23 @@ func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Ty case "__typename": out.Values[i] = graphql.MarshalString("__Type") case "kind": - out.Values[i] = ec.___Type_kind(field, obj) + out.Values[i] = ec.___Type_kind(ctx, field, obj) case "name": - out.Values[i] = ec.___Type_name(field, obj) + out.Values[i] = ec.___Type_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Type_description(field, obj) + out.Values[i] = ec.___Type_description(ctx, field, obj) case "fields": - out.Values[i] = ec.___Type_fields(field, obj) + out.Values[i] = ec.___Type_fields(ctx, field, obj) case "interfaces": - out.Values[i] = ec.___Type_interfaces(field, obj) + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(field, obj) + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) case "enumValues": - out.Values[i] = ec.___Type_enumValues(field, obj) + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) case "inputFields": - out.Values[i] = ec.___Type_inputFields(field, obj) + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) case "ofType": - out.Values[i] = ec.___Type_ofType(field, obj) + out.Values[i] = ec.___Type_ofType(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -716,12 +697,12 @@ func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Ty return out } -func (ec *executionContext) ___Type_kind(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Kind() return graphql.MarshalString(res) } -func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Name() if res == nil { return graphql.Null @@ -729,7 +710,7 @@ func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *intr return graphql.MarshalString(*res) } -func (ec *executionContext) ___Type_description(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -737,7 +718,7 @@ func (ec *executionContext) ___Type_description(field graphql.CollectedField, ob return graphql.MarshalString(*res) } -func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -754,13 +735,13 @@ func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *in if res[idx1] == nil { return graphql.Null } - return ec.___Field(field.Selections, res[idx1]) + return ec.___Field(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Interfaces() arr1 := graphql.Array{} for idx1 := range res { @@ -768,13 +749,13 @@ func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.PossibleTypes() arr1 := graphql.Array{} for idx1 := range res { @@ -782,13 +763,13 @@ func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -805,13 +786,13 @@ func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___EnumValue(field.Selections, res[idx1]) + return ec.___EnumValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.InputFields() arr1 := graphql.Array{} for idx1 := range res { @@ -819,18 +800,18 @@ func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, ob if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_ofType(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.OfType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } func UnmarshalSearchArgs(v interface{}) (SearchArgs, error) { diff --git a/example/starwars/generated.go b/example/starwars/generated.go index 53b502249f..57337edd34 100644 --- a/example/starwars/generated.go +++ b/example/starwars/generated.go @@ -16,12 +16,8 @@ import ( schema "github.com/vektah/gqlgen/neelance/schema" ) -func MakeExecutableSchema(resolvers Resolvers, opts ...ExecutableOption) graphql.ExecutableSchema { - ret := &executableSchema{resolvers: resolvers} - for _, opt := range opts { - opt(ret) - } - return ret +func MakeExecutableSchema(resolvers Resolvers) graphql.ExecutableSchema { + return &executableSchema{resolvers: resolvers} } type Resolvers interface { @@ -46,27 +42,18 @@ type Resolvers interface { Query_starship(ctx context.Context, id string) (*Starship, error) } -type ExecutableOption func(*executableSchema) - -func WithErrorConverter(fn func(error) string) ExecutableOption { - return func(s *executableSchema) { - s.errorMessageFn = fn - } -} - type executableSchema struct { - resolvers Resolvers - errorMessageFn func(error) string + resolvers Resolvers } func (e *executableSchema) Schema() *schema.Schema { return parsedSchema } -func (e *executableSchema) Query(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { - ec := e.makeExecutionContext(ctx, doc, variables, recover) +func (e *executableSchema) Query(ctx context.Context, op *query.Operation) *graphql.Response { + ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers} - data := ec._Query(op.Selections) + data := ec._Query(ctx, op.Selections) var buf bytes.Buffer data.MarshalGQL(&buf) @@ -76,10 +63,10 @@ func (e *executableSchema) Query(ctx context.Context, doc *query.Document, varia } } -func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { - ec := e.makeExecutionContext(ctx, doc, variables, recover) +func (e *executableSchema) Mutation(ctx context.Context, op *query.Operation) *graphql.Response { + ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers} - data := ec._Mutation(op.Selections) + data := ec._Mutation(ctx, op.Selections) var buf bytes.Buffer data.MarshalGQL(&buf) @@ -89,31 +76,21 @@ func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, va } } -func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) func() *graphql.Response { +func (e *executableSchema) Subscription(ctx context.Context, op *query.Operation) func() *graphql.Response { return graphql.OneShot(&graphql.Response{Errors: []*errors.QueryError{{Message: "subscriptions are not supported"}}}) } -func (e *executableSchema) makeExecutionContext(ctx context.Context, doc *query.Document, variables map[string]interface{}, recover graphql.RecoverFunc) *executionContext { - errBuilder := errors.Builder{ErrorMessageFn: e.errorMessageFn} - return &executionContext{ - Builder: errBuilder, resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx, recover: recover, - } -} - type executionContext struct { - errors.Builder + *graphql.RequestContext + resolvers Resolvers - variables map[string]interface{} - doc *query.Document - ctx context.Context - recover graphql.RecoverFunc } var droidImplementors = []string{"Droid", "Character"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Droid(sel []query.Selection, obj *Droid) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, droidImplementors, ec.variables) +func (ec *executionContext) _Droid(ctx context.Context, sel []query.Selection, obj *Droid) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, droidImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -122,17 +99,17 @@ func (ec *executionContext) _Droid(sel []query.Selection, obj *Droid) graphql.Ma case "__typename": out.Values[i] = graphql.MarshalString("Droid") case "id": - out.Values[i] = ec._Droid_id(field, obj) + out.Values[i] = ec._Droid_id(ctx, field, obj) case "name": - out.Values[i] = ec._Droid_name(field, obj) + out.Values[i] = ec._Droid_name(ctx, field, obj) case "friends": - out.Values[i] = ec._Droid_friends(field, obj) + out.Values[i] = ec._Droid_friends(ctx, field, obj) case "friendsConnection": - out.Values[i] = ec._Droid_friendsConnection(field, obj) + out.Values[i] = ec._Droid_friendsConnection(ctx, field, obj) case "appearsIn": - out.Values[i] = ec._Droid_appearsIn(field, obj) + out.Values[i] = ec._Droid_appearsIn(ctx, field, obj) case "primaryFunction": - out.Values[i] = ec._Droid_primaryFunction(field, obj) + out.Values[i] = ec._Droid_primaryFunction(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -141,39 +118,40 @@ func (ec *executionContext) _Droid(sel []query.Selection, obj *Droid) graphql.Ma return out } -func (ec *executionContext) _Droid_id(field graphql.CollectedField, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Droid_id(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { res := obj.ID return graphql.MarshalID(res) } -func (ec *executionContext) _Droid_name(field graphql.CollectedField, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Droid_name(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { res := obj.Name return graphql.MarshalString(res) } -func (ec *executionContext) _Droid_friends(field graphql.CollectedField, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Droid_friends(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Droid_friends(ec.ctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Droid_friends(rctx, obj) if err != nil { ec.Error(err) return graphql.Null } arr1 := graphql.Array{} for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { return ec._Character(field.Selections, &res[idx1]) }()) + arr1 = append(arr1, func() graphql.Marshaler { return ec._Character(ctx, field.Selections, &res[idx1]) }()) } return arr1 }) } -func (ec *executionContext) _Droid_friendsConnection(field graphql.CollectedField, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Droid_friendsConnection(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { var arg0 *int if tmp, ok := field.Args["first"]; ok { var err error @@ -205,21 +183,22 @@ func (ec *executionContext) _Droid_friendsConnection(field graphql.CollectedFiel return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Droid_friendsConnection(ec.ctx, obj, arg0, arg1) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Droid_friendsConnection(rctx, obj, arg0, arg1) if err != nil { ec.Error(err) return graphql.Null } - return ec._FriendsConnection(field.Selections, &res) + return ec._FriendsConnection(ctx, field.Selections, &res) }) } -func (ec *executionContext) _Droid_appearsIn(field graphql.CollectedField, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Droid_appearsIn(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { res := obj.AppearsIn arr1 := graphql.Array{} for idx1 := range res { @@ -228,7 +207,7 @@ func (ec *executionContext) _Droid_appearsIn(field graphql.CollectedField, obj * return arr1 } -func (ec *executionContext) _Droid_primaryFunction(field graphql.CollectedField, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Droid_primaryFunction(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { res := obj.PrimaryFunction return graphql.MarshalString(res) } @@ -236,8 +215,8 @@ func (ec *executionContext) _Droid_primaryFunction(field graphql.CollectedField, var friendsConnectionImplementors = []string{"FriendsConnection"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _FriendsConnection(sel []query.Selection, obj *FriendsConnection) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, friendsConnectionImplementors, ec.variables) +func (ec *executionContext) _FriendsConnection(ctx context.Context, sel []query.Selection, obj *FriendsConnection) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, friendsConnectionImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -246,13 +225,13 @@ func (ec *executionContext) _FriendsConnection(sel []query.Selection, obj *Frien case "__typename": out.Values[i] = graphql.MarshalString("FriendsConnection") case "totalCount": - out.Values[i] = ec._FriendsConnection_totalCount(field, obj) + out.Values[i] = ec._FriendsConnection_totalCount(ctx, field, obj) case "edges": - out.Values[i] = ec._FriendsConnection_edges(field, obj) + out.Values[i] = ec._FriendsConnection_edges(ctx, field, obj) case "friends": - out.Values[i] = ec._FriendsConnection_friends(field, obj) + out.Values[i] = ec._FriendsConnection_friends(ctx, field, obj) case "pageInfo": - out.Values[i] = ec._FriendsConnection_pageInfo(field, obj) + out.Values[i] = ec._FriendsConnection_pageInfo(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -261,65 +240,67 @@ func (ec *executionContext) _FriendsConnection(sel []query.Selection, obj *Frien return out } -func (ec *executionContext) _FriendsConnection_totalCount(field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { +func (ec *executionContext) _FriendsConnection_totalCount(ctx context.Context, field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { res := obj.TotalCount() return graphql.MarshalInt(res) } -func (ec *executionContext) _FriendsConnection_edges(field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { +func (ec *executionContext) _FriendsConnection_edges(ctx context.Context, field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.FriendsConnection_edges(ec.ctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.FriendsConnection_edges(rctx, obj) if err != nil { ec.Error(err) return graphql.Null } arr1 := graphql.Array{} for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { return ec._FriendsEdge(field.Selections, &res[idx1]) }()) + arr1 = append(arr1, func() graphql.Marshaler { return ec._FriendsEdge(ctx, field.Selections, &res[idx1]) }()) } return arr1 }) } -func (ec *executionContext) _FriendsConnection_friends(field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { +func (ec *executionContext) _FriendsConnection_friends(ctx context.Context, field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.FriendsConnection_friends(ec.ctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.FriendsConnection_friends(rctx, obj) if err != nil { ec.Error(err) return graphql.Null } arr1 := graphql.Array{} for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { return ec._Character(field.Selections, &res[idx1]) }()) + arr1 = append(arr1, func() graphql.Marshaler { return ec._Character(ctx, field.Selections, &res[idx1]) }()) } return arr1 }) } -func (ec *executionContext) _FriendsConnection_pageInfo(field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { +func (ec *executionContext) _FriendsConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { res := obj.PageInfo() - return ec._PageInfo(field.Selections, &res) + return ec._PageInfo(ctx, field.Selections, &res) } var friendsEdgeImplementors = []string{"FriendsEdge"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _FriendsEdge(sel []query.Selection, obj *FriendsEdge) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, friendsEdgeImplementors, ec.variables) +func (ec *executionContext) _FriendsEdge(ctx context.Context, sel []query.Selection, obj *FriendsEdge) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, friendsEdgeImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -328,9 +309,9 @@ func (ec *executionContext) _FriendsEdge(sel []query.Selection, obj *FriendsEdge case "__typename": out.Values[i] = graphql.MarshalString("FriendsEdge") case "cursor": - out.Values[i] = ec._FriendsEdge_cursor(field, obj) + out.Values[i] = ec._FriendsEdge_cursor(ctx, field, obj) case "node": - out.Values[i] = ec._FriendsEdge_node(field, obj) + out.Values[i] = ec._FriendsEdge_node(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -339,21 +320,21 @@ func (ec *executionContext) _FriendsEdge(sel []query.Selection, obj *FriendsEdge return out } -func (ec *executionContext) _FriendsEdge_cursor(field graphql.CollectedField, obj *FriendsEdge) graphql.Marshaler { +func (ec *executionContext) _FriendsEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *FriendsEdge) graphql.Marshaler { res := obj.Cursor return graphql.MarshalID(res) } -func (ec *executionContext) _FriendsEdge_node(field graphql.CollectedField, obj *FriendsEdge) graphql.Marshaler { +func (ec *executionContext) _FriendsEdge_node(ctx context.Context, field graphql.CollectedField, obj *FriendsEdge) graphql.Marshaler { res := obj.Node - return ec._Character(field.Selections, &res) + return ec._Character(ctx, field.Selections, &res) } var humanImplementors = []string{"Human", "Character"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Human(sel []query.Selection, obj *Human) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, humanImplementors, ec.variables) +func (ec *executionContext) _Human(ctx context.Context, sel []query.Selection, obj *Human) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, humanImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -362,21 +343,21 @@ func (ec *executionContext) _Human(sel []query.Selection, obj *Human) graphql.Ma case "__typename": out.Values[i] = graphql.MarshalString("Human") case "id": - out.Values[i] = ec._Human_id(field, obj) + out.Values[i] = ec._Human_id(ctx, field, obj) case "name": - out.Values[i] = ec._Human_name(field, obj) + out.Values[i] = ec._Human_name(ctx, field, obj) case "height": - out.Values[i] = ec._Human_height(field, obj) + out.Values[i] = ec._Human_height(ctx, field, obj) case "mass": - out.Values[i] = ec._Human_mass(field, obj) + out.Values[i] = ec._Human_mass(ctx, field, obj) case "friends": - out.Values[i] = ec._Human_friends(field, obj) + out.Values[i] = ec._Human_friends(ctx, field, obj) case "friendsConnection": - out.Values[i] = ec._Human_friendsConnection(field, obj) + out.Values[i] = ec._Human_friendsConnection(ctx, field, obj) case "appearsIn": - out.Values[i] = ec._Human_appearsIn(field, obj) + out.Values[i] = ec._Human_appearsIn(ctx, field, obj) case "starships": - out.Values[i] = ec._Human_starships(field, obj) + out.Values[i] = ec._Human_starships(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -385,17 +366,17 @@ func (ec *executionContext) _Human(sel []query.Selection, obj *Human) graphql.Ma return out } -func (ec *executionContext) _Human_id(field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_id(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { res := obj.ID return graphql.MarshalID(res) } -func (ec *executionContext) _Human_name(field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_name(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { res := obj.Name return graphql.MarshalString(res) } -func (ec *executionContext) _Human_height(field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_height(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["unit"]; ok { var err error @@ -418,34 +399,35 @@ func (ec *executionContext) _Human_height(field graphql.CollectedField, obj *Hum return graphql.MarshalFloat(res) } -func (ec *executionContext) _Human_mass(field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_mass(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { res := obj.Mass return graphql.MarshalFloat(res) } -func (ec *executionContext) _Human_friends(field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_friends(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Human_friends(ec.ctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Human_friends(rctx, obj) if err != nil { ec.Error(err) return graphql.Null } arr1 := graphql.Array{} for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { return ec._Character(field.Selections, &res[idx1]) }()) + arr1 = append(arr1, func() graphql.Marshaler { return ec._Character(ctx, field.Selections, &res[idx1]) }()) } return arr1 }) } -func (ec *executionContext) _Human_friendsConnection(field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_friendsConnection(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { var arg0 *int if tmp, ok := field.Args["first"]; ok { var err error @@ -477,21 +459,22 @@ func (ec *executionContext) _Human_friendsConnection(field graphql.CollectedFiel return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Human_friendsConnection(ec.ctx, obj, arg0, arg1) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Human_friendsConnection(rctx, obj, arg0, arg1) if err != nil { ec.Error(err) return graphql.Null } - return ec._FriendsConnection(field.Selections, &res) + return ec._FriendsConnection(ctx, field.Selections, &res) }) } -func (ec *executionContext) _Human_appearsIn(field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_appearsIn(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { res := obj.AppearsIn arr1 := graphql.Array{} for idx1 := range res { @@ -500,23 +483,24 @@ func (ec *executionContext) _Human_appearsIn(field graphql.CollectedField, obj * return arr1 } -func (ec *executionContext) _Human_starships(field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_starships(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Human_starships(ec.ctx, obj) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Human_starships(rctx, obj) if err != nil { ec.Error(err) return graphql.Null } arr1 := graphql.Array{} for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { return ec._Starship(field.Selections, &res[idx1]) }()) + arr1 = append(arr1, func() graphql.Marshaler { return ec._Starship(ctx, field.Selections, &res[idx1]) }()) } return arr1 }) @@ -525,8 +509,8 @@ func (ec *executionContext) _Human_starships(field graphql.CollectedField, obj * var mutationImplementors = []string{"Mutation"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Mutation(sel []query.Selection) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, mutationImplementors, ec.variables) +func (ec *executionContext) _Mutation(ctx context.Context, sel []query.Selection) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, mutationImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -535,7 +519,7 @@ func (ec *executionContext) _Mutation(sel []query.Selection) graphql.Marshaler { case "__typename": out.Values[i] = graphql.MarshalString("Mutation") case "createReview": - out.Values[i] = ec._Mutation_createReview(field) + out.Values[i] = ec._Mutation_createReview(ctx, field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -544,7 +528,7 @@ func (ec *executionContext) _Mutation(sel []query.Selection) graphql.Marshaler { return out } -func (ec *executionContext) _Mutation_createReview(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Mutation_createReview(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["episode"]; ok { var err error @@ -563,7 +547,8 @@ func (ec *executionContext) _Mutation_createReview(field graphql.CollectedField) return graphql.Null } } - res, err := ec.resolvers.Mutation_createReview(ec.ctx, arg0, arg1) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Mutation_createReview(rctx, arg0, arg1) if err != nil { ec.Error(err) return graphql.Null @@ -571,14 +556,14 @@ func (ec *executionContext) _Mutation_createReview(field graphql.CollectedField) if res == nil { return graphql.Null } - return ec._Review(field.Selections, res) + return ec._Review(ctx, field.Selections, res) } var pageInfoImplementors = []string{"PageInfo"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _PageInfo(sel []query.Selection, obj *PageInfo) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, pageInfoImplementors, ec.variables) +func (ec *executionContext) _PageInfo(ctx context.Context, sel []query.Selection, obj *PageInfo) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, pageInfoImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -587,11 +572,11 @@ func (ec *executionContext) _PageInfo(sel []query.Selection, obj *PageInfo) grap case "__typename": out.Values[i] = graphql.MarshalString("PageInfo") case "startCursor": - out.Values[i] = ec._PageInfo_startCursor(field, obj) + out.Values[i] = ec._PageInfo_startCursor(ctx, field, obj) case "endCursor": - out.Values[i] = ec._PageInfo_endCursor(field, obj) + out.Values[i] = ec._PageInfo_endCursor(ctx, field, obj) case "hasNextPage": - out.Values[i] = ec._PageInfo_hasNextPage(field, obj) + out.Values[i] = ec._PageInfo_hasNextPage(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -600,17 +585,17 @@ func (ec *executionContext) _PageInfo(sel []query.Selection, obj *PageInfo) grap return out } -func (ec *executionContext) _PageInfo_startCursor(field graphql.CollectedField, obj *PageInfo) graphql.Marshaler { +func (ec *executionContext) _PageInfo_startCursor(ctx context.Context, field graphql.CollectedField, obj *PageInfo) graphql.Marshaler { res := obj.StartCursor return graphql.MarshalID(res) } -func (ec *executionContext) _PageInfo_endCursor(field graphql.CollectedField, obj *PageInfo) graphql.Marshaler { +func (ec *executionContext) _PageInfo_endCursor(ctx context.Context, field graphql.CollectedField, obj *PageInfo) graphql.Marshaler { res := obj.EndCursor return graphql.MarshalID(res) } -func (ec *executionContext) _PageInfo_hasNextPage(field graphql.CollectedField, obj *PageInfo) graphql.Marshaler { +func (ec *executionContext) _PageInfo_hasNextPage(ctx context.Context, field graphql.CollectedField, obj *PageInfo) graphql.Marshaler { res := obj.HasNextPage return graphql.MarshalBoolean(res) } @@ -618,8 +603,8 @@ func (ec *executionContext) _PageInfo_hasNextPage(field graphql.CollectedField, var queryImplementors = []string{"Query"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, queryImplementors, ec.variables) +func (ec *executionContext) _Query(ctx context.Context, sel []query.Selection) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, queryImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -628,23 +613,23 @@ func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { case "__typename": out.Values[i] = graphql.MarshalString("Query") case "hero": - out.Values[i] = ec._Query_hero(field) + out.Values[i] = ec._Query_hero(ctx, field) case "reviews": - out.Values[i] = ec._Query_reviews(field) + out.Values[i] = ec._Query_reviews(ctx, field) case "search": - out.Values[i] = ec._Query_search(field) + out.Values[i] = ec._Query_search(ctx, field) case "character": - out.Values[i] = ec._Query_character(field) + out.Values[i] = ec._Query_character(ctx, field) case "droid": - out.Values[i] = ec._Query_droid(field) + out.Values[i] = ec._Query_droid(ctx, field) case "human": - out.Values[i] = ec._Query_human(field) + out.Values[i] = ec._Query_human(ctx, field) case "starship": - out.Values[i] = ec._Query_starship(field) + out.Values[i] = ec._Query_starship(ctx, field) case "__schema": - out.Values[i] = ec._Query___schema(field) + out.Values[i] = ec._Query___schema(ctx, field) case "__type": - out.Values[i] = ec._Query___type(field) + out.Values[i] = ec._Query___type(ctx, field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -653,7 +638,7 @@ func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { return out } -func (ec *executionContext) _Query_hero(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_hero(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["episode"]; ok { var err error @@ -675,21 +660,22 @@ func (ec *executionContext) _Query_hero(field graphql.CollectedField) graphql.Ma return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_hero(ec.ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_hero(rctx, arg0) if err != nil { ec.Error(err) return graphql.Null } - return ec._Character(field.Selections, &res) + return ec._Character(ctx, field.Selections, &res) }) } -func (ec *executionContext) _Query_reviews(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["episode"]; ok { var err error @@ -716,25 +702,26 @@ func (ec *executionContext) _Query_reviews(field graphql.CollectedField) graphql return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_reviews(ec.ctx, arg0, arg1) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_reviews(rctx, arg0, arg1) if err != nil { ec.Error(err) return graphql.Null } arr1 := graphql.Array{} for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { return ec._Review(field.Selections, &res[idx1]) }()) + arr1 = append(arr1, func() graphql.Marshaler { return ec._Review(ctx, field.Selections, &res[idx1]) }()) } return arr1 }) } -func (ec *executionContext) _Query_search(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_search(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["text"]; ok { var err error @@ -747,25 +734,26 @@ func (ec *executionContext) _Query_search(field graphql.CollectedField) graphql. return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_search(ec.ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_search(rctx, arg0) if err != nil { ec.Error(err) return graphql.Null } arr1 := graphql.Array{} for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { return ec._SearchResult(field.Selections, &res[idx1]) }()) + arr1 = append(arr1, func() graphql.Marshaler { return ec._SearchResult(ctx, field.Selections, &res[idx1]) }()) } return arr1 }) } -func (ec *executionContext) _Query_character(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_character(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["id"]; ok { var err error @@ -778,21 +766,22 @@ func (ec *executionContext) _Query_character(field graphql.CollectedField) graph return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_character(ec.ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_character(rctx, arg0) if err != nil { ec.Error(err) return graphql.Null } - return ec._Character(field.Selections, &res) + return ec._Character(ctx, field.Selections, &res) }) } -func (ec *executionContext) _Query_droid(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_droid(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["id"]; ok { var err error @@ -805,12 +794,13 @@ func (ec *executionContext) _Query_droid(field graphql.CollectedField) graphql.M return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_droid(ec.ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_droid(rctx, arg0) if err != nil { ec.Error(err) return graphql.Null @@ -818,11 +808,11 @@ func (ec *executionContext) _Query_droid(field graphql.CollectedField) graphql.M if res == nil { return graphql.Null } - return ec._Droid(field.Selections, res) + return ec._Droid(ctx, field.Selections, res) }) } -func (ec *executionContext) _Query_human(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_human(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["id"]; ok { var err error @@ -835,12 +825,13 @@ func (ec *executionContext) _Query_human(field graphql.CollectedField) graphql.M return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_human(ec.ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_human(rctx, arg0) if err != nil { ec.Error(err) return graphql.Null @@ -848,11 +839,11 @@ func (ec *executionContext) _Query_human(field graphql.CollectedField) graphql.M if res == nil { return graphql.Null } - return ec._Human(field.Selections, res) + return ec._Human(ctx, field.Selections, res) }) } -func (ec *executionContext) _Query_starship(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_starship(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["id"]; ok { var err error @@ -865,12 +856,13 @@ func (ec *executionContext) _Query_starship(field graphql.CollectedField) graphq return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.Query_starship(ec.ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.Query_starship(rctx, arg0) if err != nil { ec.Error(err) return graphql.Null @@ -878,19 +870,19 @@ func (ec *executionContext) _Query_starship(field graphql.CollectedField) graphq if res == nil { return graphql.Null } - return ec._Starship(field.Selections, res) + return ec._Starship(ctx, field.Selections, res) }) } -func (ec *executionContext) _Query___schema(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { res := ec.introspectSchema() if res == nil { return graphql.Null } - return ec.___Schema(field.Selections, res) + return ec.___Schema(ctx, field.Selections, res) } -func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["name"]; ok { var err error @@ -904,14 +896,14 @@ func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql. if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } var reviewImplementors = []string{"Review"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Review(sel []query.Selection, obj *Review) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, reviewImplementors, ec.variables) +func (ec *executionContext) _Review(ctx context.Context, sel []query.Selection, obj *Review) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, reviewImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -920,11 +912,11 @@ func (ec *executionContext) _Review(sel []query.Selection, obj *Review) graphql. case "__typename": out.Values[i] = graphql.MarshalString("Review") case "stars": - out.Values[i] = ec._Review_stars(field, obj) + out.Values[i] = ec._Review_stars(ctx, field, obj) case "commentary": - out.Values[i] = ec._Review_commentary(field, obj) + out.Values[i] = ec._Review_commentary(ctx, field, obj) case "time": - out.Values[i] = ec._Review_time(field, obj) + out.Values[i] = ec._Review_time(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -933,12 +925,12 @@ func (ec *executionContext) _Review(sel []query.Selection, obj *Review) graphql. return out } -func (ec *executionContext) _Review_stars(field graphql.CollectedField, obj *Review) graphql.Marshaler { +func (ec *executionContext) _Review_stars(ctx context.Context, field graphql.CollectedField, obj *Review) graphql.Marshaler { res := obj.Stars return graphql.MarshalInt(res) } -func (ec *executionContext) _Review_commentary(field graphql.CollectedField, obj *Review) graphql.Marshaler { +func (ec *executionContext) _Review_commentary(ctx context.Context, field graphql.CollectedField, obj *Review) graphql.Marshaler { res := obj.Commentary if res == nil { return graphql.Null @@ -946,7 +938,7 @@ func (ec *executionContext) _Review_commentary(field graphql.CollectedField, obj return graphql.MarshalString(*res) } -func (ec *executionContext) _Review_time(field graphql.CollectedField, obj *Review) graphql.Marshaler { +func (ec *executionContext) _Review_time(ctx context.Context, field graphql.CollectedField, obj *Review) graphql.Marshaler { res := obj.Time return graphql.MarshalTime(res) } @@ -954,8 +946,8 @@ func (ec *executionContext) _Review_time(field graphql.CollectedField, obj *Revi var starshipImplementors = []string{"Starship"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Starship(sel []query.Selection, obj *Starship) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, starshipImplementors, ec.variables) +func (ec *executionContext) _Starship(ctx context.Context, sel []query.Selection, obj *Starship) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, starshipImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -964,13 +956,13 @@ func (ec *executionContext) _Starship(sel []query.Selection, obj *Starship) grap case "__typename": out.Values[i] = graphql.MarshalString("Starship") case "id": - out.Values[i] = ec._Starship_id(field, obj) + out.Values[i] = ec._Starship_id(ctx, field, obj) case "name": - out.Values[i] = ec._Starship_name(field, obj) + out.Values[i] = ec._Starship_name(ctx, field, obj) case "length": - out.Values[i] = ec._Starship_length(field, obj) + out.Values[i] = ec._Starship_length(ctx, field, obj) case "history": - out.Values[i] = ec._Starship_history(field, obj) + out.Values[i] = ec._Starship_history(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -979,17 +971,17 @@ func (ec *executionContext) _Starship(sel []query.Selection, obj *Starship) grap return out } -func (ec *executionContext) _Starship_id(field graphql.CollectedField, obj *Starship) graphql.Marshaler { +func (ec *executionContext) _Starship_id(ctx context.Context, field graphql.CollectedField, obj *Starship) graphql.Marshaler { res := obj.ID return graphql.MarshalID(res) } -func (ec *executionContext) _Starship_name(field graphql.CollectedField, obj *Starship) graphql.Marshaler { +func (ec *executionContext) _Starship_name(ctx context.Context, field graphql.CollectedField, obj *Starship) graphql.Marshaler { res := obj.Name return graphql.MarshalString(res) } -func (ec *executionContext) _Starship_length(field graphql.CollectedField, obj *Starship) graphql.Marshaler { +func (ec *executionContext) _Starship_length(ctx context.Context, field graphql.CollectedField, obj *Starship) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["unit"]; ok { var err error @@ -1012,7 +1004,7 @@ func (ec *executionContext) _Starship_length(field graphql.CollectedField, obj * return graphql.MarshalFloat(res) } -func (ec *executionContext) _Starship_history(field graphql.CollectedField, obj *Starship) graphql.Marshaler { +func (ec *executionContext) _Starship_history(ctx context.Context, field graphql.CollectedField, obj *Starship) graphql.Marshaler { res := obj.History arr1 := graphql.Array{} for idx1 := range res { @@ -1030,8 +1022,8 @@ func (ec *executionContext) _Starship_history(field graphql.CollectedField, obj var __DirectiveImplementors = []string{"__Directive"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __DirectiveImplementors, ec.variables) +func (ec *executionContext) ___Directive(ctx context.Context, sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __DirectiveImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -1040,13 +1032,13 @@ func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspecti case "__typename": out.Values[i] = graphql.MarshalString("__Directive") case "name": - out.Values[i] = ec.___Directive_name(field, obj) + out.Values[i] = ec.___Directive_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Directive_description(field, obj) + out.Values[i] = ec.___Directive_description(ctx, field, obj) case "locations": - out.Values[i] = ec.___Directive_locations(field, obj) + out.Values[i] = ec.___Directive_locations(ctx, field, obj) case "args": - out.Values[i] = ec.___Directive_args(field, obj) + out.Values[i] = ec.___Directive_args(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -1055,12 +1047,12 @@ func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspecti return out } -func (ec *executionContext) ___Directive_name(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___Directive_description(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -1068,7 +1060,7 @@ func (ec *executionContext) ___Directive_description(field graphql.CollectedFiel return graphql.MarshalString(*res) } -func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Locations() arr1 := graphql.Array{} for idx1 := range res { @@ -1077,7 +1069,7 @@ func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, return arr1 } -func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Args() arr1 := graphql.Array{} for idx1 := range res { @@ -1085,7 +1077,7 @@ func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 @@ -1094,8 +1086,8 @@ func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj var __EnumValueImplementors = []string{"__EnumValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __EnumValueImplementors, ec.variables) +func (ec *executionContext) ___EnumValue(ctx context.Context, sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __EnumValueImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -1104,13 +1096,13 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspecti case "__typename": out.Values[i] = graphql.MarshalString("__EnumValue") case "name": - out.Values[i] = ec.___EnumValue_name(field, obj) + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) case "description": - out.Values[i] = ec.___EnumValue_description(field, obj) + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(field, obj) + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(field, obj) + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -1119,12 +1111,12 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspecti return out } -func (ec *executionContext) ___EnumValue_name(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___EnumValue_description(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -1132,12 +1124,12 @@ func (ec *executionContext) ___EnumValue_description(field graphql.CollectedFiel return graphql.MarshalString(*res) } -func (ec *executionContext) ___EnumValue_isDeprecated(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.IsDeprecated() return graphql.MarshalBoolean(res) } -func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.DeprecationReason() if res == nil { return graphql.Null @@ -1148,8 +1140,8 @@ func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.Collect var __FieldImplementors = []string{"__Field"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __FieldImplementors, ec.variables) +func (ec *executionContext) ___Field(ctx context.Context, sel []query.Selection, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __FieldImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -1158,17 +1150,17 @@ func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.F case "__typename": out.Values[i] = graphql.MarshalString("__Field") case "name": - out.Values[i] = ec.___Field_name(field, obj) + out.Values[i] = ec.___Field_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Field_description(field, obj) + out.Values[i] = ec.___Field_description(ctx, field, obj) case "args": - out.Values[i] = ec.___Field_args(field, obj) + out.Values[i] = ec.___Field_args(ctx, field, obj) case "type": - out.Values[i] = ec.___Field_type(field, obj) + out.Values[i] = ec.___Field_type(ctx, field, obj) case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(field, obj) + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(field, obj) + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -1177,12 +1169,12 @@ func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.F return out } -func (ec *executionContext) ___Field_name(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___Field_description(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -1190,7 +1182,7 @@ func (ec *executionContext) ___Field_description(field graphql.CollectedField, o return graphql.MarshalString(*res) } -func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Args() arr1 := graphql.Array{} for idx1 := range res { @@ -1198,26 +1190,26 @@ func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *int if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Field_type(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Type() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Field_isDeprecated(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.IsDeprecated() return graphql.MarshalBoolean(res) } -func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.DeprecationReason() if res == nil { return graphql.Null @@ -1228,8 +1220,8 @@ func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedFi var __InputValueImplementors = []string{"__InputValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __InputValueImplementors, ec.variables) +func (ec *executionContext) ___InputValue(ctx context.Context, sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __InputValueImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -1238,13 +1230,13 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspect case "__typename": out.Values[i] = graphql.MarshalString("__InputValue") case "name": - out.Values[i] = ec.___InputValue_name(field, obj) + out.Values[i] = ec.___InputValue_name(ctx, field, obj) case "description": - out.Values[i] = ec.___InputValue_description(field, obj) + out.Values[i] = ec.___InputValue_description(ctx, field, obj) case "type": - out.Values[i] = ec.___InputValue_type(field, obj) + out.Values[i] = ec.___InputValue_type(ctx, field, obj) case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(field, obj) + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -1253,12 +1245,12 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspect return out } -func (ec *executionContext) ___InputValue_name(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___InputValue_description(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -1266,15 +1258,15 @@ func (ec *executionContext) ___InputValue_description(field graphql.CollectedFie return graphql.MarshalString(*res) } -func (ec *executionContext) ___InputValue_type(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Type() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.DefaultValue() if res == nil { return graphql.Null @@ -1285,8 +1277,8 @@ func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedFi var __SchemaImplementors = []string{"__Schema"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __SchemaImplementors, ec.variables) +func (ec *executionContext) ___Schema(ctx context.Context, sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __SchemaImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -1295,15 +1287,15 @@ func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection. case "__typename": out.Values[i] = graphql.MarshalString("__Schema") case "types": - out.Values[i] = ec.___Schema_types(field, obj) + out.Values[i] = ec.___Schema_types(ctx, field, obj) case "queryType": - out.Values[i] = ec.___Schema_queryType(field, obj) + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) case "mutationType": - out.Values[i] = ec.___Schema_mutationType(field, obj) + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(field, obj) + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) case "directives": - out.Values[i] = ec.___Schema_directives(field, obj) + out.Values[i] = ec.___Schema_directives(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -1312,7 +1304,7 @@ func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection. return out } -func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.Types() arr1 := graphql.Array{} for idx1 := range res { @@ -1320,37 +1312,37 @@ func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *i if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Schema_queryType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.QueryType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_mutationType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.MutationType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_subscriptionType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.SubscriptionType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.Directives() arr1 := graphql.Array{} for idx1 := range res { @@ -1358,7 +1350,7 @@ func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, o if res[idx1] == nil { return graphql.Null } - return ec.___Directive(field.Selections, res[idx1]) + return ec.___Directive(ctx, field.Selections, res[idx1]) }()) } return arr1 @@ -1367,8 +1359,8 @@ func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, o var __TypeImplementors = []string{"__Type"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __TypeImplementors, ec.variables) +func (ec *executionContext) ___Type(ctx context.Context, sel []query.Selection, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __TypeImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -1377,23 +1369,23 @@ func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Ty case "__typename": out.Values[i] = graphql.MarshalString("__Type") case "kind": - out.Values[i] = ec.___Type_kind(field, obj) + out.Values[i] = ec.___Type_kind(ctx, field, obj) case "name": - out.Values[i] = ec.___Type_name(field, obj) + out.Values[i] = ec.___Type_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Type_description(field, obj) + out.Values[i] = ec.___Type_description(ctx, field, obj) case "fields": - out.Values[i] = ec.___Type_fields(field, obj) + out.Values[i] = ec.___Type_fields(ctx, field, obj) case "interfaces": - out.Values[i] = ec.___Type_interfaces(field, obj) + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(field, obj) + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) case "enumValues": - out.Values[i] = ec.___Type_enumValues(field, obj) + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) case "inputFields": - out.Values[i] = ec.___Type_inputFields(field, obj) + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) case "ofType": - out.Values[i] = ec.___Type_ofType(field, obj) + out.Values[i] = ec.___Type_ofType(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -1402,12 +1394,12 @@ func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Ty return out } -func (ec *executionContext) ___Type_kind(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Kind() return graphql.MarshalString(res) } -func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Name() if res == nil { return graphql.Null @@ -1415,7 +1407,7 @@ func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *intr return graphql.MarshalString(*res) } -func (ec *executionContext) ___Type_description(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -1423,7 +1415,7 @@ func (ec *executionContext) ___Type_description(field graphql.CollectedField, ob return graphql.MarshalString(*res) } -func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -1440,13 +1432,13 @@ func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *in if res[idx1] == nil { return graphql.Null } - return ec.___Field(field.Selections, res[idx1]) + return ec.___Field(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Interfaces() arr1 := graphql.Array{} for idx1 := range res { @@ -1454,13 +1446,13 @@ func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.PossibleTypes() arr1 := graphql.Array{} for idx1 := range res { @@ -1468,13 +1460,13 @@ func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -1491,13 +1483,13 @@ func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___EnumValue(field.Selections, res[idx1]) + return ec.___EnumValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.InputFields() arr1 := graphql.Array{} for idx1 := range res { @@ -1505,53 +1497,53 @@ func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, ob if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_ofType(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.OfType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) _Character(sel []query.Selection, obj *Character) graphql.Marshaler { +func (ec *executionContext) _Character(ctx context.Context, sel []query.Selection, obj *Character) graphql.Marshaler { switch obj := (*obj).(type) { case nil: return graphql.Null case Human: - return ec._Human(sel, &obj) + return ec._Human(ctx, sel, &obj) case *Human: - return ec._Human(sel, obj) + return ec._Human(ctx, sel, obj) case Droid: - return ec._Droid(sel, &obj) + return ec._Droid(ctx, sel, &obj) case *Droid: - return ec._Droid(sel, obj) + return ec._Droid(ctx, sel, obj) default: panic(fmt.Errorf("unexpected type %T", obj)) } } -func (ec *executionContext) _SearchResult(sel []query.Selection, obj *SearchResult) graphql.Marshaler { +func (ec *executionContext) _SearchResult(ctx context.Context, sel []query.Selection, obj *SearchResult) graphql.Marshaler { switch obj := (*obj).(type) { case nil: return graphql.Null case Human: - return ec._Human(sel, &obj) + return ec._Human(ctx, sel, &obj) case *Human: - return ec._Human(sel, obj) + return ec._Human(ctx, sel, obj) case Droid: - return ec._Droid(sel, &obj) + return ec._Droid(ctx, sel, &obj) case *Droid: - return ec._Droid(sel, obj) + return ec._Droid(ctx, sel, obj) case Starship: - return ec._Starship(sel, &obj) + return ec._Starship(ctx, sel, &obj) case *Starship: - return ec._Starship(sel, obj) + return ec._Starship(ctx, sel, obj) default: panic(fmt.Errorf("unexpected type %T", obj)) } diff --git a/example/todo/generated.go b/example/todo/generated.go index 597ee7b2a1..0aeacaa446 100644 --- a/example/todo/generated.go +++ b/example/todo/generated.go @@ -14,12 +14,8 @@ import ( schema "github.com/vektah/gqlgen/neelance/schema" ) -func MakeExecutableSchema(resolvers Resolvers, opts ...ExecutableOption) graphql.ExecutableSchema { - ret := &executableSchema{resolvers: resolvers} - for _, opt := range opts { - opt(ret) - } - return ret +func MakeExecutableSchema(resolvers Resolvers) graphql.ExecutableSchema { + return &executableSchema{resolvers: resolvers} } type Resolvers interface { @@ -30,27 +26,18 @@ type Resolvers interface { MyQuery_todos(ctx context.Context) ([]Todo, error) } -type ExecutableOption func(*executableSchema) - -func WithErrorConverter(fn func(error) string) ExecutableOption { - return func(s *executableSchema) { - s.errorMessageFn = fn - } -} - type executableSchema struct { - resolvers Resolvers - errorMessageFn func(error) string + resolvers Resolvers } func (e *executableSchema) Schema() *schema.Schema { return parsedSchema } -func (e *executableSchema) Query(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { - ec := e.makeExecutionContext(ctx, doc, variables, recover) +func (e *executableSchema) Query(ctx context.Context, op *query.Operation) *graphql.Response { + ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers} - data := ec._MyQuery(op.Selections) + data := ec._MyQuery(ctx, op.Selections) var buf bytes.Buffer data.MarshalGQL(&buf) @@ -60,10 +47,10 @@ func (e *executableSchema) Query(ctx context.Context, doc *query.Document, varia } } -func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) *graphql.Response { - ec := e.makeExecutionContext(ctx, doc, variables, recover) +func (e *executableSchema) Mutation(ctx context.Context, op *query.Operation) *graphql.Response { + ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers} - data := ec._MyMutation(op.Selections) + data := ec._MyMutation(ctx, op.Selections) var buf bytes.Buffer data.MarshalGQL(&buf) @@ -73,31 +60,21 @@ func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, va } } -func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation, recover graphql.RecoverFunc) func() *graphql.Response { +func (e *executableSchema) Subscription(ctx context.Context, op *query.Operation) func() *graphql.Response { return graphql.OneShot(&graphql.Response{Errors: []*errors.QueryError{{Message: "subscriptions are not supported"}}}) } -func (e *executableSchema) makeExecutionContext(ctx context.Context, doc *query.Document, variables map[string]interface{}, recover graphql.RecoverFunc) *executionContext { - errBuilder := errors.Builder{ErrorMessageFn: e.errorMessageFn} - return &executionContext{ - Builder: errBuilder, resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx, recover: recover, - } -} - type executionContext struct { - errors.Builder + *graphql.RequestContext + resolvers Resolvers - variables map[string]interface{} - doc *query.Document - ctx context.Context - recover graphql.RecoverFunc } var myMutationImplementors = []string{"MyMutation"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _MyMutation(sel []query.Selection) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, myMutationImplementors, ec.variables) +func (ec *executionContext) _MyMutation(ctx context.Context, sel []query.Selection) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, myMutationImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -106,9 +83,9 @@ func (ec *executionContext) _MyMutation(sel []query.Selection) graphql.Marshaler case "__typename": out.Values[i] = graphql.MarshalString("MyMutation") case "createTodo": - out.Values[i] = ec._MyMutation_createTodo(field) + out.Values[i] = ec._MyMutation_createTodo(ctx, field) case "updateTodo": - out.Values[i] = ec._MyMutation_updateTodo(field) + out.Values[i] = ec._MyMutation_updateTodo(ctx, field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -117,7 +94,7 @@ func (ec *executionContext) _MyMutation(sel []query.Selection) graphql.Marshaler return out } -func (ec *executionContext) _MyMutation_createTodo(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _MyMutation_createTodo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 TodoInput if tmp, ok := field.Args["todo"]; ok { var err error @@ -127,15 +104,16 @@ func (ec *executionContext) _MyMutation_createTodo(field graphql.CollectedField) return graphql.Null } } - res, err := ec.resolvers.MyMutation_createTodo(ec.ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.MyMutation_createTodo(rctx, arg0) if err != nil { ec.Error(err) return graphql.Null } - return ec._Todo(field.Selections, &res) + return ec._Todo(ctx, field.Selections, &res) } -func (ec *executionContext) _MyMutation_updateTodo(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _MyMutation_updateTodo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 int if tmp, ok := field.Args["id"]; ok { var err error @@ -154,7 +132,8 @@ func (ec *executionContext) _MyMutation_updateTodo(field graphql.CollectedField) return graphql.Null } } - res, err := ec.resolvers.MyMutation_updateTodo(ec.ctx, arg0, arg1) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.MyMutation_updateTodo(rctx, arg0, arg1) if err != nil { ec.Error(err) return graphql.Null @@ -162,14 +141,14 @@ func (ec *executionContext) _MyMutation_updateTodo(field graphql.CollectedField) if res == nil { return graphql.Null } - return ec._Todo(field.Selections, res) + return ec._Todo(ctx, field.Selections, res) } var myQueryImplementors = []string{"MyQuery"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _MyQuery(sel []query.Selection) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, myQueryImplementors, ec.variables) +func (ec *executionContext) _MyQuery(ctx context.Context, sel []query.Selection) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, myQueryImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -178,15 +157,15 @@ func (ec *executionContext) _MyQuery(sel []query.Selection) graphql.Marshaler { case "__typename": out.Values[i] = graphql.MarshalString("MyQuery") case "todo": - out.Values[i] = ec._MyQuery_todo(field) + out.Values[i] = ec._MyQuery_todo(ctx, field) case "lastTodo": - out.Values[i] = ec._MyQuery_lastTodo(field) + out.Values[i] = ec._MyQuery_lastTodo(ctx, field) case "todos": - out.Values[i] = ec._MyQuery_todos(field) + out.Values[i] = ec._MyQuery_todos(ctx, field) case "__schema": - out.Values[i] = ec._MyQuery___schema(field) + out.Values[i] = ec._MyQuery___schema(ctx, field) case "__type": - out.Values[i] = ec._MyQuery___type(field) + out.Values[i] = ec._MyQuery___type(ctx, field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -195,7 +174,7 @@ func (ec *executionContext) _MyQuery(sel []query.Selection) graphql.Marshaler { return out } -func (ec *executionContext) _MyQuery_todo(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _MyQuery_todo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 int if tmp, ok := field.Args["id"]; ok { var err error @@ -208,12 +187,13 @@ func (ec *executionContext) _MyQuery_todo(field graphql.CollectedField) graphql. return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.MyQuery_todo(ec.ctx, arg0) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.MyQuery_todo(rctx, arg0) if err != nil { ec.Error(err) return graphql.Null @@ -221,20 +201,21 @@ func (ec *executionContext) _MyQuery_todo(field graphql.CollectedField) graphql. if res == nil { return graphql.Null } - return ec._Todo(field.Selections, res) + return ec._Todo(ctx, field.Selections, res) }) } -func (ec *executionContext) _MyQuery_lastTodo(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _MyQuery_lastTodo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.MyQuery_lastTodo(ec.ctx) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.MyQuery_lastTodo(rctx) if err != nil { ec.Error(err) return graphql.Null @@ -242,41 +223,42 @@ func (ec *executionContext) _MyQuery_lastTodo(field graphql.CollectedField) grap if res == nil { return graphql.Null } - return ec._Todo(field.Selections, res) + return ec._Todo(ctx, field.Selections, res) }) } -func (ec *executionContext) _MyQuery_todos(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _MyQuery_todos(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { return graphql.Defer(func() (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { - userErr := ec.recover(r) + userErr := ec.Recover(r) ec.Error(userErr) ret = graphql.Null } }() - res, err := ec.resolvers.MyQuery_todos(ec.ctx) + rctx := graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field}) + res, err := ec.resolvers.MyQuery_todos(rctx) if err != nil { ec.Error(err) return graphql.Null } arr1 := graphql.Array{} for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { return ec._Todo(field.Selections, &res[idx1]) }()) + arr1 = append(arr1, func() graphql.Marshaler { return ec._Todo(ctx, field.Selections, &res[idx1]) }()) } return arr1 }) } -func (ec *executionContext) _MyQuery___schema(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _MyQuery___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { res := ec.introspectSchema() if res == nil { return graphql.Null } - return ec.___Schema(field.Selections, res) + return ec.___Schema(ctx, field.Selections, res) } -func (ec *executionContext) _MyQuery___type(field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _MyQuery___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { var arg0 string if tmp, ok := field.Args["name"]; ok { var err error @@ -290,14 +272,14 @@ func (ec *executionContext) _MyQuery___type(field graphql.CollectedField) graphq if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } var todoImplementors = []string{"Todo"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Todo(sel []query.Selection, obj *Todo) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, todoImplementors, ec.variables) +func (ec *executionContext) _Todo(ctx context.Context, sel []query.Selection, obj *Todo) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, todoImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -306,11 +288,11 @@ func (ec *executionContext) _Todo(sel []query.Selection, obj *Todo) graphql.Mars case "__typename": out.Values[i] = graphql.MarshalString("Todo") case "id": - out.Values[i] = ec._Todo_id(field, obj) + out.Values[i] = ec._Todo_id(ctx, field, obj) case "text": - out.Values[i] = ec._Todo_text(field, obj) + out.Values[i] = ec._Todo_text(ctx, field, obj) case "done": - out.Values[i] = ec._Todo_done(field, obj) + out.Values[i] = ec._Todo_done(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -319,17 +301,17 @@ func (ec *executionContext) _Todo(sel []query.Selection, obj *Todo) graphql.Mars return out } -func (ec *executionContext) _Todo_id(field graphql.CollectedField, obj *Todo) graphql.Marshaler { +func (ec *executionContext) _Todo_id(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { res := obj.ID return graphql.MarshalInt(res) } -func (ec *executionContext) _Todo_text(field graphql.CollectedField, obj *Todo) graphql.Marshaler { +func (ec *executionContext) _Todo_text(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { res := obj.Text return graphql.MarshalString(res) } -func (ec *executionContext) _Todo_done(field graphql.CollectedField, obj *Todo) graphql.Marshaler { +func (ec *executionContext) _Todo_done(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { res := obj.Done return graphql.MarshalBoolean(res) } @@ -337,8 +319,8 @@ func (ec *executionContext) _Todo_done(field graphql.CollectedField, obj *Todo) var __DirectiveImplementors = []string{"__Directive"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __DirectiveImplementors, ec.variables) +func (ec *executionContext) ___Directive(ctx context.Context, sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __DirectiveImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -347,13 +329,13 @@ func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspecti case "__typename": out.Values[i] = graphql.MarshalString("__Directive") case "name": - out.Values[i] = ec.___Directive_name(field, obj) + out.Values[i] = ec.___Directive_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Directive_description(field, obj) + out.Values[i] = ec.___Directive_description(ctx, field, obj) case "locations": - out.Values[i] = ec.___Directive_locations(field, obj) + out.Values[i] = ec.___Directive_locations(ctx, field, obj) case "args": - out.Values[i] = ec.___Directive_args(field, obj) + out.Values[i] = ec.___Directive_args(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -362,12 +344,12 @@ func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspecti return out } -func (ec *executionContext) ___Directive_name(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___Directive_description(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -375,7 +357,7 @@ func (ec *executionContext) ___Directive_description(field graphql.CollectedFiel return graphql.MarshalString(*res) } -func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Locations() arr1 := graphql.Array{} for idx1 := range res { @@ -384,7 +366,7 @@ func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, return arr1 } -func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { res := obj.Args() arr1 := graphql.Array{} for idx1 := range res { @@ -392,7 +374,7 @@ func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 @@ -401,8 +383,8 @@ func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj var __EnumValueImplementors = []string{"__EnumValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __EnumValueImplementors, ec.variables) +func (ec *executionContext) ___EnumValue(ctx context.Context, sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __EnumValueImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -411,13 +393,13 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspecti case "__typename": out.Values[i] = graphql.MarshalString("__EnumValue") case "name": - out.Values[i] = ec.___EnumValue_name(field, obj) + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) case "description": - out.Values[i] = ec.___EnumValue_description(field, obj) + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(field, obj) + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(field, obj) + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -426,12 +408,12 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspecti return out } -func (ec *executionContext) ___EnumValue_name(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___EnumValue_description(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -439,12 +421,12 @@ func (ec *executionContext) ___EnumValue_description(field graphql.CollectedFiel return graphql.MarshalString(*res) } -func (ec *executionContext) ___EnumValue_isDeprecated(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.IsDeprecated() return graphql.MarshalBoolean(res) } -func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { res := obj.DeprecationReason() if res == nil { return graphql.Null @@ -455,8 +437,8 @@ func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.Collect var __FieldImplementors = []string{"__Field"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __FieldImplementors, ec.variables) +func (ec *executionContext) ___Field(ctx context.Context, sel []query.Selection, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __FieldImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -465,17 +447,17 @@ func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.F case "__typename": out.Values[i] = graphql.MarshalString("__Field") case "name": - out.Values[i] = ec.___Field_name(field, obj) + out.Values[i] = ec.___Field_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Field_description(field, obj) + out.Values[i] = ec.___Field_description(ctx, field, obj) case "args": - out.Values[i] = ec.___Field_args(field, obj) + out.Values[i] = ec.___Field_args(ctx, field, obj) case "type": - out.Values[i] = ec.___Field_type(field, obj) + out.Values[i] = ec.___Field_type(ctx, field, obj) case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(field, obj) + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(field, obj) + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -484,12 +466,12 @@ func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.F return out } -func (ec *executionContext) ___Field_name(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___Field_description(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -497,7 +479,7 @@ func (ec *executionContext) ___Field_description(field graphql.CollectedField, o return graphql.MarshalString(*res) } -func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Args() arr1 := graphql.Array{} for idx1 := range res { @@ -505,26 +487,26 @@ func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *int if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Field_type(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.Type() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Field_isDeprecated(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.IsDeprecated() return graphql.MarshalBoolean(res) } -func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { res := obj.DeprecationReason() if res == nil { return graphql.Null @@ -535,8 +517,8 @@ func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedFi var __InputValueImplementors = []string{"__InputValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __InputValueImplementors, ec.variables) +func (ec *executionContext) ___InputValue(ctx context.Context, sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __InputValueImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -545,13 +527,13 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspect case "__typename": out.Values[i] = graphql.MarshalString("__InputValue") case "name": - out.Values[i] = ec.___InputValue_name(field, obj) + out.Values[i] = ec.___InputValue_name(ctx, field, obj) case "description": - out.Values[i] = ec.___InputValue_description(field, obj) + out.Values[i] = ec.___InputValue_description(ctx, field, obj) case "type": - out.Values[i] = ec.___InputValue_type(field, obj) + out.Values[i] = ec.___InputValue_type(ctx, field, obj) case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(field, obj) + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -560,12 +542,12 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspect return out } -func (ec *executionContext) ___InputValue_name(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Name() return graphql.MarshalString(res) } -func (ec *executionContext) ___InputValue_description(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -573,15 +555,15 @@ func (ec *executionContext) ___InputValue_description(field graphql.CollectedFie return graphql.MarshalString(*res) } -func (ec *executionContext) ___InputValue_type(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.Type() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { res := obj.DefaultValue() if res == nil { return graphql.Null @@ -592,8 +574,8 @@ func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedFi var __SchemaImplementors = []string{"__Schema"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __SchemaImplementors, ec.variables) +func (ec *executionContext) ___Schema(ctx context.Context, sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __SchemaImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -602,15 +584,15 @@ func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection. case "__typename": out.Values[i] = graphql.MarshalString("__Schema") case "types": - out.Values[i] = ec.___Schema_types(field, obj) + out.Values[i] = ec.___Schema_types(ctx, field, obj) case "queryType": - out.Values[i] = ec.___Schema_queryType(field, obj) + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) case "mutationType": - out.Values[i] = ec.___Schema_mutationType(field, obj) + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(field, obj) + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) case "directives": - out.Values[i] = ec.___Schema_directives(field, obj) + out.Values[i] = ec.___Schema_directives(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -619,7 +601,7 @@ func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection. return out } -func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.Types() arr1 := graphql.Array{} for idx1 := range res { @@ -627,37 +609,37 @@ func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *i if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Schema_queryType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.QueryType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_mutationType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.MutationType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_subscriptionType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.SubscriptionType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } -func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { res := obj.Directives() arr1 := graphql.Array{} for idx1 := range res { @@ -665,7 +647,7 @@ func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, o if res[idx1] == nil { return graphql.Null } - return ec.___Directive(field.Selections, res[idx1]) + return ec.___Directive(ctx, field.Selections, res[idx1]) }()) } return arr1 @@ -674,8 +656,8 @@ func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, o var __TypeImplementors = []string{"__Type"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ec.doc, sel, __TypeImplementors, ec.variables) +func (ec *executionContext) ___Type(ctx context.Context, sel []query.Selection, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, __TypeImplementors, ec.Variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias @@ -684,23 +666,23 @@ func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Ty case "__typename": out.Values[i] = graphql.MarshalString("__Type") case "kind": - out.Values[i] = ec.___Type_kind(field, obj) + out.Values[i] = ec.___Type_kind(ctx, field, obj) case "name": - out.Values[i] = ec.___Type_name(field, obj) + out.Values[i] = ec.___Type_name(ctx, field, obj) case "description": - out.Values[i] = ec.___Type_description(field, obj) + out.Values[i] = ec.___Type_description(ctx, field, obj) case "fields": - out.Values[i] = ec.___Type_fields(field, obj) + out.Values[i] = ec.___Type_fields(ctx, field, obj) case "interfaces": - out.Values[i] = ec.___Type_interfaces(field, obj) + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(field, obj) + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) case "enumValues": - out.Values[i] = ec.___Type_enumValues(field, obj) + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) case "inputFields": - out.Values[i] = ec.___Type_inputFields(field, obj) + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) case "ofType": - out.Values[i] = ec.___Type_ofType(field, obj) + out.Values[i] = ec.___Type_ofType(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -709,12 +691,12 @@ func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Ty return out } -func (ec *executionContext) ___Type_kind(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Kind() return graphql.MarshalString(res) } -func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Name() if res == nil { return graphql.Null @@ -722,7 +704,7 @@ func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *intr return graphql.MarshalString(*res) } -func (ec *executionContext) ___Type_description(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Description() if res == nil { return graphql.Null @@ -730,7 +712,7 @@ func (ec *executionContext) ___Type_description(field graphql.CollectedField, ob return graphql.MarshalString(*res) } -func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -747,13 +729,13 @@ func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *in if res[idx1] == nil { return graphql.Null } - return ec.___Field(field.Selections, res[idx1]) + return ec.___Field(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.Interfaces() arr1 := graphql.Array{} for idx1 := range res { @@ -761,13 +743,13 @@ func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.PossibleTypes() arr1 := graphql.Array{} for idx1 := range res { @@ -775,13 +757,13 @@ func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, if res[idx1] == nil { return graphql.Null } - return ec.___Type(field.Selections, res[idx1]) + return ec.___Type(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { var arg0 bool if tmp, ok := field.Args["includeDeprecated"]; ok { var err error @@ -798,13 +780,13 @@ func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj if res[idx1] == nil { return graphql.Null } - return ec.___EnumValue(field.Selections, res[idx1]) + return ec.___EnumValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.InputFields() arr1 := graphql.Array{} for idx1 := range res { @@ -812,18 +794,18 @@ func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, ob if res[idx1] == nil { return graphql.Null } - return ec.___InputValue(field.Selections, res[idx1]) + return ec.___InputValue(ctx, field.Selections, res[idx1]) }()) } return arr1 } -func (ec *executionContext) ___Type_ofType(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { res := obj.OfType() if res == nil { return graphql.Null } - return ec.___Type(field.Selections, res) + return ec.___Type(ctx, field.Selections, res) } func UnmarshalTodoInput(v interface{}) (TodoInput, error) {