diff --git a/internal/common/types.go b/internal/common/types.go index f0b699b77f3..f69509ee5f2 100644 --- a/internal/common/types.go +++ b/internal/common/types.go @@ -1,7 +1,8 @@ package common import ( - "github.com/neelance/graphql-go/errors" + "fmt" + "github.com/neelance/graphql-go/internal/lexer" ) @@ -47,7 +48,7 @@ func parseNullType(l *lexer.Lexer) Type { type Resolver func(name string) Type -func ResolveType(t Type, resolver Resolver) (Type, *errors.QueryError) { +func ResolveType(t Type, resolver Resolver) (Type, error) { switch t := t.(type) { case *List: ofType, err := ResolveType(t.OfType, resolver) @@ -64,7 +65,7 @@ func ResolveType(t Type, resolver Resolver) (Type, *errors.QueryError) { case *TypeName: refT := resolver(t.Name) if refT == nil { - return nil, errors.Errorf("type %q not found", t.Name) + return nil, fmt.Errorf("type %q not found", t.Name) } return refT, nil default: diff --git a/internal/exec/exec.go b/internal/exec/exec.go index 0fa5219115a..06c8b7d7e65 100644 --- a/internal/exec/exec.go +++ b/internal/exec/exec.go @@ -384,12 +384,12 @@ func (r *request) handlePanic() { func ExecuteRequest(ctx context.Context, e *Exec, document *query.Document, operationName string, variables map[string]interface{}) (interface{}, []*errors.QueryError) { op, err := getOperation(document, operationName) if err != nil { - return nil, []*errors.QueryError{err} + return nil, []*errors.QueryError{errors.Errorf("%s", err)} } coercedVariables, err := coerceInputObject(&op.Vars, variables) if err != nil { - return nil, []*errors.QueryError{err} + return nil, []*errors.QueryError{errors.Errorf("%s", err)} } r := &request{ @@ -417,14 +417,14 @@ func ExecuteRequest(ctx context.Context, e *Exec, document *query.Document, oper return data, r.errs } -func getOperation(document *query.Document, operationName string) (*query.Operation, *errors.QueryError) { +func getOperation(document *query.Document, operationName string) (*query.Operation, error) { if len(document.Operations) == 0 { - return nil, errors.Errorf("no operations in query document") + return nil, fmt.Errorf("no operations in query document") } if operationName == "" { if len(document.Operations) > 1 { - return nil, errors.Errorf("more than one operation in query document and no operation name given") + return nil, fmt.Errorf("more than one operation in query document and no operation name given") } for _, op := range document.Operations { return op, nil // return the one and only operation @@ -433,12 +433,12 @@ func getOperation(document *query.Document, operationName string) (*query.Operat op, ok := document.Operations[operationName] if !ok { - return nil, errors.Errorf("no operation with name %q", operationName) + return nil, fmt.Errorf("no operation with name %q", operationName) } return op, nil } -func coerceInputObject(io *common.InputMap, variables map[string]interface{}) (map[string]interface{}, *errors.QueryError) { +func coerceInputObject(io *common.InputMap, variables map[string]interface{}) (map[string]interface{}, error) { coerced := make(map[string]interface{}) for _, iv := range io.Fields { value, ok := variables[iv.Name] @@ -458,7 +458,7 @@ func coerceInputObject(io *common.InputMap, variables map[string]interface{}) (m return coerced, nil } -func coerceInputValue(iv *common.InputValue, value interface{}) (interface{}, *errors.QueryError) { +func coerceInputValue(iv *common.InputValue, value interface{}) (interface{}, error) { t, _ := unwrapNonNull(iv.Type) switch t := t.(type) { case *scalar: diff --git a/internal/exec/scalar.go b/internal/exec/scalar.go index dbb6cb680e2..8d54c5458d0 100644 --- a/internal/exec/scalar.go +++ b/internal/exec/scalar.go @@ -1,17 +1,17 @@ package exec import ( + "fmt" "math" "reflect" - "github.com/neelance/graphql-go/errors" "github.com/neelance/graphql-go/internal/schema" ) type scalar struct { name string reflectType reflect.Type - coerceInput func(input interface{}) (interface{}, *errors.QueryError) + coerceInput func(input interface{}) (interface{}, error) } func (*scalar) Kind() string { return "SCALAR" } @@ -21,10 +21,10 @@ var builtinScalars = []*scalar{ &scalar{ name: "Int", reflectType: reflect.TypeOf(int32(0)), - coerceInput: func(input interface{}) (interface{}, *errors.QueryError) { + coerceInput: func(input interface{}) (interface{}, error) { i := input.(int) if i < math.MinInt32 || i > math.MaxInt32 { - return nil, errors.Errorf("not a 32-bit integer: %d", i) + return nil, fmt.Errorf("not a 32-bit integer: %d", i) } return int32(i), nil }, @@ -32,28 +32,28 @@ var builtinScalars = []*scalar{ &scalar{ name: "Float", reflectType: reflect.TypeOf(float64(0)), - coerceInput: func(input interface{}) (interface{}, *errors.QueryError) { + coerceInput: func(input interface{}) (interface{}, error) { return input, nil // TODO }, }, &scalar{ name: "String", reflectType: reflect.TypeOf(""), - coerceInput: func(input interface{}) (interface{}, *errors.QueryError) { + coerceInput: func(input interface{}) (interface{}, error) { return input, nil // TODO }, }, &scalar{ name: "Boolean", reflectType: reflect.TypeOf(true), - coerceInput: func(input interface{}) (interface{}, *errors.QueryError) { + coerceInput: func(input interface{}) (interface{}, error) { return input, nil // TODO }, }, &scalar{ name: "ID", reflectType: reflect.TypeOf(""), - coerceInput: func(input interface{}) (interface{}, *errors.QueryError) { + coerceInput: func(input interface{}) (interface{}, error) { return input, nil // TODO }, }, diff --git a/internal/query/query.go b/internal/query/query.go index 6131a72524e..588f7b55e93 100644 --- a/internal/query/query.go +++ b/internal/query/query.go @@ -89,7 +89,7 @@ func Parse(queryString string, resolver common.Resolver) (doc *Document, err *er for _, v := range op.Vars.Fields { t, err := common.ResolveType(v.Type, resolver) if err != nil { - return nil, err + return nil, errors.Errorf("%s", err) } v.Type = t } diff --git a/internal/schema/schema.go b/internal/schema/schema.go index 9b3235c5c97..4a034adce4d 100644 --- a/internal/schema/schema.go +++ b/internal/schema/schema.go @@ -86,7 +86,7 @@ func New() *Schema { } } -func (s *Schema) Parse(schemaString string) *errors.QueryError { +func (s *Schema) Parse(schemaString string) error { sc := &scanner.Scanner{ Mode: scanner.ScanIdents | scanner.ScanInts | scanner.ScanFloats | scanner.ScanStrings, } @@ -151,7 +151,7 @@ func (s *Schema) Parse(schemaString string) *errors.QueryError { return nil } -func resolveNamedType(s *Schema, t NamedType) *errors.QueryError { +func resolveNamedType(s *Schema, t NamedType) error { switch t := t.(type) { case *Object: for _, f := range t.Fields { @@ -173,7 +173,7 @@ func resolveNamedType(s *Schema, t NamedType) *errors.QueryError { return nil } -func resolveField(s *Schema, f *Field) *errors.QueryError { +func resolveField(s *Schema, f *Field) error { t, err := common.ResolveType(f.Type, s.Resolve) if err != nil { return err @@ -182,7 +182,7 @@ func resolveField(s *Schema, f *Field) *errors.QueryError { return resolveInputObject(s, &f.Args) } -func resolveInputObject(s *Schema, io *common.InputMap) *errors.QueryError { +func resolveInputObject(s *Schema, io *common.InputMap) error { for _, f := range io.Fields { t, err := common.ResolveType(f.Type, s.Resolve) if err != nil {