pass errors a few more places
This commit is contained in:
+12
-4
@@ -51,15 +51,19 @@ type argument struct {
|
|||||||
GraphQLName string
|
GraphQLName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromASTArg(arg *ast.VariableDefinition, schema *ast.Schema) argument {
|
func fromASTArg(arg *ast.VariableDefinition, schema *ast.Schema) (argument, error) {
|
||||||
graphQLName := arg.Variable
|
graphQLName := arg.Variable
|
||||||
firstRest := strings.SplitN(graphQLName, "", 2)
|
firstRest := strings.SplitN(graphQLName, "", 2)
|
||||||
goName := strings.ToLower(firstRest[0]) + firstRest[1]
|
goName := strings.ToLower(firstRest[0]) + firstRest[1]
|
||||||
|
goType, err := typeForInputType(arg.Type, schema)
|
||||||
|
if err != nil {
|
||||||
|
return argument{}, err
|
||||||
|
}
|
||||||
return argument{
|
return argument{
|
||||||
GraphQLName: graphQLName,
|
GraphQLName: graphQLName,
|
||||||
GoName: goName,
|
GoName: goName,
|
||||||
GoType: typeForInputType(arg.Type, schema),
|
GoType: goType,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func reverse(slice []string) {
|
func reverse(slice []string) {
|
||||||
@@ -100,7 +104,11 @@ func fromASTOperation(op *ast.OperationDefinition, schema *ast.Schema) (operatio
|
|||||||
|
|
||||||
args := make([]argument, len(op.VariableDefinitions))
|
args := make([]argument, len(op.VariableDefinitions))
|
||||||
for i, arg := range op.VariableDefinitions {
|
for i, arg := range op.VariableDefinitions {
|
||||||
args[i] = fromASTArg(arg, schema)
|
var err error
|
||||||
|
args[i], err = fromASTArg(arg, schema)
|
||||||
|
if err != nil {
|
||||||
|
return operation{}, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typ, err := typeForOperation(op, schema)
|
typ, err := typeForOperation(op, schema)
|
||||||
|
|||||||
+7
-4
@@ -13,14 +13,14 @@ func typeForOperation(operation *ast.OperationDefinition, schema *ast.Schema) (s
|
|||||||
return builder.String(), err
|
return builder.String(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func typeForInputType(typ *ast.Type, schema *ast.Schema) string {
|
func typeForInputType(typ *ast.Type, schema *ast.Schema) (string, error) {
|
||||||
var builder strings.Builder
|
var builder strings.Builder
|
||||||
|
|
||||||
// TODO: handle non-scalar types (by passing ...something... as the
|
// TODO: handle non-scalar types (by passing ...something... as the
|
||||||
// SelectionSet?)
|
// SelectionSet?)
|
||||||
writeType(&builder, typ, nil, schema)
|
err := writeType(&builder, typ, nil, schema)
|
||||||
|
|
||||||
return builder.String()
|
return builder.String(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeSelectionSetStruct(builder *strings.Builder, selectionSet ast.SelectionSet, schema *ast.Schema) error {
|
func writeSelectionSetStruct(builder *strings.Builder, selectionSet ast.SelectionSet, schema *ast.Schema) error {
|
||||||
@@ -46,7 +46,10 @@ func writeSelectionSetStruct(builder *strings.Builder, selectionSet ast.Selectio
|
|||||||
// but empirically it might not.
|
// but empirically it might not.
|
||||||
return fmt.Errorf("undefined selection %v", selection)
|
return fmt.Errorf("undefined selection %v", selection)
|
||||||
}
|
}
|
||||||
writeType(builder, selection.Definition.Type, selection.SelectionSet, schema)
|
err := writeType(builder, selection.Definition.Type, selection.SelectionSet, schema)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if jsonName != goName {
|
if jsonName != goName {
|
||||||
builder.WriteString("`json:\"")
|
builder.WriteString("`json:\"")
|
||||||
|
|||||||
Reference in New Issue
Block a user