From c097164a943a9fbbf27b5999426a37401aece17a Mon Sep 17 00:00:00 2001 From: Sean Sorrell Date: Tue, 30 Mar 2021 16:49:50 -0700 Subject: [PATCH] fix compile errors introduced by ab449f07e --- internal/exec/exec.go | 2 +- internal/exec/resolvable/meta.go | 12 +++--------- internal/exec/resolvable/resolvable.go | 14 +++++++------- internal/schema/schema.go | 10 +++++----- internal/schema/schema_internal_test.go | 4 ++-- internal/schema/schema_test.go | 4 ++-- internal/validation/validation.go | 6 +++--- introspection/introspection.go | 2 +- 8 files changed, 24 insertions(+), 30 deletions(-) diff --git a/internal/exec/exec.go b/internal/exec/exec.go index 588c16899..f972359b2 100644 --- a/internal/exec/exec.go +++ b/internal/exec/exec.go @@ -169,7 +169,7 @@ func execFieldSelection(ctx context.Context, r *Request, s *resolvable.Schema, f var result reflect.Value var err *errors.QueryError - traceCtx, finish := r.Tracer.TraceField(ctx, f.field.TraceLabel, f.field.TypeName, f.field.Name.Name, !f.field.Async, f.field.Args) + traceCtx, finish := r.Tracer.TraceField(ctx, f.field.TraceLabel, f.field.TypeName, f.field.Name, !f.field.Async, f.field.Args) defer func() { finish(err) }() diff --git a/internal/exec/resolvable/meta.go b/internal/exec/resolvable/meta.go index d764e60f4..fdf41465d 100644 --- a/internal/exec/resolvable/meta.go +++ b/internal/exec/resolvable/meta.go @@ -39,9 +39,7 @@ func newMeta(s *types.Schema) *Meta { fieldTypename := Field{ FieldDefinition: types.FieldDefinition{ - Name: types.Ident{ - Name: "__typename", - }, + Name: "__typename", Type: &types.NonNull{OfType: s.Types["String"]}, }, TraceLabel: fmt.Sprintf("GraphQL field: __typename"), @@ -49,9 +47,7 @@ func newMeta(s *types.Schema) *Meta { fieldSchema := Field{ FieldDefinition: types.FieldDefinition{ - Name: types.Ident{ - Name: "__schema", - }, + Name: "__schema", Type: s.Types["__Schema"], }, TraceLabel: fmt.Sprintf("GraphQL field: __schema"), @@ -59,9 +55,7 @@ func newMeta(s *types.Schema) *Meta { fieldType := Field{ FieldDefinition: types.FieldDefinition{ - Name: types.Ident{ - Name: "__type", - }, + Name: "__type", Type: s.Types["__Type"], }, TraceLabel: fmt.Sprintf("GraphQL field: __type"), diff --git a/internal/exec/resolvable/resolvable.go b/internal/exec/resolvable/resolvable.go index 0fa658ef9..a2ca6e4e1 100644 --- a/internal/exec/resolvable/resolvable.go +++ b/internal/exec/resolvable/resolvable.go @@ -231,16 +231,16 @@ func (b *execBuilder) makeObjectExec(typeName string, fields types.FieldsDefinit fieldsCount := fieldCount(rt, map[string]int{}) for _, f := range fields { var fieldIndex []int - methodIndex := findMethod(resolverType, f.Name.Name) + methodIndex := findMethod(resolverType, f.Name) if b.schema.UseFieldResolvers && methodIndex == -1 { - if fieldsCount[strings.ToLower(stripUnderscore(f.Name.Name))] > 1 { - return nil, fmt.Errorf("%s does not resolve %q: ambiguous field %q", resolverType, typeName, f.Name.Name) + if fieldsCount[strings.ToLower(stripUnderscore(f.Name))] > 1 { + return nil, fmt.Errorf("%s does not resolve %q: ambiguous field %q", resolverType, typeName, f.Name) } - fieldIndex = findField(rt, f.Name.Name, []int{}) + fieldIndex = findField(rt, f.Name, []int{}) } if methodIndex == -1 && len(fieldIndex) == 0 { hint := "" - if findMethod(reflect.PtrTo(resolverType), f.Name.Name) != -1 { + if findMethod(reflect.PtrTo(resolverType), f.Name) != -1 { hint = " (hint: the method exists on the pointer type)" } return nil, fmt.Errorf("%s does not resolve %q: missing method for field %q%s", resolverType, typeName, f.Name, hint) @@ -257,7 +257,7 @@ func (b *execBuilder) makeObjectExec(typeName string, fields types.FieldsDefinit if err != nil { return nil, fmt.Errorf("%s\n\tused by (%s).%s", err, resolverType, m.Name) } - Fields[f.Name.Name] = fe + Fields[f.Name] = fe } // Check type assertions when @@ -356,7 +356,7 @@ func (b *execBuilder) makeFieldExec(typeName string, f *types.FieldDefinition, m HasContext: hasContext, ArgsPacker: argsPacker, HasError: hasError, - TraceLabel: fmt.Sprintf("GraphQL field: %s.%s", typeName, f.Name.Name), + TraceLabel: fmt.Sprintf("GraphQL field: %s.%s", typeName, f.Name), } var out reflect.Type diff --git a/internal/schema/schema.go b/internal/schema/schema.go index 57df2d07a..b829b8684 100644 --- a/internal/schema/schema.go +++ b/internal/schema/schema.go @@ -159,8 +159,8 @@ func mergeExtensions(s *types.Schema) error { e := ext.Type.(*types.ObjectTypeDefinition) for _, field := range e.Fields { - if og.Fields.Get(field.Name.Name) != nil { - return fmt.Errorf("extended field %q already exists", field.Name.Name) + if og.Fields.Get(field.Name) != nil { + return fmt.Errorf("extended field %q already exists", field.Name) } } og.Fields = append(og.Fields, e.Fields...) @@ -188,8 +188,8 @@ func mergeExtensions(s *types.Schema) error { e := ext.Type.(*types.InterfaceTypeDefinition) for _, field := range e.Fields { - if og.Fields.Get(field.Name.Name) != nil { - return fmt.Errorf("extended field %s already exists", field.Name.Name) + if og.Fields.Get(field.Name) != nil { + return fmt.Errorf("extended field %s already exists", field.Name) } } og.Fields = append(og.Fields, e.Fields...) @@ -526,7 +526,7 @@ func parseFieldsDef(l *common.Lexer) types.FieldsDefinition { for l.Peek() != '}' { f := &types.FieldDefinition{} f.Desc = l.DescComment() - f.Name = l.ConsumeIdentWithLoc() + f.Name = l.ConsumeIdent() if l.Peek() == '(' { l.ConsumeToken('(') for l.Peek() != ')' { diff --git a/internal/schema/schema_internal_test.go b/internal/schema/schema_internal_test.go index 812922bb6..c2a5b0af5 100644 --- a/internal/schema/schema_internal_test.go +++ b/internal/schema/schema_internal_test.go @@ -19,7 +19,7 @@ func TestParseInterfaceDef(t *testing.T) { tests := []testCase{{ description: "Parses simple interface", definition: "Greeting { field: String }", - expected: &types.InterfaceTypeDefinition{Name: "Greeting", Fields: types.FieldsDefinition{&types.FieldDefinition{Name: types.Ident{Name: "field"}}}}, + expected: &types.InterfaceTypeDefinition{Name: "Greeting", Fields: types.FieldsDefinition{&types.FieldDefinition{Name: "field"}}}, }} for _, test := range tests { @@ -118,7 +118,7 @@ func compareInterfaces(t *testing.T, expected, actual *types.InterfaceTypeDefini } for i, f := range expected.Fields { - if f.Name.Name != actual.Fields[i].Name.Name { + if f.Name != actual.Fields[i].Name { t.Errorf("fields[%d]: wrong field name: want %q, got %q", i, f.Name, actual.Fields[i].Name) } } diff --git a/internal/schema/schema_test.go b/internal/schema/schema_test.go index 4450a0ef4..485c82fce 100644 --- a/internal/schema/schema_test.go +++ b/internal/schema/schema_test.go @@ -29,7 +29,7 @@ func TestParse(t *testing.T) { return fmt.Errorf("invalid number of fields: want %d, have %d", want, have) } const fieldName = "message" - if typ.Fields[0].Name.Name != fieldName { + if typ.Fields[0].Name != fieldName { return fmt.Errorf("field %q not found", fieldName) } return nil @@ -746,7 +746,7 @@ Second line of the description. "category": struct{}{}, } for _, f := range typ.Fields { - if _, ok := fields[f.Name.Name]; !ok { + if _, ok := fields[f.Name]; !ok { return fmt.Errorf("Unexpected field %q", f.Name) } } diff --git a/internal/validation/validation.go b/internal/validation/validation.go index 8451e8343..4633fd1cd 100644 --- a/internal/validation/validation.go +++ b/internal/validation/validation.go @@ -294,17 +294,17 @@ func validateSelection(c *opContext, sel types.Selection, t types.NamedType) { switch fieldName { case "__typename": f = &types.FieldDefinition{ - Name: types.Ident{Name: "__typename"}, + Name: "__typename", Type: c.schema.Types["String"], } case "__schema": f = &types.FieldDefinition{ - Name: types.Ident{Name: "__schema"}, + Name: "__schema", Type: c.schema.Types["__Schema"], } case "__type": f = &types.FieldDefinition{ - Name: types.Ident{Name: "__type"}, + Name: "__type", Arguments: types.ArgumentsDefinition{ &types.InputValueDefinition{ Name: types.Ident{Name: "name"}, diff --git a/introspection/introspection.go b/introspection/introspection.go index 2c9761b13..a0a2fa9bb 100644 --- a/introspection/introspection.go +++ b/introspection/introspection.go @@ -194,7 +194,7 @@ type Field struct { } func (r *Field) Name() string { - return r.field.Name.Name + return r.field.Name } func (r *Field) Description() *string {