diff --git a/cmd/ggraphqlc/dumper.go b/cmd/ggraphqlc/dumper.go index 37cbb3123e0..4bc93a57ae5 100644 --- a/cmd/ggraphqlc/dumper.go +++ b/cmd/ggraphqlc/dumper.go @@ -63,6 +63,8 @@ func (w *writer) lf() { } func (w *writer) writePackage() { + w.line("// This file was generated by github.com/vektah/graphql-go, DO NOT EDIT") + w.lf() w.line("package %s", w.PackageName) w.lf() } @@ -122,7 +124,7 @@ func (w *writer) writeVars() { func (w *writer) writeObjectResolver(object object) { w.line("// nolint: gocyclo, errcheck, gas, goconst") - w.begin("func _%s(ec *executionContext, sel []query.Selection, it *%s) {", lcFirst(object.Type.GraphQLName), object.Type.Local()) + w.begin("func (ec *executionContext) _%s(sel []query.Selection, it *%s) {", lcFirst(object.Type.GraphQLName), object.Type.Local()) w.line("groupedFieldSet := ec.collectFields(sel, %sSatisfies, map[string]bool{})", lcFirst(object.Type.GraphQLName)) w.line("ec.json.BeginObject()") @@ -255,9 +257,9 @@ func (w *writer) doWriteJsonType(t kind, val string, remainingMods []string, isP w.line(" ec.json.Null()") for _, implementor := range t.Implementors { w.line("case %s:", implementor.Local()) - w.line(" _%s(ec, field.Selections, &it)", lcFirst(implementor.GraphQLName)) + w.line(" ec._%s(field.Selections, &it)", lcFirst(implementor.GraphQLName)) w.line("case *%s:", implementor.Local()) - w.line(" _%s(ec, field.Selections, it)", lcFirst(implementor.GraphQLName)) + w.line(" ec._%s(field.Selections, it)", lcFirst(implementor.GraphQLName)) } w.line("default:") @@ -267,7 +269,7 @@ func (w *writer) doWriteJsonType(t kind, val string, remainingMods []string, isP if !isPtr { val = "&" + val } - w.line("_%s(ec, field.Selections, %s)", lcFirst(t.GraphQLName), val) + w.line("ec._%s(field.Selections, %s)", lcFirst(t.GraphQLName), val) } } diff --git a/cmd/ggraphqlc/exec.go b/cmd/ggraphqlc/exec.go index 0a86d3be1e5..a05e53e13b8 100644 --- a/cmd/ggraphqlc/exec.go +++ b/cmd/ggraphqlc/exec.go @@ -54,9 +54,9 @@ func NewResolver(resolvers Resolvers) relay.Resolver { c.json.ObjectKey("data") if op.Type == query.Query { - {{.RootQuery}}(&c, op.Selections, nil) + c.{{.RootQuery}}(op.Selections, nil) } else if op.Type == query.Mutation { - {{.RootMutation}}(&c, op.Selections, nil) + c.{{.RootMutation}}(op.Selections, nil) } else { c.Errorf("unsupported operation %s", op.Type) c.json.Null() @@ -81,11 +81,11 @@ type executionContext struct { ctx context.Context } -func (c *executionContext) introspectSchema() *introspection.Schema { +func (ec *executionContext) introspectSchema() *introspection.Schema { return introspection.WrapSchema(parsedSchema) } -func (c *executionContext) introspectType(name string) *introspection.Type { +func (ec *executionContext) introspectType(name string) *introspection.Type { t := parsedSchema.Resolve(name) if t == nil { return nil @@ -102,7 +102,7 @@ func instanceOf(val string, satisfies []string) bool { return false } -func (c *executionContext) collectFields(selSet []query.Selection, satisfies []string, visited map[string]bool) []collectedField { +func (ec *executionContext) collectFields(selSet []query.Selection, satisfies []string, visited map[string]bool) []collectedField { var groupedFields []collectedField for _, sel := range selSet { @@ -116,7 +116,7 @@ func (c *executionContext) collectFields(selSet []query.Selection, satisfies []s if len(sel.Arguments) > 0 { f.Args = map[string]interface{}{} for _, arg := range sel.Arguments { - f.Args[arg.Name.Name] = arg.Value.Value(c.variables) + f.Args[arg.Name.Name] = arg.Value.Value(ec.variables) } } return f @@ -128,7 +128,7 @@ func (c *executionContext) collectFields(selSet []query.Selection, satisfies []s continue } - for _, childField := range c.collectFields(sel.Selections, satisfies, visited) { + for _, childField := range ec.collectFields(sel.Selections, satisfies, visited) { f := getOrCreateField(&groupedFields, childField.Name, func() collectedField { return childField }) f.Selections = append(f.Selections, childField.Selections...) } @@ -140,9 +140,9 @@ func (c *executionContext) collectFields(selSet []query.Selection, satisfies []s } visited[fragmentName] = true - fragment := c.doc.Fragments.Get(fragmentName) + fragment := ec.doc.Fragments.Get(fragmentName) if fragment == nil { - c.Errorf("missing fragment %s", fragmentName) + ec.Errorf("missing fragment %s", fragmentName) continue } @@ -150,7 +150,7 @@ func (c *executionContext) collectFields(selSet []query.Selection, satisfies []s continue } - for _, childField := range c.collectFields(fragment.Selections, satisfies, visited) { + for _, childField := range ec.collectFields(fragment.Selections, satisfies, visited) { f := getOrCreateField(&groupedFields, childField.Name, func() collectedField { return childField }) f.Selections = append(f.Selections, childField.Selections...) } diff --git a/example/starwars/gen/generated.go b/example/starwars/gen/generated.go index d60d8e82d24..7062458461a 100644 --- a/example/starwars/gen/generated.go +++ b/example/starwars/gen/generated.go @@ -1,3 +1,5 @@ +// This file was generated by github.com/vektah/graphql-go, DO NOT EDIT + package gen import ( @@ -51,7 +53,7 @@ var ( ) // nolint: gocyclo, errcheck, gas, goconst -func _droid(ec *executionContext, sel []query.Selection, it *starwars.Droid) { +func (ec *executionContext) _droid(sel []query.Selection, it *starwars.Droid) { groupedFieldSet := ec.collectFields(sel, droidSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -81,13 +83,13 @@ func _droid(ec *executionContext, sel []query.Selection, it *starwars.Droid) { case nil: ec.json.Null() case starwars.Human: - _human(ec, field.Selections, &it) + ec._human(field.Selections, &it) case *starwars.Human: - _human(ec, field.Selections, it) + ec._human(field.Selections, it) case starwars.Droid: - _droid(ec, field.Selections, &it) + ec._droid(field.Selections, &it) case *starwars.Droid: - _droid(ec, field.Selections, it) + ec._droid(field.Selections, it) default: panic(fmt.Errorf("unexpected type %T", it)) } @@ -112,7 +114,7 @@ func _droid(ec *executionContext, sel []query.Selection, it *starwars.Droid) { ec.Error(err) continue } - _friendsConnection(ec, field.Selections, &res) + ec._friendsConnection(field.Selections, &res) continue case "appearsIn": @@ -138,7 +140,7 @@ func _droid(ec *executionContext, sel []query.Selection, it *starwars.Droid) { } // nolint: gocyclo, errcheck, gas, goconst -func _friendsConnection(ec *executionContext, sel []query.Selection, it *starwars.FriendsConnection) { +func (ec *executionContext) _friendsConnection(sel []query.Selection, it *starwars.FriendsConnection) { groupedFieldSet := ec.collectFields(sel, friendsConnectionSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -158,7 +160,7 @@ func _friendsConnection(ec *executionContext, sel []query.Selection, it *starwar } ec.json.BeginArray() for _, val := range res { - _friendsEdge(ec, field.Selections, &val) + ec._friendsEdge(field.Selections, &val) } ec.json.EndArray() continue @@ -176,13 +178,13 @@ func _friendsConnection(ec *executionContext, sel []query.Selection, it *starwar case nil: ec.json.Null() case starwars.Human: - _human(ec, field.Selections, &it) + ec._human(field.Selections, &it) case *starwars.Human: - _human(ec, field.Selections, it) + ec._human(field.Selections, it) case starwars.Droid: - _droid(ec, field.Selections, &it) + ec._droid(field.Selections, &it) case *starwars.Droid: - _droid(ec, field.Selections, it) + ec._droid(field.Selections, it) default: panic(fmt.Errorf("unexpected type %T", it)) } @@ -193,7 +195,7 @@ func _friendsConnection(ec *executionContext, sel []query.Selection, it *starwar case "pageInfo": ec.json.ObjectKey(field.Alias) res := it.PageInfo() - _pageInfo(ec, field.Selections, &res) + ec._pageInfo(field.Selections, &res) continue } @@ -203,7 +205,7 @@ func _friendsConnection(ec *executionContext, sel []query.Selection, it *starwar } // nolint: gocyclo, errcheck, gas, goconst -func _friendsEdge(ec *executionContext, sel []query.Selection, it *starwars.FriendsEdge) { +func (ec *executionContext) _friendsEdge(sel []query.Selection, it *starwars.FriendsEdge) { groupedFieldSet := ec.collectFields(sel, friendsEdgeSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -221,13 +223,13 @@ func _friendsEdge(ec *executionContext, sel []query.Selection, it *starwars.Frie case nil: ec.json.Null() case starwars.Human: - _human(ec, field.Selections, &it) + ec._human(field.Selections, &it) case *starwars.Human: - _human(ec, field.Selections, it) + ec._human(field.Selections, it) case starwars.Droid: - _droid(ec, field.Selections, &it) + ec._droid(field.Selections, &it) case *starwars.Droid: - _droid(ec, field.Selections, it) + ec._droid(field.Selections, it) default: panic(fmt.Errorf("unexpected type %T", it)) } @@ -240,7 +242,7 @@ func _friendsEdge(ec *executionContext, sel []query.Selection, it *starwars.Frie } // nolint: gocyclo, errcheck, gas, goconst -func _human(ec *executionContext, sel []query.Selection, it *starwars.Human) { +func (ec *executionContext) _human(sel []query.Selection, it *starwars.Human) { groupedFieldSet := ec.collectFields(sel, humanSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -282,13 +284,13 @@ func _human(ec *executionContext, sel []query.Selection, it *starwars.Human) { case nil: ec.json.Null() case starwars.Human: - _human(ec, field.Selections, &it) + ec._human(field.Selections, &it) case *starwars.Human: - _human(ec, field.Selections, it) + ec._human(field.Selections, it) case starwars.Droid: - _droid(ec, field.Selections, &it) + ec._droid(field.Selections, &it) case *starwars.Droid: - _droid(ec, field.Selections, it) + ec._droid(field.Selections, it) default: panic(fmt.Errorf("unexpected type %T", it)) } @@ -313,7 +315,7 @@ func _human(ec *executionContext, sel []query.Selection, it *starwars.Human) { ec.Error(err) continue } - _friendsConnection(ec, field.Selections, &res) + ec._friendsConnection(field.Selections, &res) continue case "appearsIn": @@ -335,7 +337,7 @@ func _human(ec *executionContext, sel []query.Selection, it *starwars.Human) { } ec.json.BeginArray() for _, val := range res { - _starship(ec, field.Selections, &val) + ec._starship(field.Selections, &val) } ec.json.EndArray() continue @@ -347,7 +349,7 @@ func _human(ec *executionContext, sel []query.Selection, it *starwars.Human) { } // nolint: gocyclo, errcheck, gas, goconst -func _mutation(ec *executionContext, sel []query.Selection, it *interface{}) { +func (ec *executionContext) _mutation(sel []query.Selection, it *interface{}) { groupedFieldSet := ec.collectFields(sel, mutationSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -371,7 +373,7 @@ func _mutation(ec *executionContext, sel []query.Selection, it *interface{}) { if res == nil { ec.json.Null() } else { - _review(ec, field.Selections, res) + ec._review(field.Selections, res) } continue @@ -382,7 +384,7 @@ func _mutation(ec *executionContext, sel []query.Selection, it *interface{}) { } // nolint: gocyclo, errcheck, gas, goconst -func _pageInfo(ec *executionContext, sel []query.Selection, it *starwars.PageInfo) { +func (ec *executionContext) _pageInfo(sel []query.Selection, it *starwars.PageInfo) { groupedFieldSet := ec.collectFields(sel, pageInfoSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -412,7 +414,7 @@ func _pageInfo(ec *executionContext, sel []query.Selection, it *starwars.PageInf } // nolint: gocyclo, errcheck, gas, goconst -func _query(ec *executionContext, sel []query.Selection, it *interface{}) { +func (ec *executionContext) _query(sel []query.Selection, it *interface{}) { groupedFieldSet := ec.collectFields(sel, querySatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -433,13 +435,13 @@ func _query(ec *executionContext, sel []query.Selection, it *interface{}) { case nil: ec.json.Null() case starwars.Human: - _human(ec, field.Selections, &it) + ec._human(field.Selections, &it) case *starwars.Human: - _human(ec, field.Selections, it) + ec._human(field.Selections, it) case starwars.Droid: - _droid(ec, field.Selections, &it) + ec._droid(field.Selections, &it) case *starwars.Droid: - _droid(ec, field.Selections, it) + ec._droid(field.Selections, it) default: panic(fmt.Errorf("unexpected type %T", it)) } @@ -458,7 +460,7 @@ func _query(ec *executionContext, sel []query.Selection, it *interface{}) { } ec.json.BeginArray() for _, val := range res { - _review(ec, field.Selections, &val) + ec._review(field.Selections, &val) } ec.json.EndArray() continue @@ -480,17 +482,17 @@ func _query(ec *executionContext, sel []query.Selection, it *interface{}) { case nil: ec.json.Null() case starwars.Human: - _human(ec, field.Selections, &it) + ec._human(field.Selections, &it) case *starwars.Human: - _human(ec, field.Selections, it) + ec._human(field.Selections, it) case starwars.Droid: - _droid(ec, field.Selections, &it) + ec._droid(field.Selections, &it) case *starwars.Droid: - _droid(ec, field.Selections, it) + ec._droid(field.Selections, it) case starwars.Starship: - _starship(ec, field.Selections, &it) + ec._starship(field.Selections, &it) case *starwars.Starship: - _starship(ec, field.Selections, it) + ec._starship(field.Selections, it) default: panic(fmt.Errorf("unexpected type %T", it)) } @@ -513,13 +515,13 @@ func _query(ec *executionContext, sel []query.Selection, it *interface{}) { case nil: ec.json.Null() case starwars.Human: - _human(ec, field.Selections, &it) + ec._human(field.Selections, &it) case *starwars.Human: - _human(ec, field.Selections, it) + ec._human(field.Selections, it) case starwars.Droid: - _droid(ec, field.Selections, &it) + ec._droid(field.Selections, &it) case *starwars.Droid: - _droid(ec, field.Selections, it) + ec._droid(field.Selections, it) default: panic(fmt.Errorf("unexpected type %T", it)) } @@ -539,7 +541,7 @@ func _query(ec *executionContext, sel []query.Selection, it *interface{}) { if res == nil { ec.json.Null() } else { - _droid(ec, field.Selections, res) + ec._droid(field.Selections, res) } continue @@ -557,7 +559,7 @@ func _query(ec *executionContext, sel []query.Selection, it *interface{}) { if res == nil { ec.json.Null() } else { - _human(ec, field.Selections, res) + ec._human(field.Selections, res) } continue @@ -575,7 +577,7 @@ func _query(ec *executionContext, sel []query.Selection, it *interface{}) { if res == nil { ec.json.Null() } else { - _starship(ec, field.Selections, res) + ec._starship(field.Selections, res) } continue @@ -585,7 +587,7 @@ func _query(ec *executionContext, sel []query.Selection, it *interface{}) { if res == nil { ec.json.Null() } else { - ___Schema(ec, field.Selections, res) + ec.___Schema(field.Selections, res) } continue @@ -599,7 +601,7 @@ func _query(ec *executionContext, sel []query.Selection, it *interface{}) { if res == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, res) + ec.___Type(field.Selections, res) } continue @@ -610,7 +612,7 @@ func _query(ec *executionContext, sel []query.Selection, it *interface{}) { } // nolint: gocyclo, errcheck, gas, goconst -func _review(ec *executionContext, sel []query.Selection, it *starwars.Review) { +func (ec *executionContext) _review(sel []query.Selection, it *starwars.Review) { groupedFieldSet := ec.collectFields(sel, reviewSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -638,7 +640,7 @@ func _review(ec *executionContext, sel []query.Selection, it *starwars.Review) { } // nolint: gocyclo, errcheck, gas, goconst -func _starship(ec *executionContext, sel []query.Selection, it *starwars.Starship) { +func (ec *executionContext) _starship(sel []query.Selection, it *starwars.Starship) { groupedFieldSet := ec.collectFields(sel, starshipSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -668,7 +670,7 @@ func _starship(ec *executionContext, sel []query.Selection, it *starwars.Starshi } // nolint: gocyclo, errcheck, gas, goconst -func ___Directive(ec *executionContext, sel []query.Selection, it *introspection.Directive) { +func (ec *executionContext) ___Directive(sel []query.Selection, it *introspection.Directive) { groupedFieldSet := ec.collectFields(sel, __DirectiveSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -707,7 +709,7 @@ func ___Directive(ec *executionContext, sel []query.Selection, it *introspection if val == nil { ec.json.Null() } else { - ___InputValue(ec, field.Selections, val) + ec.___InputValue(field.Selections, val) } } ec.json.EndArray() @@ -720,7 +722,7 @@ func ___Directive(ec *executionContext, sel []query.Selection, it *introspection } // nolint: gocyclo, errcheck, gas, goconst -func ___EnumValue(ec *executionContext, sel []query.Selection, it *introspection.EnumValue) { +func (ec *executionContext) ___EnumValue(sel []query.Selection, it *introspection.EnumValue) { groupedFieldSet := ec.collectFields(sel, __EnumValueSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -764,7 +766,7 @@ func ___EnumValue(ec *executionContext, sel []query.Selection, it *introspection } // nolint: gocyclo, errcheck, gas, goconst -func ___Field(ec *executionContext, sel []query.Selection, it *introspection.Field) { +func (ec *executionContext) ___Field(sel []query.Selection, it *introspection.Field) { groupedFieldSet := ec.collectFields(sel, __FieldSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -793,7 +795,7 @@ func ___Field(ec *executionContext, sel []query.Selection, it *introspection.Fie if val == nil { ec.json.Null() } else { - ___InputValue(ec, field.Selections, val) + ec.___InputValue(field.Selections, val) } } ec.json.EndArray() @@ -805,7 +807,7 @@ func ___Field(ec *executionContext, sel []query.Selection, it *introspection.Fie if res == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, res) + ec.___Type(field.Selections, res) } continue @@ -832,7 +834,7 @@ func ___Field(ec *executionContext, sel []query.Selection, it *introspection.Fie } // nolint: gocyclo, errcheck, gas, goconst -func ___InputValue(ec *executionContext, sel []query.Selection, it *introspection.InputValue) { +func (ec *executionContext) ___InputValue(sel []query.Selection, it *introspection.InputValue) { groupedFieldSet := ec.collectFields(sel, __InputValueSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -859,7 +861,7 @@ func ___InputValue(ec *executionContext, sel []query.Selection, it *introspectio if res == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, res) + ec.___Type(field.Selections, res) } continue @@ -880,7 +882,7 @@ func ___InputValue(ec *executionContext, sel []query.Selection, it *introspectio } // nolint: gocyclo, errcheck, gas, goconst -func ___Schema(ec *executionContext, sel []query.Selection, it *introspection.Schema) { +func (ec *executionContext) ___Schema(sel []query.Selection, it *introspection.Schema) { groupedFieldSet := ec.collectFields(sel, __SchemaSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -893,7 +895,7 @@ func ___Schema(ec *executionContext, sel []query.Selection, it *introspection.Sc if val == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, val) + ec.___Type(field.Selections, val) } } ec.json.EndArray() @@ -905,7 +907,7 @@ func ___Schema(ec *executionContext, sel []query.Selection, it *introspection.Sc if res == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, res) + ec.___Type(field.Selections, res) } continue @@ -915,7 +917,7 @@ func ___Schema(ec *executionContext, sel []query.Selection, it *introspection.Sc if res == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, res) + ec.___Type(field.Selections, res) } continue @@ -925,7 +927,7 @@ func ___Schema(ec *executionContext, sel []query.Selection, it *introspection.Sc if res == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, res) + ec.___Type(field.Selections, res) } continue @@ -937,7 +939,7 @@ func ___Schema(ec *executionContext, sel []query.Selection, it *introspection.Sc if val == nil { ec.json.Null() } else { - ___Directive(ec, field.Selections, val) + ec.___Directive(field.Selections, val) } } ec.json.EndArray() @@ -950,7 +952,7 @@ func ___Schema(ec *executionContext, sel []query.Selection, it *introspection.Sc } // nolint: gocyclo, errcheck, gas, goconst -func ___Type(ec *executionContext, sel []query.Selection, it *introspection.Type) { +func (ec *executionContext) ___Type(sel []query.Selection, it *introspection.Type) { groupedFieldSet := ec.collectFields(sel, __TypeSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -996,7 +998,7 @@ func ___Type(ec *executionContext, sel []query.Selection, it *introspection.Type if val == nil { ec.json.Null() } else { - ___Field(ec, field.Selections, val) + ec.___Field(field.Selections, val) } } ec.json.EndArray() @@ -1014,7 +1016,7 @@ func ___Type(ec *executionContext, sel []query.Selection, it *introspection.Type if val == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, val) + ec.___Type(field.Selections, val) } } ec.json.EndArray() @@ -1032,7 +1034,7 @@ func ___Type(ec *executionContext, sel []query.Selection, it *introspection.Type if val == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, val) + ec.___Type(field.Selections, val) } } ec.json.EndArray() @@ -1054,7 +1056,7 @@ func ___Type(ec *executionContext, sel []query.Selection, it *introspection.Type if val == nil { ec.json.Null() } else { - ___EnumValue(ec, field.Selections, val) + ec.___EnumValue(field.Selections, val) } } ec.json.EndArray() @@ -1072,7 +1074,7 @@ func ___Type(ec *executionContext, sel []query.Selection, it *introspection.Type if val == nil { ec.json.Null() } else { - ___InputValue(ec, field.Selections, val) + ec.___InputValue(field.Selections, val) } } ec.json.EndArray() @@ -1085,7 +1087,7 @@ func ___Type(ec *executionContext, sel []query.Selection, it *introspection.Type if res == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, res) + ec.___Type(field.Selections, res) } continue @@ -1134,9 +1136,9 @@ func NewResolver(resolvers Resolvers) relay.Resolver { c.json.ObjectKey("data") if op.Type == query.Query { - _query(&c, op.Selections, nil) + c._query(op.Selections, nil) } else if op.Type == query.Mutation { - _mutation(&c, op.Selections, nil) + c._mutation(op.Selections, nil) } else { c.Errorf("unsupported operation %s", op.Type) c.json.Null() @@ -1161,11 +1163,11 @@ type executionContext struct { ctx context.Context } -func (c *executionContext) introspectSchema() *introspection.Schema { +func (ec *executionContext) introspectSchema() *introspection.Schema { return introspection.WrapSchema(parsedSchema) } -func (c *executionContext) introspectType(name string) *introspection.Type { +func (ec *executionContext) introspectType(name string) *introspection.Type { t := parsedSchema.Resolve(name) if t == nil { return nil @@ -1182,7 +1184,7 @@ func instanceOf(val string, satisfies []string) bool { return false } -func (c *executionContext) collectFields(selSet []query.Selection, satisfies []string, visited map[string]bool) []collectedField { +func (ec *executionContext) collectFields(selSet []query.Selection, satisfies []string, visited map[string]bool) []collectedField { var groupedFields []collectedField for _, sel := range selSet { @@ -1196,7 +1198,7 @@ func (c *executionContext) collectFields(selSet []query.Selection, satisfies []s if len(sel.Arguments) > 0 { f.Args = map[string]interface{}{} for _, arg := range sel.Arguments { - f.Args[arg.Name.Name] = arg.Value.Value(c.variables) + f.Args[arg.Name.Name] = arg.Value.Value(ec.variables) } } return f @@ -1208,7 +1210,7 @@ func (c *executionContext) collectFields(selSet []query.Selection, satisfies []s continue } - for _, childField := range c.collectFields(sel.Selections, satisfies, visited) { + for _, childField := range ec.collectFields(sel.Selections, satisfies, visited) { f := getOrCreateField(&groupedFields, childField.Name, func() collectedField { return childField }) f.Selections = append(f.Selections, childField.Selections...) } @@ -1220,9 +1222,9 @@ func (c *executionContext) collectFields(selSet []query.Selection, satisfies []s } visited[fragmentName] = true - fragment := c.doc.Fragments.Get(fragmentName) + fragment := ec.doc.Fragments.Get(fragmentName) if fragment == nil { - c.Errorf("missing fragment %s", fragmentName) + ec.Errorf("missing fragment %s", fragmentName) continue } @@ -1230,7 +1232,7 @@ func (c *executionContext) collectFields(selSet []query.Selection, satisfies []s continue } - for _, childField := range c.collectFields(fragment.Selections, satisfies, visited) { + for _, childField := range ec.collectFields(fragment.Selections, satisfies, visited) { f := getOrCreateField(&groupedFields, childField.Name, func() collectedField { return childField }) f.Selections = append(f.Selections, childField.Selections...) } diff --git a/example/todo/gen/generated.go b/example/todo/gen/generated.go index 1a98b459121..3f5294a004e 100644 --- a/example/todo/gen/generated.go +++ b/example/todo/gen/generated.go @@ -1,3 +1,5 @@ +// This file was generated by github.com/vektah/graphql-go, DO NOT EDIT + package gen import ( @@ -37,7 +39,7 @@ var ( ) // nolint: gocyclo, errcheck, gas, goconst -func _myMutation(ec *executionContext, sel []query.Selection, it *interface{}) { +func (ec *executionContext) _myMutation(sel []query.Selection, it *interface{}) { groupedFieldSet := ec.collectFields(sel, myMutationSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -53,7 +55,7 @@ func _myMutation(ec *executionContext, sel []query.Selection, it *interface{}) { ec.Error(err) continue } - _todo(ec, field.Selections, &res) + ec._todo(field.Selections, &res) continue case "updateTodo": @@ -71,7 +73,7 @@ func _myMutation(ec *executionContext, sel []query.Selection, it *interface{}) { ec.Error(err) continue } - _todo(ec, field.Selections, &res) + ec._todo(field.Selections, &res) continue } @@ -81,7 +83,7 @@ func _myMutation(ec *executionContext, sel []query.Selection, it *interface{}) { } // nolint: gocyclo, errcheck, gas, goconst -func _myQuery(ec *executionContext, sel []query.Selection, it *interface{}) { +func (ec *executionContext) _myQuery(sel []query.Selection, it *interface{}) { groupedFieldSet := ec.collectFields(sel, myQuerySatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -100,7 +102,7 @@ func _myQuery(ec *executionContext, sel []query.Selection, it *interface{}) { if res == nil { ec.json.Null() } else { - _todo(ec, field.Selections, res) + ec._todo(field.Selections, res) } continue @@ -114,7 +116,7 @@ func _myQuery(ec *executionContext, sel []query.Selection, it *interface{}) { if res == nil { ec.json.Null() } else { - _todo(ec, field.Selections, res) + ec._todo(field.Selections, res) } continue @@ -127,7 +129,7 @@ func _myQuery(ec *executionContext, sel []query.Selection, it *interface{}) { } ec.json.BeginArray() for _, val := range res { - _todo(ec, field.Selections, &val) + ec._todo(field.Selections, &val) } ec.json.EndArray() continue @@ -138,7 +140,7 @@ func _myQuery(ec *executionContext, sel []query.Selection, it *interface{}) { if res == nil { ec.json.Null() } else { - ___Schema(ec, field.Selections, res) + ec.___Schema(field.Selections, res) } continue @@ -152,7 +154,7 @@ func _myQuery(ec *executionContext, sel []query.Selection, it *interface{}) { if res == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, res) + ec.___Type(field.Selections, res) } continue @@ -163,7 +165,7 @@ func _myQuery(ec *executionContext, sel []query.Selection, it *interface{}) { } // nolint: gocyclo, errcheck, gas, goconst -func _todo(ec *executionContext, sel []query.Selection, it *todo.Todo) { +func (ec *executionContext) _todo(sel []query.Selection, it *todo.Todo) { groupedFieldSet := ec.collectFields(sel, todoSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -193,7 +195,7 @@ func _todo(ec *executionContext, sel []query.Selection, it *todo.Todo) { } // nolint: gocyclo, errcheck, gas, goconst -func ___Directive(ec *executionContext, sel []query.Selection, it *introspection.Directive) { +func (ec *executionContext) ___Directive(sel []query.Selection, it *introspection.Directive) { groupedFieldSet := ec.collectFields(sel, __DirectiveSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -232,7 +234,7 @@ func ___Directive(ec *executionContext, sel []query.Selection, it *introspection if val == nil { ec.json.Null() } else { - ___InputValue(ec, field.Selections, val) + ec.___InputValue(field.Selections, val) } } ec.json.EndArray() @@ -245,7 +247,7 @@ func ___Directive(ec *executionContext, sel []query.Selection, it *introspection } // nolint: gocyclo, errcheck, gas, goconst -func ___EnumValue(ec *executionContext, sel []query.Selection, it *introspection.EnumValue) { +func (ec *executionContext) ___EnumValue(sel []query.Selection, it *introspection.EnumValue) { groupedFieldSet := ec.collectFields(sel, __EnumValueSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -289,7 +291,7 @@ func ___EnumValue(ec *executionContext, sel []query.Selection, it *introspection } // nolint: gocyclo, errcheck, gas, goconst -func ___Field(ec *executionContext, sel []query.Selection, it *introspection.Field) { +func (ec *executionContext) ___Field(sel []query.Selection, it *introspection.Field) { groupedFieldSet := ec.collectFields(sel, __FieldSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -318,7 +320,7 @@ func ___Field(ec *executionContext, sel []query.Selection, it *introspection.Fie if val == nil { ec.json.Null() } else { - ___InputValue(ec, field.Selections, val) + ec.___InputValue(field.Selections, val) } } ec.json.EndArray() @@ -330,7 +332,7 @@ func ___Field(ec *executionContext, sel []query.Selection, it *introspection.Fie if res == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, res) + ec.___Type(field.Selections, res) } continue @@ -357,7 +359,7 @@ func ___Field(ec *executionContext, sel []query.Selection, it *introspection.Fie } // nolint: gocyclo, errcheck, gas, goconst -func ___InputValue(ec *executionContext, sel []query.Selection, it *introspection.InputValue) { +func (ec *executionContext) ___InputValue(sel []query.Selection, it *introspection.InputValue) { groupedFieldSet := ec.collectFields(sel, __InputValueSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -384,7 +386,7 @@ func ___InputValue(ec *executionContext, sel []query.Selection, it *introspectio if res == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, res) + ec.___Type(field.Selections, res) } continue @@ -405,7 +407,7 @@ func ___InputValue(ec *executionContext, sel []query.Selection, it *introspectio } // nolint: gocyclo, errcheck, gas, goconst -func ___Schema(ec *executionContext, sel []query.Selection, it *introspection.Schema) { +func (ec *executionContext) ___Schema(sel []query.Selection, it *introspection.Schema) { groupedFieldSet := ec.collectFields(sel, __SchemaSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -418,7 +420,7 @@ func ___Schema(ec *executionContext, sel []query.Selection, it *introspection.Sc if val == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, val) + ec.___Type(field.Selections, val) } } ec.json.EndArray() @@ -430,7 +432,7 @@ func ___Schema(ec *executionContext, sel []query.Selection, it *introspection.Sc if res == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, res) + ec.___Type(field.Selections, res) } continue @@ -440,7 +442,7 @@ func ___Schema(ec *executionContext, sel []query.Selection, it *introspection.Sc if res == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, res) + ec.___Type(field.Selections, res) } continue @@ -450,7 +452,7 @@ func ___Schema(ec *executionContext, sel []query.Selection, it *introspection.Sc if res == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, res) + ec.___Type(field.Selections, res) } continue @@ -462,7 +464,7 @@ func ___Schema(ec *executionContext, sel []query.Selection, it *introspection.Sc if val == nil { ec.json.Null() } else { - ___Directive(ec, field.Selections, val) + ec.___Directive(field.Selections, val) } } ec.json.EndArray() @@ -475,7 +477,7 @@ func ___Schema(ec *executionContext, sel []query.Selection, it *introspection.Sc } // nolint: gocyclo, errcheck, gas, goconst -func ___Type(ec *executionContext, sel []query.Selection, it *introspection.Type) { +func (ec *executionContext) ___Type(sel []query.Selection, it *introspection.Type) { groupedFieldSet := ec.collectFields(sel, __TypeSatisfies, map[string]bool{}) ec.json.BeginObject() for _, field := range groupedFieldSet { @@ -521,7 +523,7 @@ func ___Type(ec *executionContext, sel []query.Selection, it *introspection.Type if val == nil { ec.json.Null() } else { - ___Field(ec, field.Selections, val) + ec.___Field(field.Selections, val) } } ec.json.EndArray() @@ -539,7 +541,7 @@ func ___Type(ec *executionContext, sel []query.Selection, it *introspection.Type if val == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, val) + ec.___Type(field.Selections, val) } } ec.json.EndArray() @@ -557,7 +559,7 @@ func ___Type(ec *executionContext, sel []query.Selection, it *introspection.Type if val == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, val) + ec.___Type(field.Selections, val) } } ec.json.EndArray() @@ -579,7 +581,7 @@ func ___Type(ec *executionContext, sel []query.Selection, it *introspection.Type if val == nil { ec.json.Null() } else { - ___EnumValue(ec, field.Selections, val) + ec.___EnumValue(field.Selections, val) } } ec.json.EndArray() @@ -597,7 +599,7 @@ func ___Type(ec *executionContext, sel []query.Selection, it *introspection.Type if val == nil { ec.json.Null() } else { - ___InputValue(ec, field.Selections, val) + ec.___InputValue(field.Selections, val) } } ec.json.EndArray() @@ -610,7 +612,7 @@ func ___Type(ec *executionContext, sel []query.Selection, it *introspection.Type if res == nil { ec.json.Null() } else { - ___Type(ec, field.Selections, res) + ec.___Type(field.Selections, res) } continue @@ -659,9 +661,9 @@ func NewResolver(resolvers Resolvers) relay.Resolver { c.json.ObjectKey("data") if op.Type == query.Query { - _myQuery(&c, op.Selections, nil) + c._myQuery(op.Selections, nil) } else if op.Type == query.Mutation { - _myMutation(&c, op.Selections, nil) + c._myMutation(op.Selections, nil) } else { c.Errorf("unsupported operation %s", op.Type) c.json.Null() @@ -686,11 +688,11 @@ type executionContext struct { ctx context.Context } -func (c *executionContext) introspectSchema() *introspection.Schema { +func (ec *executionContext) introspectSchema() *introspection.Schema { return introspection.WrapSchema(parsedSchema) } -func (c *executionContext) introspectType(name string) *introspection.Type { +func (ec *executionContext) introspectType(name string) *introspection.Type { t := parsedSchema.Resolve(name) if t == nil { return nil @@ -707,7 +709,7 @@ func instanceOf(val string, satisfies []string) bool { return false } -func (c *executionContext) collectFields(selSet []query.Selection, satisfies []string, visited map[string]bool) []collectedField { +func (ec *executionContext) collectFields(selSet []query.Selection, satisfies []string, visited map[string]bool) []collectedField { var groupedFields []collectedField for _, sel := range selSet { @@ -721,7 +723,7 @@ func (c *executionContext) collectFields(selSet []query.Selection, satisfies []s if len(sel.Arguments) > 0 { f.Args = map[string]interface{}{} for _, arg := range sel.Arguments { - f.Args[arg.Name.Name] = arg.Value.Value(c.variables) + f.Args[arg.Name.Name] = arg.Value.Value(ec.variables) } } return f @@ -733,7 +735,7 @@ func (c *executionContext) collectFields(selSet []query.Selection, satisfies []s continue } - for _, childField := range c.collectFields(sel.Selections, satisfies, visited) { + for _, childField := range ec.collectFields(sel.Selections, satisfies, visited) { f := getOrCreateField(&groupedFields, childField.Name, func() collectedField { return childField }) f.Selections = append(f.Selections, childField.Selections...) } @@ -745,9 +747,9 @@ func (c *executionContext) collectFields(selSet []query.Selection, satisfies []s } visited[fragmentName] = true - fragment := c.doc.Fragments.Get(fragmentName) + fragment := ec.doc.Fragments.Get(fragmentName) if fragment == nil { - c.Errorf("missing fragment %s", fragmentName) + ec.Errorf("missing fragment %s", fragmentName) continue } @@ -755,7 +757,7 @@ func (c *executionContext) collectFields(selSet []query.Selection, satisfies []s continue } - for _, childField := range c.collectFields(fragment.Selections, satisfies, visited) { + for _, childField := range ec.collectFields(fragment.Selections, satisfies, visited) { f := getOrCreateField(&groupedFields, childField.Name, func() collectedField { return childField }) f.Selections = append(f.Selections, childField.Selections...) }