refactor typegen to explicitly handle kinds

This commit is contained in:
Ben Kraft
2020-04-02 18:35:04 -07:00
parent f8545f7e76
commit 8d87040069
+15 -9
View File
@@ -96,15 +96,21 @@ func (builder *typeBuilder) writeType(typ *ast.Type, selectionSet ast.SelectionS
builder.WriteString("*")
}
if selectionSet != nil {
typedef := builder.schema.Types[typ.Name()]
switch typedef.Kind {
case ast.Object, ast.InputObject:
return builder.writeSelectionSetStruct(selectionSet)
case ast.Scalar, ast.Enum:
goName := graphQLNameToGoName[typ.Name()]
// TODO(benkraft): Handle custom scalars and enums.
if goName == "" {
return fmt.Errorf("unknown scalar name: %s", typ.Name())
}
builder.WriteString(goName)
return nil
case ast.Union, ast.Interface:
return fmt.Errorf("not implemented: %v", typedef.Kind)
default:
return fmt.Errorf("unexpected kind: %v", typedef.Kind)
}
// TODO: handle enums better. (do unions need special handling?)
goName := graphQLNameToGoName[typ.Name()]
if goName == "" {
return fmt.Errorf("unknown scalar name: %s", typ.Name())
}
builder.WriteString(goName)
return nil
}