-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more flexible API for creating a schema
- Loading branch information
Showing
5 changed files
with
132 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package exec | ||
|
||
import ( | ||
"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) | ||
} | ||
|
||
func (*scalar) Kind() string { return "SCALAR" } | ||
func (t *scalar) TypeName() string { return t.name } | ||
|
||
var builtinScalars = []*scalar{ | ||
&scalar{ | ||
name: "Int", | ||
reflectType: reflect.TypeOf(int32(0)), | ||
coerceInput: func(input interface{}) (interface{}, *errors.QueryError) { | ||
i := input.(int) | ||
if i < math.MinInt32 || i > math.MaxInt32 { | ||
return nil, errors.Errorf("not a 32-bit integer: %d", i) | ||
} | ||
return int32(i), nil | ||
}, | ||
}, | ||
&scalar{ | ||
name: "Float", | ||
reflectType: reflect.TypeOf(float64(0)), | ||
coerceInput: func(input interface{}) (interface{}, *errors.QueryError) { | ||
return input, nil // TODO | ||
}, | ||
}, | ||
&scalar{ | ||
name: "String", | ||
reflectType: reflect.TypeOf(""), | ||
coerceInput: func(input interface{}) (interface{}, *errors.QueryError) { | ||
return input, nil // TODO | ||
}, | ||
}, | ||
&scalar{ | ||
name: "Boolean", | ||
reflectType: reflect.TypeOf(true), | ||
coerceInput: func(input interface{}) (interface{}, *errors.QueryError) { | ||
return input, nil // TODO | ||
}, | ||
}, | ||
&scalar{ | ||
name: "ID", | ||
reflectType: reflect.TypeOf(""), | ||
coerceInput: func(input interface{}) (interface{}, *errors.QueryError) { | ||
return input, nil // TODO | ||
}, | ||
}, | ||
} | ||
|
||
func AddBuiltinScalars(s *schema.Schema) { | ||
for _, scalar := range builtinScalars { | ||
s.Types[scalar.name] = scalar | ||
} | ||
} |
Oops, something went wrong.