diff --git a/codegen/config/config_test.go b/codegen/config/config_test.go index d4f94f9c973..6ac5257cfdd 100644 --- a/codegen/config/config_test.go +++ b/codegen/config/config_test.go @@ -87,7 +87,7 @@ func TestConfigCheck(t *testing.T) { err = config.normalize() require.NoError(t, err) - err = config.check() + err = config.Check() require.EqualError(t, err, "filenames exec.go and models.go are in the same directory but have different package definitions") }) } diff --git a/codegen/testdata/cfg/conflictedPackages.yml b/codegen/config/testdata/cfg/conflictedPackages.yml similarity index 100% rename from codegen/testdata/cfg/conflictedPackages.yml rename to codegen/config/testdata/cfg/conflictedPackages.yml diff --git a/codegen/field.go b/codegen/field.go index 1c9c129bf28..1e68ad8ba8f 100644 --- a/codegen/field.go +++ b/codegen/field.go @@ -98,10 +98,10 @@ func (b *builder) bindField(obj *Object, f *Field) error { case obj.Type == config.MapType: return nil case b.Config.Models[obj.Name].Fields[f.Name].FieldName != "": - f.Name = b.Config.Models[obj.Name].Fields[f.Name].FieldName + f.GoFieldName = b.Config.Models[obj.Name].Fields[f.Name].FieldName } - target, err := b.findBindTarget(obj.Type.(*types.Named), f.Name) + target, err := b.findBindTarget(obj.Type.(*types.Named), f.GoFieldName) if err != nil { return err } diff --git a/codegen/generated!.gotpl b/codegen/generated!.gotpl index 31486bd550e..ca9e754929e 100644 --- a/codegen/generated!.gotpl +++ b/codegen/generated!.gotpl @@ -48,7 +48,7 @@ type ComplexityRoot struct { {{ $object.Name|toCamel }} struct { {{ range $field := $object.Fields -}} {{ if not $field.IsReserved -}} - {{ $field.Name|toCamel }} {{ $field.ComplexitySignature }} + {{ $field.GoFieldName }} {{ $field.ComplexitySignature }} {{ end }} {{- end }} } @@ -86,8 +86,8 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in {{ if not $object.IsReserved }} {{ range $field := $object.Fields }} {{ if not $field.IsReserved }} - case "{{$object.Name}}.{{$field.Name}}": - if e.complexity.{{$object.Name|toCamel}}.{{$field.Name|toCamel}} == nil { + case "{{$object.Name}}.{{$field.GoFieldName}}": + if e.complexity.{{$object.Name|toCamel}}.{{$field.GoFieldName}} == nil { break } {{ if $field.Args }} @@ -96,7 +96,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } {{ end }} - return e.complexity.{{$object.Name|toCamel}}.{{$field.Name|toCamel}}(childComplexity{{if $field.Args}}, {{$field.ComplexityArgs}} {{end}}), true + return e.complexity.{{$object.Name|toCamel}}.{{$field.GoFieldName}}(childComplexity{{if $field.Args}}, {{$field.ComplexityArgs}} {{end}}), true {{ end }} {{ end }} {{ end }} diff --git a/codegen/templates/templates.go b/codegen/templates/templates.go index 0282f32c0a2..8522824e5c9 100644 --- a/codegen/templates/templates.go +++ b/codegen/templates/templates.go @@ -229,6 +229,9 @@ func Call(p *types.Func) string { } func ToCamel(s string) string { + if s == "_" { + return "_" + } buffer := make([]rune, 0, len(s)) upper := true lastWasUpper := false @@ -288,6 +291,7 @@ var keywords = []string{ "import", "return", "var", + "_", } // sanitizeKeywords prevents collisions with go keywords for arguments to resolver functions diff --git a/codegen/testserver/generated.go b/codegen/testserver/generated.go index 7bba322c1d7..4a79db8c945 100644 --- a/codegen/testserver/generated.go +++ b/codegen/testserver/generated.go @@ -58,12 +58,12 @@ type ComplexityRoot struct { } EmbeddedPointer struct { - Id func(childComplexity int) int + ID func(childComplexity int) int Title func(childComplexity int) int } Error struct { - Id func(childComplexity int) int + ID func(childComplexity int) int ErrorOnNonRequiredField func(childComplexity int) int ErrorOnRequiredField func(childComplexity int) int NilOnRequiredField func(childComplexity int) int @@ -74,15 +74,15 @@ type ComplexityRoot struct { } InnerObject struct { - Id func(childComplexity int) int + ID func(childComplexity int) int } InvalidIdentifier struct { - Id func(childComplexity int) int + ID func(childComplexity int) int } It struct { - Id func(childComplexity int) int + ID func(childComplexity int) int } ModelMethods struct { @@ -102,7 +102,6 @@ type ComplexityRoot struct { Recursive func(childComplexity int, input *RecursiveInputSlice) int NestedInputs func(childComplexity int, input [][]*OuterInput) int NestedOutputs func(childComplexity int) int - Keywords func(childComplexity int, input *Keywords) int Shapes func(childComplexity int) int ErrorBubble func(childComplexity int) int ModelMethods func(childComplexity int) int @@ -115,7 +114,7 @@ type ComplexityRoot struct { DirectiveInput func(childComplexity int, arg InputDirectives) int InputSlice func(childComplexity int, arg []string) int ShapeUnion func(childComplexity int) int - KeywordArgs func(childComplexity int, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string) int + ValidType func(childComplexity int) int } Rectangle struct { @@ -130,11 +129,18 @@ type ComplexityRoot struct { } User struct { - Id func(childComplexity int) int + ID func(childComplexity int) int Friends func(childComplexity int) int Created func(childComplexity int) int Updated func(childComplexity int) int } + + ValidType struct { + DifferentCase func(childComplexity int) int + DifferentCaseOld func(childComplexity int) int + ValidInputKeywords func(childComplexity int, input *ValidInput) int + ValidArgs func(childComplexity int, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string, _Arg string) int + } } type ForcedResolverResolver interface { @@ -150,7 +156,6 @@ type QueryResolver interface { Recursive(ctx context.Context, input *RecursiveInputSlice) (*bool, error) NestedInputs(ctx context.Context, input [][]*OuterInput) (*bool, error) NestedOutputs(ctx context.Context) ([][]*OuterObject, error) - Keywords(ctx context.Context, input *Keywords) (bool, error) Shapes(ctx context.Context) ([]Shape, error) ErrorBubble(ctx context.Context) (*Error, error) ModelMethods(ctx context.Context) (*ModelMethods, error) @@ -163,7 +168,7 @@ type QueryResolver interface { DirectiveInput(ctx context.Context, arg InputDirectives) (*string, error) InputSlice(ctx context.Context, arg []string) (bool, error) ShapeUnion(ctx context.Context) (ShapeUnion, error) - KeywordArgs(ctx context.Context, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string) (bool, error) + ValidType(ctx context.Context) (*ValidType, error) } type SubscriptionResolver interface { Updated(ctx context.Context) (<-chan string, error) @@ -188,14 +193,14 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in _ = ec switch typeName + "." + field { - case "Circle.radius": + case "Circle.Radius": if e.complexity.Circle.Radius == nil { break } return e.complexity.Circle.Radius(childComplexity), true - case "Circle.area": + case "Circle.Area": if e.complexity.Circle.Area == nil { break } @@ -203,11 +208,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Circle.Area(childComplexity), true case "EmbeddedPointer.ID": - if e.complexity.EmbeddedPointer.Id == nil { + if e.complexity.EmbeddedPointer.ID == nil { break } - return e.complexity.EmbeddedPointer.Id(childComplexity), true + return e.complexity.EmbeddedPointer.ID(childComplexity), true case "EmbeddedPointer.Title": if e.complexity.EmbeddedPointer.Title == nil { @@ -216,105 +221,105 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.EmbeddedPointer.Title(childComplexity), true - case "Error.id": - if e.complexity.Error.Id == nil { + case "Error.ID": + if e.complexity.Error.ID == nil { break } - return e.complexity.Error.Id(childComplexity), true + return e.complexity.Error.ID(childComplexity), true - case "Error.errorOnNonRequiredField": + case "Error.ErrorOnNonRequiredField": if e.complexity.Error.ErrorOnNonRequiredField == nil { break } return e.complexity.Error.ErrorOnNonRequiredField(childComplexity), true - case "Error.errorOnRequiredField": + case "Error.ErrorOnRequiredField": if e.complexity.Error.ErrorOnRequiredField == nil { break } return e.complexity.Error.ErrorOnRequiredField(childComplexity), true - case "Error.nilOnRequiredField": + case "Error.NilOnRequiredField": if e.complexity.Error.NilOnRequiredField == nil { break } return e.complexity.Error.NilOnRequiredField(childComplexity), true - case "ForcedResolver.field": + case "ForcedResolver.Field": if e.complexity.ForcedResolver.Field == nil { break } return e.complexity.ForcedResolver.Field(childComplexity), true - case "InnerObject.id": - if e.complexity.InnerObject.Id == nil { + case "InnerObject.ID": + if e.complexity.InnerObject.ID == nil { break } - return e.complexity.InnerObject.Id(childComplexity), true + return e.complexity.InnerObject.ID(childComplexity), true - case "InvalidIdentifier.id": - if e.complexity.InvalidIdentifier.Id == nil { + case "InvalidIdentifier.ID": + if e.complexity.InvalidIdentifier.ID == nil { break } - return e.complexity.InvalidIdentifier.Id(childComplexity), true + return e.complexity.InvalidIdentifier.ID(childComplexity), true - case "It.id": - if e.complexity.It.Id == nil { + case "It.ID": + if e.complexity.It.ID == nil { break } - return e.complexity.It.Id(childComplexity), true + return e.complexity.It.ID(childComplexity), true - case "ModelMethods.resolverField": + case "ModelMethods.ResolverField": if e.complexity.ModelMethods.ResolverField == nil { break } return e.complexity.ModelMethods.ResolverField(childComplexity), true - case "ModelMethods.noContext": + case "ModelMethods.NoContext": if e.complexity.ModelMethods.NoContext == nil { break } return e.complexity.ModelMethods.NoContext(childComplexity), true - case "ModelMethods.withContext": + case "ModelMethods.WithContext": if e.complexity.ModelMethods.WithContext == nil { break } return e.complexity.ModelMethods.WithContext(childComplexity), true - case "OuterObject.inner": + case "OuterObject.Inner": if e.complexity.OuterObject.Inner == nil { break } return e.complexity.OuterObject.Inner(childComplexity), true - case "Query.invalidIdentifier": + case "Query.InvalidIdentifier": if e.complexity.Query.InvalidIdentifier == nil { break } return e.complexity.Query.InvalidIdentifier(childComplexity), true - case "Query.collision": + case "Query.Collision": if e.complexity.Query.Collision == nil { break } return e.complexity.Query.Collision(childComplexity), true - case "Query.mapInput": + case "Query.MapInput": if e.complexity.Query.MapInput == nil { break } @@ -326,7 +331,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.MapInput(childComplexity, args["input"].(map[string]interface{})), true - case "Query.recursive": + case "Query.Recursive": if e.complexity.Query.Recursive == nil { break } @@ -338,7 +343,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Recursive(childComplexity, args["input"].(*RecursiveInputSlice)), true - case "Query.nestedInputs": + case "Query.NestedInputs": if e.complexity.Query.NestedInputs == nil { break } @@ -350,54 +355,42 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.NestedInputs(childComplexity, args["input"].([][]*OuterInput)), true - case "Query.nestedOutputs": + case "Query.NestedOutputs": if e.complexity.Query.NestedOutputs == nil { break } return e.complexity.Query.NestedOutputs(childComplexity), true - case "Query.keywords": - if e.complexity.Query.Keywords == nil { - break - } - - args, err := ec.field_Query_keywords_args(context.TODO(), rawArgs) - if err != nil { - return 0, false - } - - return e.complexity.Query.Keywords(childComplexity, args["input"].(*Keywords)), true - - case "Query.shapes": + case "Query.Shapes": if e.complexity.Query.Shapes == nil { break } return e.complexity.Query.Shapes(childComplexity), true - case "Query.errorBubble": + case "Query.ErrorBubble": if e.complexity.Query.ErrorBubble == nil { break } return e.complexity.Query.ErrorBubble(childComplexity), true - case "Query.modelMethods": + case "Query.ModelMethods": if e.complexity.Query.ModelMethods == nil { break } return e.complexity.Query.ModelMethods(childComplexity), true - case "Query.valid": + case "Query.Valid": if e.complexity.Query.Valid == nil { break } return e.complexity.Query.Valid(childComplexity), true - case "Query.user": + case "Query.User": if e.complexity.Query.User == nil { break } @@ -409,7 +402,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.User(childComplexity, args["id"].(int)), true - case "Query.nullableArg": + case "Query.NullableArg": if e.complexity.Query.NullableArg == nil { break } @@ -421,7 +414,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.NullableArg(childComplexity, args["arg"].(*int)), true - case "Query.directiveArg": + case "Query.DirectiveArg": if e.complexity.Query.DirectiveArg == nil { break } @@ -433,7 +426,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.DirectiveArg(childComplexity, args["arg"].(string)), true - case "Query.directiveNullableArg": + case "Query.DirectiveNullableArg": if e.complexity.Query.DirectiveNullableArg == nil { break } @@ -445,7 +438,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.DirectiveNullableArg(childComplexity, args["arg"].(*int), args["arg2"].(*int)), true - case "Query.directiveInputNullable": + case "Query.DirectiveInputNullable": if e.complexity.Query.DirectiveInputNullable == nil { break } @@ -457,7 +450,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.DirectiveInputNullable(childComplexity, args["arg"].(*InputDirectives)), true - case "Query.directiveInput": + case "Query.DirectiveInput": if e.complexity.Query.DirectiveInput == nil { break } @@ -469,7 +462,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.DirectiveInput(childComplexity, args["arg"].(InputDirectives)), true - case "Query.inputSlice": + case "Query.InputSlice": if e.complexity.Query.InputSlice == nil { break } @@ -481,88 +474,121 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.InputSlice(childComplexity, args["arg"].([]string)), true - case "Query.shapeUnion": + case "Query.ShapeUnion": if e.complexity.Query.ShapeUnion == nil { break } return e.complexity.Query.ShapeUnion(childComplexity), true - case "Query.keywordArgs": - if e.complexity.Query.KeywordArgs == nil { + case "Query.ValidType": + if e.complexity.Query.ValidType == nil { break } - args, err := ec.field_Query_keywordArgs_args(context.TODO(), rawArgs) - if err != nil { - return 0, false - } + return e.complexity.Query.ValidType(childComplexity), true - return e.complexity.Query.KeywordArgs(childComplexity, args["break"].(string), args["default"].(string), args["func"].(string), args["interface"].(string), args["select"].(string), args["case"].(string), args["defer"].(string), args["go"].(string), args["map"].(string), args["struct"].(string), args["chan"].(string), args["else"].(string), args["goto"].(string), args["package"].(string), args["switch"].(string), args["const"].(string), args["fallthrough"].(string), args["if"].(string), args["range"].(string), args["type"].(string), args["continue"].(string), args["for"].(string), args["import"].(string), args["return"].(string), args["var"].(string)), true - - case "Rectangle.length": + case "Rectangle.Length": if e.complexity.Rectangle.Length == nil { break } return e.complexity.Rectangle.Length(childComplexity), true - case "Rectangle.width": + case "Rectangle.Width": if e.complexity.Rectangle.Width == nil { break } return e.complexity.Rectangle.Width(childComplexity), true - case "Rectangle.area": + case "Rectangle.Area": if e.complexity.Rectangle.Area == nil { break } return e.complexity.Rectangle.Area(childComplexity), true - case "Subscription.updated": + case "Subscription.Updated": if e.complexity.Subscription.Updated == nil { break } return e.complexity.Subscription.Updated(childComplexity), true - case "Subscription.initPayload": + case "Subscription.InitPayload": if e.complexity.Subscription.InitPayload == nil { break } return e.complexity.Subscription.InitPayload(childComplexity), true - case "User.id": - if e.complexity.User.Id == nil { + case "User.ID": + if e.complexity.User.ID == nil { break } - return e.complexity.User.Id(childComplexity), true + return e.complexity.User.ID(childComplexity), true - case "User.friends": + case "User.Friends": if e.complexity.User.Friends == nil { break } return e.complexity.User.Friends(childComplexity), true - case "User.created": + case "User.Created": if e.complexity.User.Created == nil { break } return e.complexity.User.Created(childComplexity), true - case "User.updated": + case "User.Updated": if e.complexity.User.Updated == nil { break } return e.complexity.User.Updated(childComplexity), true + case "ValidType.DifferentCase": + if e.complexity.ValidType.DifferentCase == nil { + break + } + + return e.complexity.ValidType.DifferentCase(childComplexity), true + + case "ValidType.DifferentCaseOld": + if e.complexity.ValidType.DifferentCaseOld == nil { + break + } + + return e.complexity.ValidType.DifferentCaseOld(childComplexity), true + + case "ValidType.ValidInputKeywords": + if e.complexity.ValidType.ValidInputKeywords == nil { + break + } + + args, err := ec.field_ValidType_validInputKeywords_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.ValidType.ValidInputKeywords(childComplexity, args["input"].(*ValidInput)), true + + case "ValidType.ValidArgs": + if e.complexity.ValidType.ValidArgs == nil { + break + } + + args, err := ec.field_ValidType_validArgs_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.ValidType.ValidArgs(childComplexity, args["break"].(string), args["default"].(string), args["func"].(string), args["interface"].(string), args["select"].(string), args["case"].(string), args["defer"].(string), args["go"].(string), args["map"].(string), args["struct"].(string), args["chan"].(string), args["else"].(string), args["goto"].(string), args["package"].(string), args["switch"].(string), args["const"].(string), args["fallthrough"].(string), args["if"].(string), args["range"].(string), args["type"].(string), args["continue"].(string), args["for"].(string), args["import"].(string), args["return"].(string), args["var"].(string), args["_"].(string)), true + } return 0, false } @@ -694,7 +720,6 @@ var parsedSchema = gqlparser.MustLoadSchema( recursive(input: RecursiveInputSlice): Boolean nestedInputs(input: [[OuterInput]] = [[{inner: {id: 1}}]]): Boolean nestedOutputs: [[OuterObject]] - keywords(input: Keywords): Boolean! shapes: [Shape] errorBubble: Error modelMethods: ModelMethods @@ -780,64 +805,6 @@ type InnerObject { id: Int! } -input Keywords { - break: String! - default: String! - func: String! - interface: String! - select: String! - case: String! - defer: String! - go: String! - map: String! - struct: String! - chan: String! - else: String! - goto: String! - package: String! - switch: String! - const: String! - fallthrough: String! - if: String! - range: String! - type: String! - continue: String! - for: String! - import: String! - return: String! - var: String! -} - -extend type Query { - keywordArgs( - break: String!, - default: String!, - func: String!, - interface: String!, - select: String!, - case: String!, - defer: String!, - go: String!, - map: String!, - struct: String!, - chan: String!, - else: String!, - goto: String!, - package: String!, - switch: String!, - const: String!, - fallthrough: String!, - if: String!, - range: String!, - type: String!, - continue: String!, - for: String!, - import: String!, - return: String!, - var: String!, - ): Boolean! -} - interface Shape { area: Float } @@ -870,6 +837,75 @@ enum Status { } scalar Time +`}, + &ast.Source{Name: "validtypes.graphql", Input: `extend type Query { + validType: ValidType +} + +""" These things are all valid, but without care generate invalid go code """ +type ValidType { + differentCase: String! + different_case: String! + validInputKeywords(input: ValidInput): Boolean! + validArgs( + break: String!, + default: String!, + func: String!, + interface: String!, + select: String!, + case: String!, + defer: String!, + go: String!, + map: String!, + struct: String!, + chan: String!, + else: String!, + goto: String!, + package: String!, + switch: String!, + const: String!, + fallthrough: String!, + if: String!, + range: String!, + type: String!, + continue: String!, + for: String!, + import: String!, + return: String!, + var: String!, + _: String!, + ): Boolean! +} + +input ValidInput { + break: String! + default: String! + func: String! + interface: String! + select: String! + case: String! + defer: String! + go: String! + map: String! + struct: String! + chan: String! + else: String! + goto: String! + package: String! + switch: String! + const: String! + fallthrough: String! + if: String! + range: String! + type: String! + continue: String! + for: String! + import: String! + return: String! + var: String! + _: String! +} + `}, ) @@ -1049,7 +1085,77 @@ func (ec *executionContext) field_Query_inputSlice_args(ctx context.Context, raw return args, nil } -func (ec *executionContext) field_Query_keywordArgs_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { +func (ec *executionContext) field_Query_mapInput_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 map[string]interface{} + if tmp, ok := rawArgs["input"]; ok { + arg0, err = ec.unmarshalOChanges2map(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_nestedInputs_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 [][]*OuterInput + if tmp, ok := rawArgs["input"]; ok { + arg0, err = ec.unmarshalOOuterInput2ᚕᚕᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterInput(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_nullableArg_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *int + if tmp, ok := rawArgs["arg"]; ok { + arg0, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + if err != nil { + return nil, err + } + } + args["arg"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_recursive_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *RecursiveInputSlice + if tmp, ok := rawArgs["input"]; ok { + arg0, err = ec.unmarshalORecursiveInputSlice2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐRecursiveInputSlice(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_user_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 int + if tmp, ok := rawArgs["id"]; ok { + arg0, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + return args, nil +} + +func (ec *executionContext) field_ValidType_validArgs_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} var arg0 string @@ -1252,29 +1358,23 @@ func (ec *executionContext) field_Query_keywordArgs_args(ctx context.Context, ra } } args["var"] = arg24 - return args, nil -} - -func (ec *executionContext) field_Query_keywords_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { - var err error - args := map[string]interface{}{} - var arg0 *Keywords - if tmp, ok := rawArgs["input"]; ok { - arg0, err = ec.unmarshalOKeywords2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐKeywords(ctx, tmp) + var arg25 string + if tmp, ok := rawArgs["_"]; ok { + arg25, err = ec.unmarshalNString2string(ctx, tmp) if err != nil { return nil, err } } - args["input"] = arg0 + args["_"] = arg25 return args, nil } -func (ec *executionContext) field_Query_mapInput_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { +func (ec *executionContext) field_ValidType_validInputKeywords_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 map[string]interface{} + var arg0 *ValidInput if tmp, ok := rawArgs["input"]; ok { - arg0, err = ec.unmarshalOChanges2map(ctx, tmp) + arg0, err = ec.unmarshalOValidInput2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐValidInput(ctx, tmp) if err != nil { return nil, err } @@ -1283,62 +1383,6 @@ func (ec *executionContext) field_Query_mapInput_args(ctx context.Context, rawAr return args, nil } -func (ec *executionContext) field_Query_nestedInputs_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { - var err error - args := map[string]interface{}{} - var arg0 [][]*OuterInput - if tmp, ok := rawArgs["input"]; ok { - arg0, err = ec.unmarshalOOuterInput2ᚕᚕᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterInput(ctx, tmp) - if err != nil { - return nil, err - } - } - args["input"] = arg0 - return args, nil -} - -func (ec *executionContext) field_Query_nullableArg_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { - var err error - args := map[string]interface{}{} - var arg0 *int - if tmp, ok := rawArgs["arg"]; ok { - arg0, err = ec.unmarshalOInt2ᚖint(ctx, tmp) - if err != nil { - return nil, err - } - } - args["arg"] = arg0 - return args, nil -} - -func (ec *executionContext) field_Query_recursive_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { - var err error - args := map[string]interface{}{} - var arg0 *RecursiveInputSlice - if tmp, ok := rawArgs["input"]; ok { - arg0, err = ec.unmarshalORecursiveInputSlice2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐRecursiveInputSlice(ctx, tmp) - if err != nil { - return nil, err - } - } - args["input"] = arg0 - return args, nil -} - -func (ec *executionContext) field_Query_user_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { - var err error - args := map[string]interface{}{} - var arg0 int - if tmp, ok := rawArgs["id"]; ok { - arg0, err = ec.unmarshalNInt2int(ctx, tmp) - if err != nil { - return nil, err - } - } - args["id"] = arg0 - return args, nil -} - func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -1913,52 +1957,19 @@ func (ec *executionContext) _Query_nestedOutputs(ctx context.Context, field grap Field: field, Args: nil, } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().NestedOutputs(rctx) - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.([][]*OuterObject) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalOOuterObject2ᚕᚕᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterObject(ctx, field.Selections, res) -} - -func (ec *executionContext) _Query_keywords(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Query", - Field: field, - Args: nil, - } - ctx = graphql.WithResolverContext(ctx, rctx) - rawArgs := field.ArgumentMap(ec.Variables) - args, err := ec.field_Query_keywords_args(ctx, rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - rctx.Args = args + ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Keywords(rctx, args["input"].(*Keywords)) + return ec.resolvers.Query().NestedOutputs(rctx) }) if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.(bool) + res := resTmp.([][]*OuterObject) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalNBoolean2bool(ctx, field.Selections, res) + return ec.marshalOOuterObject2ᚕᚕᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterObject(ctx, field.Selections, res) } func (ec *executionContext) _Query_shapes(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { @@ -2298,7 +2309,7 @@ func (ec *executionContext) _Query_shapeUnion(ctx context.Context, field graphql return ec.marshalNShapeUnion2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐShapeUnion(ctx, field.Selections, res) } -func (ec *executionContext) _Query_keywordArgs(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query_validType(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -2307,28 +2318,18 @@ func (ec *executionContext) _Query_keywordArgs(ctx context.Context, field graphq Args: nil, } ctx = graphql.WithResolverContext(ctx, rctx) - rawArgs := field.ArgumentMap(ec.Variables) - args, err := ec.field_Query_keywordArgs_args(ctx, rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().KeywordArgs(rctx, args["break"].(string), args["default"].(string), args["func"].(string), args["interface"].(string), args["select"].(string), args["case"].(string), args["defer"].(string), args["go"].(string), args["map"].(string), args["struct"].(string), args["chan"].(string), args["else"].(string), args["goto"].(string), args["package"].(string), args["switch"].(string), args["const"].(string), args["fallthrough"].(string), args["if"].(string), args["range"].(string), args["type"].(string), args["continue"].(string), args["for"].(string), args["import"].(string), args["return"].(string), args["var"].(string)) + return ec.resolvers.Query().ValidType(rctx) }) if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.(bool) + res := resTmp.(*ValidType) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalNBoolean2bool(ctx, field.Selections, res) + return ec.marshalOValidType2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐValidType(ctx, field.Selections, res) } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { @@ -2610,6 +2611,124 @@ func (ec *executionContext) _User_updated(ctx context.Context, field graphql.Col return ec.marshalOTime2ᚖtimeᚐTime(ctx, field.Selections, res) } +func (ec *executionContext) _ValidType_differentCase(ctx context.Context, field graphql.CollectedField, obj *ValidType) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "ValidType", + Field: field, + Args: nil, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DifferentCase, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _ValidType_different_case(ctx context.Context, field graphql.CollectedField, obj *ValidType) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "ValidType", + Field: field, + Args: nil, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DifferentCaseOld, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _ValidType_validInputKeywords(ctx context.Context, field graphql.CollectedField, obj *ValidType) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "ValidType", + Field: field, + Args: nil, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_ValidType_validInputKeywords_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ValidInputKeywords, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _ValidType_validArgs(ctx context.Context, field graphql.CollectedField, obj *ValidType) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "ValidType", + Field: field, + Args: nil, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_ValidType_validArgs_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ValidArgs, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() @@ -3518,8 +3637,44 @@ func (ec *executionContext) unmarshalInputInputDirectives(ctx context.Context, v return it, nil } -func (ec *executionContext) unmarshalInputKeywords(ctx context.Context, v interface{}) (Keywords, error) { - var it Keywords +func (ec *executionContext) unmarshalInputOuterInput(ctx context.Context, v interface{}) (OuterInput, error) { + var it OuterInput + var asMap = v.(map[string]interface{}) + + for k, v := range asMap { + switch k { + case "inner": + var err error + it.Inner, err = ec.unmarshalNInnerInput2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInnerInput(ctx, v) + if err != nil { + return it, err + } + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputRecursiveInputSlice(ctx context.Context, v interface{}) (RecursiveInputSlice, error) { + var it RecursiveInputSlice + var asMap = v.(map[string]interface{}) + + for k, v := range asMap { + switch k { + case "self": + var err error + it.Self, err = ec.unmarshalORecursiveInputSlice2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐRecursiveInputSlice(ctx, v) + if err != nil { + return it, err + } + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputValidInput(ctx context.Context, v interface{}) (ValidInput, error) { + var it ValidInput var asMap = v.(map[string]interface{}) for k, v := range asMap { @@ -3674,39 +3829,9 @@ func (ec *executionContext) unmarshalInputKeywords(ctx context.Context, v interf if err != nil { return it, err } - } - } - - return it, nil -} - -func (ec *executionContext) unmarshalInputOuterInput(ctx context.Context, v interface{}) (OuterInput, error) { - var it OuterInput - var asMap = v.(map[string]interface{}) - - for k, v := range asMap { - switch k { - case "inner": - var err error - it.Inner, err = ec.unmarshalNInnerInput2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInnerInput(ctx, v) - if err != nil { - return it, err - } - } - } - - return it, nil -} - -func (ec *executionContext) unmarshalInputRecursiveInputSlice(ctx context.Context, v interface{}) (RecursiveInputSlice, error) { - var it RecursiveInputSlice - var asMap = v.(map[string]interface{}) - - for k, v := range asMap { - switch k { - case "self": + case "_": var err error - it.Self, err = ec.unmarshalORecursiveInputSlice2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐRecursiveInputSlice(ctx, v) + it.Underscore, err = ec.unmarshalNString2string(ctx, v) if err != nil { return it, err } @@ -4073,15 +4198,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr res = ec._Query_nestedOutputs(ctx, field) return res }) - case "keywords": - field := field - out.Concurrently(i, func() (res graphql.Marshaler) { - res = ec._Query_keywords(ctx, field) - if res == graphql.Null { - invalid = true - } - return res - }) case "shapes": field := field out.Concurrently(i, func() (res graphql.Marshaler) { @@ -4166,13 +4282,10 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } return res }) - case "keywordArgs": + case "validType": field := field out.Concurrently(i, func() (res graphql.Marshaler) { - res = ec._Query_keywordArgs(ctx, field) - if res == graphql.Null { - invalid = true - } + res = ec._Query_validType(ctx, field) return res }) case "__type": @@ -4283,6 +4396,48 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj return out } +var validTypeImplementors = []string{"ValidType"} + +func (ec *executionContext) _ValidType(ctx context.Context, sel ast.SelectionSet, obj *ValidType) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, validTypeImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("ValidType") + case "differentCase": + out.Values[i] = ec._ValidType_differentCase(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "different_case": + out.Values[i] = ec._ValidType_different_case(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "validInputKeywords": + out.Values[i] = ec._ValidType_validInputKeywords(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "validArgs": + out.Values[i] = ec._ValidType_validArgs(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + var __DirectiveImplementors = []string{"__Directive"} func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { @@ -4996,18 +5151,6 @@ func (ec *executionContext) marshalOIt2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋco return ec._It(ctx, sel, v) } -func (ec *executionContext) unmarshalOKeywords2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐKeywords(ctx context.Context, v interface{}) (Keywords, error) { - return ec.unmarshalInputKeywords(ctx, v) -} - -func (ec *executionContext) unmarshalOKeywords2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐKeywords(ctx context.Context, v interface{}) (*Keywords, error) { - if v == nil { - return nil, nil - } - res, err := ec.unmarshalOKeywords2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐKeywords(ctx, v) - return &res, err -} - func (ec *executionContext) marshalOModelMethods2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐModelMethods(ctx context.Context, sel ast.SelectionSet, v ModelMethods) graphql.Marshaler { return ec._ModelMethods(ctx, sel, &v) } @@ -5283,6 +5426,29 @@ func (ec *executionContext) marshalOTime2ᚖtimeᚐTime(ctx context.Context, sel return ec.marshalOTime2timeᚐTime(ctx, sel, *v) } +func (ec *executionContext) unmarshalOValidInput2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐValidInput(ctx context.Context, v interface{}) (ValidInput, error) { + return ec.unmarshalInputValidInput(ctx, v) +} + +func (ec *executionContext) unmarshalOValidInput2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐValidInput(ctx context.Context, v interface{}) (*ValidInput, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOValidInput2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐValidInput(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOValidType2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐValidType(ctx context.Context, sel ast.SelectionSet, v ValidType) graphql.Marshaler { + return ec._ValidType(ctx, sel, &v) +} + +func (ec *executionContext) marshalOValidType2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐValidType(ctx context.Context, sel ast.SelectionSet, v *ValidType) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._ValidType(ctx, sel, v) +} + func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup diff --git a/codegen/testserver/gqlgen.yml b/codegen/testserver/gqlgen.yml index f326e6d0556..c240e129ca9 100644 --- a/codegen/testserver/gqlgen.yml +++ b/codegen/testserver/gqlgen.yml @@ -1,4 +1,5 @@ -schema: schema.graphql +schema: + - "*.graphql" exec: filename: generated.go @@ -40,3 +41,12 @@ models: model: "github.com/99designs/gqlgen/codegen/testserver.EmbeddedPointerModel" ThirdParty: model: "github.com/99designs/gqlgen/codegen/testserver.ThirdParty" + Keywords: + fields: + _: { fieldName: Underscore } + ValidInput: + fields: + _: { fieldName: Underscore } + ValidType: + fields: + different_case: { fieldName: DifferentCaseOld } diff --git a/codegen/testserver/models-gen.go b/codegen/testserver/models-gen.go index 716b09bedea..f0af1136297 100644 --- a/codegen/testserver/models-gen.go +++ b/codegen/testserver/models-gen.go @@ -28,7 +28,22 @@ type InputDirectives struct { ThirdParty *ThirdParty `json:"thirdParty"` } -type Keywords struct { +type OuterInput struct { + Inner InnerInput `json:"inner"` +} + +type OuterObject struct { + Inner InnerObject `json:"inner"` +} + +type User struct { + ID int `json:"id"` + Friends []User `json:"friends"` + Created time.Time `json:"created"` + Updated *time.Time `json:"updated"` +} + +type ValidInput struct { Break string `json:"break"` Default string `json:"default"` Func string `json:"func"` @@ -54,21 +69,15 @@ type Keywords struct { Import string `json:"import"` Return string `json:"return"` Var string `json:"var"` + Underscore string `json:"_"` } -type OuterInput struct { - Inner InnerInput `json:"inner"` -} - -type OuterObject struct { - Inner InnerObject `json:"inner"` -} - -type User struct { - ID int `json:"id"` - Friends []User `json:"friends"` - Created time.Time `json:"created"` - Updated *time.Time `json:"updated"` +// These things are all valid, but without care generate invalid go code +type ValidType struct { + DifferentCase string `json:"differentCase"` + DifferentCaseOld string `json:"different_case"` + ValidInputKeywords bool `json:"validInputKeywords"` + ValidArgs bool `json:"validArgs"` } type Status string diff --git a/codegen/testserver/resolver.go b/codegen/testserver/resolver.go index 20bcaa425fd..190b6c84871 100644 --- a/codegen/testserver/resolver.go +++ b/codegen/testserver/resolver.go @@ -59,9 +59,6 @@ func (r *queryResolver) NestedInputs(ctx context.Context, input [][]*OuterInput) func (r *queryResolver) NestedOutputs(ctx context.Context) ([][]*OuterObject, error) { panic("not implemented") } -func (r *queryResolver) Keywords(ctx context.Context, input *Keywords) (bool, error) { - panic("not implemented") -} func (r *queryResolver) Shapes(ctx context.Context) ([]Shape, error) { panic("not implemented") } @@ -98,7 +95,7 @@ func (r *queryResolver) InputSlice(ctx context.Context, arg []string) (bool, err func (r *queryResolver) ShapeUnion(ctx context.Context) (ShapeUnion, error) { panic("not implemented") } -func (r *queryResolver) KeywordArgs(ctx context.Context, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string) (bool, error) { +func (r *queryResolver) ValidType(ctx context.Context) (*ValidType, error) { panic("not implemented") } diff --git a/codegen/testserver/schema.graphql b/codegen/testserver/schema.graphql index 21da0e9b219..c400847ad97 100644 --- a/codegen/testserver/schema.graphql +++ b/codegen/testserver/schema.graphql @@ -5,7 +5,6 @@ type Query { recursive(input: RecursiveInputSlice): Boolean nestedInputs(input: [[OuterInput]] = [[{inner: {id: 1}}]]): Boolean nestedOutputs: [[OuterObject]] - keywords(input: Keywords): Boolean! shapes: [Shape] errorBubble: Error modelMethods: ModelMethods @@ -91,64 +90,6 @@ type InnerObject { id: Int! } -input Keywords { - break: String! - default: String! - func: String! - interface: String! - select: String! - case: String! - defer: String! - go: String! - map: String! - struct: String! - chan: String! - else: String! - goto: String! - package: String! - switch: String! - const: String! - fallthrough: String! - if: String! - range: String! - type: String! - continue: String! - for: String! - import: String! - return: String! - var: String! -} - -extend type Query { - keywordArgs( - break: String!, - default: String!, - func: String!, - interface: String!, - select: String!, - case: String!, - defer: String!, - go: String!, - map: String!, - struct: String!, - chan: String!, - else: String!, - goto: String!, - package: String!, - switch: String!, - const: String!, - fallthrough: String!, - if: String!, - range: String!, - type: String!, - continue: String!, - for: String!, - import: String!, - return: String!, - var: String!, - ): Boolean! -} - interface Shape { area: Float } diff --git a/codegen/testserver/stub.go b/codegen/testserver/stub.go index d88f0ddbb5a..0a80f2e6844 100644 --- a/codegen/testserver/stub.go +++ b/codegen/testserver/stub.go @@ -23,7 +23,6 @@ type Stub struct { Recursive func(ctx context.Context, input *RecursiveInputSlice) (*bool, error) NestedInputs func(ctx context.Context, input [][]*OuterInput) (*bool, error) NestedOutputs func(ctx context.Context) ([][]*OuterObject, error) - Keywords func(ctx context.Context, input *Keywords) (bool, error) Shapes func(ctx context.Context) ([]Shape, error) ErrorBubble func(ctx context.Context) (*Error, error) ModelMethods func(ctx context.Context) (*ModelMethods, error) @@ -36,7 +35,7 @@ type Stub struct { DirectiveInput func(ctx context.Context, arg InputDirectives) (*string, error) InputSlice func(ctx context.Context, arg []string) (bool, error) ShapeUnion func(ctx context.Context) (ShapeUnion, error) - KeywordArgs func(ctx context.Context, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string) (bool, error) + ValidType func(ctx context.Context) (*ValidType, error) } SubscriptionResolver struct { Updated func(ctx context.Context) (<-chan string, error) @@ -95,9 +94,6 @@ func (r *stubQuery) NestedInputs(ctx context.Context, input [][]*OuterInput) (*b func (r *stubQuery) NestedOutputs(ctx context.Context) ([][]*OuterObject, error) { return r.QueryResolver.NestedOutputs(ctx) } -func (r *stubQuery) Keywords(ctx context.Context, input *Keywords) (bool, error) { - return r.QueryResolver.Keywords(ctx, input) -} func (r *stubQuery) Shapes(ctx context.Context) ([]Shape, error) { return r.QueryResolver.Shapes(ctx) } @@ -134,8 +130,8 @@ func (r *stubQuery) InputSlice(ctx context.Context, arg []string) (bool, error) func (r *stubQuery) ShapeUnion(ctx context.Context) (ShapeUnion, error) { return r.QueryResolver.ShapeUnion(ctx) } -func (r *stubQuery) KeywordArgs(ctx context.Context, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string) (bool, error) { - return r.QueryResolver.KeywordArgs(ctx, breakArg, defaultArg, funcArg, interfaceArg, selectArg, caseArg, deferArg, goArg, mapArg, structArg, chanArg, elseArg, gotoArg, packageArg, switchArg, constArg, fallthroughArg, ifArg, rangeArg, typeArg, continueArg, forArg, importArg, returnArg, varArg) +func (r *stubQuery) ValidType(ctx context.Context) (*ValidType, error) { + return r.QueryResolver.ValidType(ctx) } type stubSubscription struct{ *Stub } diff --git a/codegen/testserver/validtypes.graphql b/codegen/testserver/validtypes.graphql new file mode 100644 index 00000000000..f344a9f2de5 --- /dev/null +++ b/codegen/testserver/validtypes.graphql @@ -0,0 +1,68 @@ +extend type Query { + validType: ValidType +} + +""" These things are all valid, but without care generate invalid go code """ +type ValidType { + differentCase: String! + different_case: String! + validInputKeywords(input: ValidInput): Boolean! + validArgs( + break: String!, + default: String!, + func: String!, + interface: String!, + select: String!, + case: String!, + defer: String!, + go: String!, + map: String!, + struct: String!, + chan: String!, + else: String!, + goto: String!, + package: String!, + switch: String!, + const: String!, + fallthrough: String!, + if: String!, + range: String!, + type: String!, + continue: String!, + for: String!, + import: String!, + return: String!, + var: String!, + _: String!, + ): Boolean! +} + +input ValidInput { + break: String! + default: String! + func: String! + interface: String! + select: String! + case: String! + defer: String! + go: String! + map: String! + struct: String! + chan: String! + else: String! + goto: String! + package: String! + switch: String! + const: String! + fallthrough: String! + if: String! + range: String! + type: String! + continue: String! + for: String! + import: String! + return: String! + var: String! + _: String! +} + diff --git a/codegen/testserver/validtypes_test.go b/codegen/testserver/validtypes_test.go new file mode 100644 index 00000000000..7c6df2fafec --- /dev/null +++ b/codegen/testserver/validtypes_test.go @@ -0,0 +1,38 @@ +package testserver + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/require" +) + +func TestValidType(t *testing.T) { + resolvers := &Stub{} + resolvers.QueryResolver.ValidType = func(ctx context.Context) (validType *ValidType, e error) { + return &ValidType{ + DifferentCase: "new", + DifferentCaseOld: "old", + }, nil + } + + srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers}))) + c := client.New(srv.URL) + + t.Run("fields with differing cases can be distinguished", func(t *testing.T) { + var resp struct { + ValidType struct { + New string `json:"differentCase"` + Old string `json:"different_case"` + } + } + err := c.Post(`query { validType { differentCase, different_case } }`, &resp) + require.NoError(t, err) + + require.Equal(t, "new", resp.ValidType.New) + require.Equal(t, "old", resp.ValidType.Old) + }) +} diff --git a/example/chat/generated.go b/example/chat/generated.go index fa4c1334332..21c7d263de1 100644 --- a/example/chat/generated.go +++ b/example/chat/generated.go @@ -50,7 +50,7 @@ type ComplexityRoot struct { } Message struct { - Id func(childComplexity int) int + ID func(childComplexity int) int Text func(childComplexity int) int CreatedBy func(childComplexity int) int CreatedAt func(childComplexity int) int @@ -94,49 +94,49 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in _ = ec switch typeName + "." + field { - case "Chatroom.name": + case "Chatroom.Name": if e.complexity.Chatroom.Name == nil { break } return e.complexity.Chatroom.Name(childComplexity), true - case "Chatroom.messages": + case "Chatroom.Messages": if e.complexity.Chatroom.Messages == nil { break } return e.complexity.Chatroom.Messages(childComplexity), true - case "Message.id": - if e.complexity.Message.Id == nil { + case "Message.ID": + if e.complexity.Message.ID == nil { break } - return e.complexity.Message.Id(childComplexity), true + return e.complexity.Message.ID(childComplexity), true - case "Message.text": + case "Message.Text": if e.complexity.Message.Text == nil { break } return e.complexity.Message.Text(childComplexity), true - case "Message.createdBy": + case "Message.CreatedBy": if e.complexity.Message.CreatedBy == nil { break } return e.complexity.Message.CreatedBy(childComplexity), true - case "Message.createdAt": + case "Message.CreatedAt": if e.complexity.Message.CreatedAt == nil { break } return e.complexity.Message.CreatedAt(childComplexity), true - case "Mutation.post": + case "Mutation.Post": if e.complexity.Mutation.Post == nil { break } @@ -148,7 +148,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.Post(childComplexity, args["text"].(string), args["username"].(string), args["roomName"].(string)), true - case "Query.room": + case "Query.Room": if e.complexity.Query.Room == nil { break } @@ -160,7 +160,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Room(childComplexity, args["name"].(string)), true - case "Subscription.messageAdded": + case "Subscription.MessageAdded": if e.complexity.Subscription.MessageAdded == nil { break } diff --git a/example/config/generated.go b/example/config/generated.go index 17e04c5d0bc..b7337bb00e7 100644 --- a/example/config/generated.go +++ b/example/config/generated.go @@ -51,15 +51,15 @@ type ComplexityRoot struct { } Todo struct { - Id func(childComplexity int) int - DatabaseId func(childComplexity int) int + ID func(childComplexity int) int + DatabaseID func(childComplexity int) int Description func(childComplexity int) int Done func(childComplexity int) int User func(childComplexity int) int } User struct { - Id func(childComplexity int) int + ID func(childComplexity int) int FullName func(childComplexity int) int } } @@ -89,7 +89,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in _ = ec switch typeName + "." + field { - case "Mutation.createTodo": + case "Mutation.CreateTodo": if e.complexity.Mutation.CreateTodo == nil { break } @@ -101,26 +101,26 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.CreateTodo(childComplexity, args["input"].(NewTodo)), true - case "Query.todos": + case "Query.Todos": if e.complexity.Query.Todos == nil { break } return e.complexity.Query.Todos(childComplexity), true - case "Todo.id": - if e.complexity.Todo.Id == nil { + case "Todo.ID": + if e.complexity.Todo.ID == nil { break } - return e.complexity.Todo.Id(childComplexity), true + return e.complexity.Todo.ID(childComplexity), true - case "Todo.databaseId": - if e.complexity.Todo.DatabaseId == nil { + case "Todo.DatabaseID": + if e.complexity.Todo.DatabaseID == nil { break } - return e.complexity.Todo.DatabaseId(childComplexity), true + return e.complexity.Todo.DatabaseID(childComplexity), true case "Todo.Description": if e.complexity.Todo.Description == nil { @@ -129,26 +129,26 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Todo.Description(childComplexity), true - case "Todo.done": + case "Todo.Done": if e.complexity.Todo.Done == nil { break } return e.complexity.Todo.Done(childComplexity), true - case "Todo.user": + case "Todo.User": if e.complexity.Todo.User == nil { break } return e.complexity.Todo.User(childComplexity), true - case "User.id": - if e.complexity.User.Id == nil { + case "User.ID": + if e.complexity.User.ID == nil { break } - return e.complexity.User.Id(childComplexity), true + return e.complexity.User.ID(childComplexity), true case "User.FullName": if e.complexity.User.FullName == nil { @@ -491,7 +491,7 @@ func (ec *executionContext) _Todo_databaseId(ctx context.Context, field graphql. return ec.marshalNInt2int(ctx, field.Selections, res) } -func (ec *executionContext) _Todo_Description(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { +func (ec *executionContext) _Todo_text(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -595,7 +595,7 @@ func (ec *executionContext) _User_id(ctx context.Context, field graphql.Collecte return ec.marshalNID2string(ctx, field.Selections, res) } -func (ec *executionContext) _User_FullName(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { +func (ec *executionContext) _User_name(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1432,7 +1432,7 @@ func (ec *executionContext) unmarshalInputNewTodo(ctx context.Context, v interfa if err != nil { return it, err } - case "UserID": + case "userId": var err error it.UserID, err = ec.unmarshalNString2string(ctx, v) if err != nil { @@ -1547,8 +1547,8 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { invalid = true } - case "Description": - out.Values[i] = ec._Todo_Description(ctx, field, obj) + case "text": + out.Values[i] = ec._Todo_text(ctx, field, obj) if out.Values[i] == graphql.Null { invalid = true } @@ -1589,8 +1589,8 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { invalid = true } - case "FullName": - out.Values[i] = ec._User_FullName(ctx, field, obj) + case "name": + out.Values[i] = ec._User_name(ctx, field, obj) if out.Values[i] == graphql.Null { invalid = true } diff --git a/example/config/resolver.go b/example/config/resolver.go index c089094fa33..02d59e09037 100644 --- a/example/config/resolver.go +++ b/example/config/resolver.go @@ -60,6 +60,10 @@ func (r *queryResolver) Todos(ctx context.Context) ([]Todo, error) { type todoResolver struct{ *Resolver } +func (r *todoResolver) Description(ctx context.Context, obj *Todo) (string, error) { + panic("implement me") +} + func (r *todoResolver) ID(ctx context.Context, obj *Todo) (string, error) { if obj.ID != "" { return obj.ID, nil diff --git a/example/dataloader/generated.go b/example/dataloader/generated.go index 404af1956ef..f09ad400dcd 100644 --- a/example/dataloader/generated.go +++ b/example/dataloader/generated.go @@ -44,13 +44,13 @@ type DirectiveRoot struct { type ComplexityRoot struct { Address struct { - Id func(childComplexity int) int + ID func(childComplexity int) int Street func(childComplexity int) int Country func(childComplexity int) int } Customer struct { - Id func(childComplexity int) int + ID func(childComplexity int) int Name func(childComplexity int) int Address func(childComplexity int) int Orders func(childComplexity int) int @@ -61,7 +61,7 @@ type ComplexityRoot struct { } Order struct { - Id func(childComplexity int) int + ID func(childComplexity int) int Date func(childComplexity int) int Amount func(childComplexity int) int Items func(childComplexity int) int @@ -102,98 +102,98 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in _ = ec switch typeName + "." + field { - case "Address.id": - if e.complexity.Address.Id == nil { + case "Address.ID": + if e.complexity.Address.ID == nil { break } - return e.complexity.Address.Id(childComplexity), true + return e.complexity.Address.ID(childComplexity), true - case "Address.street": + case "Address.Street": if e.complexity.Address.Street == nil { break } return e.complexity.Address.Street(childComplexity), true - case "Address.country": + case "Address.Country": if e.complexity.Address.Country == nil { break } return e.complexity.Address.Country(childComplexity), true - case "Customer.id": - if e.complexity.Customer.Id == nil { + case "Customer.ID": + if e.complexity.Customer.ID == nil { break } - return e.complexity.Customer.Id(childComplexity), true + return e.complexity.Customer.ID(childComplexity), true - case "Customer.name": + case "Customer.Name": if e.complexity.Customer.Name == nil { break } return e.complexity.Customer.Name(childComplexity), true - case "Customer.address": + case "Customer.Address": if e.complexity.Customer.Address == nil { break } return e.complexity.Customer.Address(childComplexity), true - case "Customer.orders": + case "Customer.Orders": if e.complexity.Customer.Orders == nil { break } return e.complexity.Customer.Orders(childComplexity), true - case "Item.name": + case "Item.Name": if e.complexity.Item.Name == nil { break } return e.complexity.Item.Name(childComplexity), true - case "Order.id": - if e.complexity.Order.Id == nil { + case "Order.ID": + if e.complexity.Order.ID == nil { break } - return e.complexity.Order.Id(childComplexity), true + return e.complexity.Order.ID(childComplexity), true - case "Order.date": + case "Order.Date": if e.complexity.Order.Date == nil { break } return e.complexity.Order.Date(childComplexity), true - case "Order.amount": + case "Order.Amount": if e.complexity.Order.Amount == nil { break } return e.complexity.Order.Amount(childComplexity), true - case "Order.items": + case "Order.Items": if e.complexity.Order.Items == nil { break } return e.complexity.Order.Items(childComplexity), true - case "Query.customers": + case "Query.Customers": if e.complexity.Query.Customers == nil { break } return e.complexity.Query.Customers(childComplexity), true - case "Query.torture1d": + case "Query.Torture1d": if e.complexity.Query.Torture1d == nil { break } @@ -205,7 +205,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Torture1d(childComplexity, args["customerIds"].([]int)), true - case "Query.torture2d": + case "Query.Torture2d": if e.complexity.Query.Torture2d == nil { break } diff --git a/example/scalars/generated.go b/example/scalars/generated.go index 764500f7466..914a491e015 100644 --- a/example/scalars/generated.go +++ b/example/scalars/generated.go @@ -45,7 +45,7 @@ type DirectiveRoot struct { type ComplexityRoot struct { Address struct { - Id func(childComplexity int) int + ID func(childComplexity int) int Location func(childComplexity int) int } @@ -55,7 +55,7 @@ type ComplexityRoot struct { } User struct { - Id func(childComplexity int) int + ID func(childComplexity int) int Name func(childComplexity int) int Created func(childComplexity int) int IsBanned func(childComplexity int) int @@ -90,21 +90,21 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in _ = ec switch typeName + "." + field { - case "Address.id": - if e.complexity.Address.Id == nil { + case "Address.ID": + if e.complexity.Address.ID == nil { break } - return e.complexity.Address.Id(childComplexity), true + return e.complexity.Address.ID(childComplexity), true - case "Address.location": + case "Address.Location": if e.complexity.Address.Location == nil { break } return e.complexity.Address.Location(childComplexity), true - case "Query.user": + case "Query.User": if e.complexity.Query.User == nil { break } @@ -116,7 +116,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.User(childComplexity, args["id"].(external.ObjectID)), true - case "Query.search": + case "Query.Search": if e.complexity.Query.Search == nil { break } @@ -128,56 +128,56 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Search(childComplexity, args["input"].(*model.SearchArgs)), true - case "User.id": - if e.complexity.User.Id == nil { + case "User.ID": + if e.complexity.User.ID == nil { break } - return e.complexity.User.Id(childComplexity), true + return e.complexity.User.ID(childComplexity), true - case "User.name": + case "User.Name": if e.complexity.User.Name == nil { break } return e.complexity.User.Name(childComplexity), true - case "User.created": + case "User.Created": if e.complexity.User.Created == nil { break } return e.complexity.User.Created(childComplexity), true - case "User.isBanned": + case "User.IsBanned": if e.complexity.User.IsBanned == nil { break } return e.complexity.User.IsBanned(childComplexity), true - case "User.primitiveResolver": + case "User.PrimitiveResolver": if e.complexity.User.PrimitiveResolver == nil { break } return e.complexity.User.PrimitiveResolver(childComplexity), true - case "User.customResolver": + case "User.CustomResolver": if e.complexity.User.CustomResolver == nil { break } return e.complexity.User.CustomResolver(childComplexity), true - case "User.address": + case "User.Address": if e.complexity.User.Address == nil { break } return e.complexity.User.Address(childComplexity), true - case "User.tier": + case "User.Tier": if e.complexity.User.Tier == nil { break } diff --git a/example/selection/generated.go b/example/selection/generated.go index 226225b96a3..3692f5a0e13 100644 --- a/example/selection/generated.go +++ b/example/selection/generated.go @@ -80,63 +80,63 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in _ = ec switch typeName + "." + field { - case "Like.reaction": + case "Like.Reaction": if e.complexity.Like.Reaction == nil { break } return e.complexity.Like.Reaction(childComplexity), true - case "Like.sent": + case "Like.Sent": if e.complexity.Like.Sent == nil { break } return e.complexity.Like.Sent(childComplexity), true - case "Like.selection": + case "Like.Selection": if e.complexity.Like.Selection == nil { break } return e.complexity.Like.Selection(childComplexity), true - case "Like.collected": + case "Like.Collected": if e.complexity.Like.Collected == nil { break } return e.complexity.Like.Collected(childComplexity), true - case "Post.message": + case "Post.Message": if e.complexity.Post.Message == nil { break } return e.complexity.Post.Message(childComplexity), true - case "Post.sent": + case "Post.Sent": if e.complexity.Post.Sent == nil { break } return e.complexity.Post.Sent(childComplexity), true - case "Post.selection": + case "Post.Selection": if e.complexity.Post.Selection == nil { break } return e.complexity.Post.Selection(childComplexity), true - case "Post.collected": + case "Post.Collected": if e.complexity.Post.Collected == nil { break } return e.complexity.Post.Collected(childComplexity), true - case "Query.events": + case "Query.Events": if e.complexity.Query.Events == nil { break } diff --git a/example/starwars/generated.go b/example/starwars/generated.go index 46cfa7f74bd..b460c01e686 100644 --- a/example/starwars/generated.go +++ b/example/starwars/generated.go @@ -48,7 +48,7 @@ type DirectiveRoot struct { type ComplexityRoot struct { Droid struct { - Id func(childComplexity int) int + ID func(childComplexity int) int Name func(childComplexity int) int Friends func(childComplexity int) int FriendsConnection func(childComplexity int, first *int, after *string) int @@ -69,7 +69,7 @@ type ComplexityRoot struct { } Human struct { - Id func(childComplexity int) int + ID func(childComplexity int) int Name func(childComplexity int) int Height func(childComplexity int, unit LengthUnit) int Mass func(childComplexity int) int @@ -106,7 +106,7 @@ type ComplexityRoot struct { } Starship struct { - Id func(childComplexity int) int + ID func(childComplexity int) int Name func(childComplexity int) int Length func(childComplexity int, unit *LengthUnit) int History func(childComplexity int) int @@ -158,28 +158,28 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in _ = ec switch typeName + "." + field { - case "Droid.id": - if e.complexity.Droid.Id == nil { + case "Droid.ID": + if e.complexity.Droid.ID == nil { break } - return e.complexity.Droid.Id(childComplexity), true + return e.complexity.Droid.ID(childComplexity), true - case "Droid.name": + case "Droid.Name": if e.complexity.Droid.Name == nil { break } return e.complexity.Droid.Name(childComplexity), true - case "Droid.friends": + case "Droid.Friends": if e.complexity.Droid.Friends == nil { break } return e.complexity.Droid.Friends(childComplexity), true - case "Droid.friendsConnection": + case "Droid.FriendsConnection": if e.complexity.Droid.FriendsConnection == nil { break } @@ -191,77 +191,77 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Droid.FriendsConnection(childComplexity, args["first"].(*int), args["after"].(*string)), true - case "Droid.appearsIn": + case "Droid.AppearsIn": if e.complexity.Droid.AppearsIn == nil { break } return e.complexity.Droid.AppearsIn(childComplexity), true - case "Droid.primaryFunction": + case "Droid.PrimaryFunction": if e.complexity.Droid.PrimaryFunction == nil { break } return e.complexity.Droid.PrimaryFunction(childComplexity), true - case "FriendsConnection.totalCount": + case "FriendsConnection.TotalCount": if e.complexity.FriendsConnection.TotalCount == nil { break } return e.complexity.FriendsConnection.TotalCount(childComplexity), true - case "FriendsConnection.edges": + case "FriendsConnection.Edges": if e.complexity.FriendsConnection.Edges == nil { break } return e.complexity.FriendsConnection.Edges(childComplexity), true - case "FriendsConnection.friends": + case "FriendsConnection.Friends": if e.complexity.FriendsConnection.Friends == nil { break } return e.complexity.FriendsConnection.Friends(childComplexity), true - case "FriendsConnection.pageInfo": + case "FriendsConnection.PageInfo": if e.complexity.FriendsConnection.PageInfo == nil { break } return e.complexity.FriendsConnection.PageInfo(childComplexity), true - case "FriendsEdge.cursor": + case "FriendsEdge.Cursor": if e.complexity.FriendsEdge.Cursor == nil { break } return e.complexity.FriendsEdge.Cursor(childComplexity), true - case "FriendsEdge.node": + case "FriendsEdge.Node": if e.complexity.FriendsEdge.Node == nil { break } return e.complexity.FriendsEdge.Node(childComplexity), true - case "Human.id": - if e.complexity.Human.Id == nil { + case "Human.ID": + if e.complexity.Human.ID == nil { break } - return e.complexity.Human.Id(childComplexity), true + return e.complexity.Human.ID(childComplexity), true - case "Human.name": + case "Human.Name": if e.complexity.Human.Name == nil { break } return e.complexity.Human.Name(childComplexity), true - case "Human.height": + case "Human.Height": if e.complexity.Human.Height == nil { break } @@ -273,21 +273,21 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Human.Height(childComplexity, args["unit"].(LengthUnit)), true - case "Human.mass": + case "Human.Mass": if e.complexity.Human.Mass == nil { break } return e.complexity.Human.Mass(childComplexity), true - case "Human.friends": + case "Human.Friends": if e.complexity.Human.Friends == nil { break } return e.complexity.Human.Friends(childComplexity), true - case "Human.friendsConnection": + case "Human.FriendsConnection": if e.complexity.Human.FriendsConnection == nil { break } @@ -299,21 +299,21 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Human.FriendsConnection(childComplexity, args["first"].(*int), args["after"].(*string)), true - case "Human.appearsIn": + case "Human.AppearsIn": if e.complexity.Human.AppearsIn == nil { break } return e.complexity.Human.AppearsIn(childComplexity), true - case "Human.starships": + case "Human.Starships": if e.complexity.Human.Starships == nil { break } return e.complexity.Human.Starships(childComplexity), true - case "Mutation.createReview": + case "Mutation.CreateReview": if e.complexity.Mutation.CreateReview == nil { break } @@ -325,28 +325,28 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.CreateReview(childComplexity, args["episode"].(Episode), args["review"].(Review)), true - case "PageInfo.startCursor": + case "PageInfo.StartCursor": if e.complexity.PageInfo.StartCursor == nil { break } return e.complexity.PageInfo.StartCursor(childComplexity), true - case "PageInfo.endCursor": + case "PageInfo.EndCursor": if e.complexity.PageInfo.EndCursor == nil { break } return e.complexity.PageInfo.EndCursor(childComplexity), true - case "PageInfo.hasNextPage": + case "PageInfo.HasNextPage": if e.complexity.PageInfo.HasNextPage == nil { break } return e.complexity.PageInfo.HasNextPage(childComplexity), true - case "Query.hero": + case "Query.Hero": if e.complexity.Query.Hero == nil { break } @@ -358,7 +358,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Hero(childComplexity, args["episode"].(*Episode)), true - case "Query.reviews": + case "Query.Reviews": if e.complexity.Query.Reviews == nil { break } @@ -370,7 +370,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Reviews(childComplexity, args["episode"].(Episode), args["since"].(*time.Time)), true - case "Query.search": + case "Query.Search": if e.complexity.Query.Search == nil { break } @@ -382,7 +382,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Search(childComplexity, args["text"].(string)), true - case "Query.character": + case "Query.Character": if e.complexity.Query.Character == nil { break } @@ -394,7 +394,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Character(childComplexity, args["id"].(string)), true - case "Query.droid": + case "Query.Droid": if e.complexity.Query.Droid == nil { break } @@ -406,7 +406,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Droid(childComplexity, args["id"].(string)), true - case "Query.human": + case "Query.Human": if e.complexity.Query.Human == nil { break } @@ -418,7 +418,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Human(childComplexity, args["id"].(string)), true - case "Query.starship": + case "Query.Starship": if e.complexity.Query.Starship == nil { break } @@ -430,42 +430,42 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Starship(childComplexity, args["id"].(string)), true - case "Review.stars": + case "Review.Stars": if e.complexity.Review.Stars == nil { break } return e.complexity.Review.Stars(childComplexity), true - case "Review.commentary": + case "Review.Commentary": if e.complexity.Review.Commentary == nil { break } return e.complexity.Review.Commentary(childComplexity), true - case "Review.time": + case "Review.Time": if e.complexity.Review.Time == nil { break } return e.complexity.Review.Time(childComplexity), true - case "Starship.id": - if e.complexity.Starship.Id == nil { + case "Starship.ID": + if e.complexity.Starship.ID == nil { break } - return e.complexity.Starship.Id(childComplexity), true + return e.complexity.Starship.ID(childComplexity), true - case "Starship.name": + case "Starship.Name": if e.complexity.Starship.Name == nil { break } return e.complexity.Starship.Name(childComplexity), true - case "Starship.length": + case "Starship.Length": if e.complexity.Starship.Length == nil { break } @@ -477,7 +477,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Starship.Length(childComplexity, args["unit"].(*LengthUnit)), true - case "Starship.history": + case "Starship.History": if e.complexity.Starship.History == nil { break } diff --git a/example/todo/generated.go b/example/todo/generated.go index 97c638394f3..b95f35ea97d 100644 --- a/example/todo/generated.go +++ b/example/todo/generated.go @@ -54,7 +54,7 @@ type ComplexityRoot struct { } Todo struct { - Id func(childComplexity int) int + ID func(childComplexity int) int Text func(childComplexity int) int Done func(childComplexity int) int } @@ -85,7 +85,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in _ = ec switch typeName + "." + field { - case "MyMutation.createTodo": + case "MyMutation.CreateTodo": if e.complexity.MyMutation.CreateTodo == nil { break } @@ -97,7 +97,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MyMutation.CreateTodo(childComplexity, args["todo"].(TodoInput)), true - case "MyMutation.updateTodo": + case "MyMutation.UpdateTodo": if e.complexity.MyMutation.UpdateTodo == nil { break } @@ -109,7 +109,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MyMutation.UpdateTodo(childComplexity, args["id"].(int), args["changes"].(map[string]interface{})), true - case "MyQuery.todo": + case "MyQuery.Todo": if e.complexity.MyQuery.Todo == nil { break } @@ -121,35 +121,35 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MyQuery.Todo(childComplexity, args["id"].(int)), true - case "MyQuery.lastTodo": + case "MyQuery.LastTodo": if e.complexity.MyQuery.LastTodo == nil { break } return e.complexity.MyQuery.LastTodo(childComplexity), true - case "MyQuery.todos": + case "MyQuery.Todos": if e.complexity.MyQuery.Todos == nil { break } return e.complexity.MyQuery.Todos(childComplexity), true - case "Todo.id": - if e.complexity.Todo.Id == nil { + case "Todo.ID": + if e.complexity.Todo.ID == nil { break } - return e.complexity.Todo.Id(childComplexity), true + return e.complexity.Todo.ID(childComplexity), true - case "Todo.text": + case "Todo.Text": if e.complexity.Todo.Text == nil { break } return e.complexity.Todo.Text(childComplexity), true - case "Todo.done": + case "Todo.Done": if e.complexity.Todo.Done == nil { break } diff --git a/example/type-system-extension/generated.go b/example/type-system-extension/generated.go index 190b4c6ba87..d0cfc65866f 100644 --- a/example/type-system-extension/generated.go +++ b/example/type-system-extension/generated.go @@ -65,7 +65,7 @@ type ComplexityRoot struct { } Todo struct { - Id func(childComplexity int) int + ID func(childComplexity int) int Text func(childComplexity int) int State func(childComplexity int) int Verified func(childComplexity int) int @@ -95,7 +95,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in _ = ec switch typeName + "." + field { - case "MyMutation.createTodo": + case "MyMutation.CreateTodo": if e.complexity.MyMutation.CreateTodo == nil { break } @@ -107,14 +107,14 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MyMutation.CreateTodo(childComplexity, args["todo"].(TodoInput)), true - case "MyQuery.todos": + case "MyQuery.Todos": if e.complexity.MyQuery.Todos == nil { break } return e.complexity.MyQuery.Todos(childComplexity), true - case "MyQuery.todo": + case "MyQuery.Todo": if e.complexity.MyQuery.Todo == nil { break } @@ -126,28 +126,28 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MyQuery.Todo(childComplexity, args["id"].(string)), true - case "Todo.id": - if e.complexity.Todo.Id == nil { + case "Todo.ID": + if e.complexity.Todo.ID == nil { break } - return e.complexity.Todo.Id(childComplexity), true + return e.complexity.Todo.ID(childComplexity), true - case "Todo.text": + case "Todo.Text": if e.complexity.Todo.Text == nil { break } return e.complexity.Todo.Text(childComplexity), true - case "Todo.state": + case "Todo.State": if e.complexity.Todo.State == nil { break } return e.complexity.Todo.State(childComplexity), true - case "Todo.verified": + case "Todo.Verified": if e.complexity.Todo.Verified == nil { break } diff --git a/integration/generated.go b/integration/generated.go index 82a43f247e4..d875ecf8426 100644 --- a/integration/generated.go +++ b/integration/generated.go @@ -55,7 +55,7 @@ type ComplexityRoot struct { Path func(childComplexity int) int Date func(childComplexity int, filter models.DateFilter) int Viewer func(childComplexity int) int - JsonEncoding func(childComplexity int) int + JSONEncoding func(childComplexity int) int Error func(childComplexity int, typeArg *models.ErrorType) int } @@ -99,35 +99,35 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in _ = ec switch typeName + "." + field { - case "Element.child": + case "Element.Child": if e.complexity.Element.Child == nil { break } return e.complexity.Element.Child(childComplexity), true - case "Element.error": + case "Element.Error": if e.complexity.Element.Error == nil { break } return e.complexity.Element.Error(childComplexity), true - case "Element.mismatched": + case "Element.Mismatched": if e.complexity.Element.Mismatched == nil { break } return e.complexity.Element.Mismatched(childComplexity), true - case "Query.path": + case "Query.Path": if e.complexity.Query.Path == nil { break } return e.complexity.Query.Path(childComplexity), true - case "Query.date": + case "Query.Date": if e.complexity.Query.Date == nil { break } @@ -139,21 +139,21 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Date(childComplexity, args["filter"].(models.DateFilter)), true - case "Query.viewer": + case "Query.Viewer": if e.complexity.Query.Viewer == nil { break } return e.complexity.Query.Viewer(childComplexity), true - case "Query.jsonEncoding": - if e.complexity.Query.JsonEncoding == nil { + case "Query.JSONEncoding": + if e.complexity.Query.JSONEncoding == nil { break } - return e.complexity.Query.JsonEncoding(childComplexity), true + return e.complexity.Query.JSONEncoding(childComplexity), true - case "Query.error": + case "Query.Error": if e.complexity.Query.Error == nil { break } @@ -165,21 +165,21 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Error(childComplexity, args["type"].(*models.ErrorType)), true - case "User.name": + case "User.Name": if e.complexity.User.Name == nil { break } return e.complexity.User.Name(childComplexity), true - case "User.likes": + case "User.Likes": if e.complexity.User.Likes == nil { break } return e.complexity.User.Likes(childComplexity), true - case "Viewer.user": + case "Viewer.User": if e.complexity.Viewer.User == nil { break }