Skip to content

Commit

Permalink
fix compile errors introduced by ab449f0
Browse files Browse the repository at this point in the history
  • Loading branch information
seansorr committed Mar 30, 2021
1 parent ab449f0 commit c097164
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion internal/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}()
Expand Down
12 changes: 3 additions & 9 deletions internal/exec/resolvable/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,23 @@ 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"),
}

fieldSchema := Field{
FieldDefinition: types.FieldDefinition{
Name: types.Ident{
Name: "__schema",
},
Name: "__schema",
Type: s.Types["__Schema"],
},
TraceLabel: fmt.Sprintf("GraphQL field: __schema"),
}

fieldType := Field{
FieldDefinition: types.FieldDefinition{
Name: types.Ident{
Name: "__type",
},
Name: "__type",
Type: s.Types["__Type"],
},
TraceLabel: fmt.Sprintf("GraphQL field: __type"),
Expand Down
14 changes: 7 additions & 7 deletions internal/exec/resolvable/resolvable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions internal/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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() != ')' {
Expand Down
4 changes: 2 additions & 2 deletions internal/schema/schema_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
2 changes: 1 addition & 1 deletion introspection/introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c097164

Please sign in to comment.