Documentation ¶
Index ¶
- Variables
- type Argument
- type Directive
- type Enum
- type EnumValue
- type EnumValues
- type Field
- type Fields
- type InputCoercion
- type InputFields
- type InputObject
- type InputObjectField
- type Interface
- type List
- type NonNull
- type Object
- type OutputCoercion
- type Params
- type ResolverFunc
- type Result
- type Scalar
- type Schema
- type Type
- type TypeDefinition
- type TypeResolver
- type ValidationContext
- type Validator
- func (v *Validator) ValidateFieldsInSetCanMerge(ctx *execCtx, o *Object, set []ast.Selection) []error
- func (v *Validator) ValidateLeafFieldSelections(ctx *execCtx, f *Field)
- func (v *Validator) ValidateOperations(ctx *execCtx) []error
- func (v *Validator) ValidateRequest(ctx *execCtx) []error
- func (v *Validator) ValidateSameResponseShape(ctx *execCtx, o *Object, fieldA *ast.Field, fieldB *ast.Field) bool
- func (v *Validator) ValidateSelectionSet(ctx *execCtx, o *Object, set []ast.Selection) []error
- func (v *Validator) ValidateSelectionSetMerges(ctx *execCtx, o *Object, set []ast.Selection) []error
Constants ¶
This section is empty.
Variables ¶
var ( // String is a built-in type in GraphQL String = &Scalar{ Name: "String", Description: "This is the built-in String scalar", InputCoercion: func(s string) (interface{}, error) { if strings.HasPrefix(s, "\"") && strings.HasSuffix(s, "\"") { t := s[1 : len(s)-1] if utf8.ValidString(t) { return t, nil } } return nil, fmt.Errorf("value '%s' couldn't be coerced as input for String", s) }, OutputCoercion: func(v interface{}) ([]byte, error) { r := reflect.ValueOf(v) switch { case v == nil: return []byte("null"), nil case r.Kind() == reflect.String: if utf8.ValidString(r.String()) { return json.Marshal(r.String()) } case r.Kind() == reflect.Bool: if r.Bool() { return []byte("true"), nil } return []byte("false"), nil case r.Kind() == reflect.Int || r.Kind() == reflect.Int16 || r.Kind() == reflect.Int32: return []byte(fmt.Sprintf(`"%v"`, r.Int())), nil case r.Kind() == reflect.Float32 || r.Kind() == reflect.Float64: return []byte(fmt.Sprintf(`"%v"`, r.Float())), nil } return nil, fmt.Errorf("value '%v' couldn't be coerced as output for String", v) }, } // ID is a built-in type in GraphQL ID = &Scalar{ Name: "ID", Description: "This is the built-in ID scalar", InputCoercion: func(s string) (interface{}, error) { if strings.HasPrefix(s, "\"") && strings.HasSuffix(s, "\"") { t := s[1 : len(s)-1] if utf8.ValidString(t) { return t, nil } } return nil, fmt.Errorf("value '%s' couldn't be coerced as input for String", s) }, OutputCoercion: func(v interface{}) ([]byte, error) { r := reflect.ValueOf(v) switch { case v == nil: return []byte("null"), nil case r.Kind() == reflect.String: if utf8.ValidString(r.String()) { return json.Marshal(r.String()) } case r.Kind() == reflect.Int || r.Kind() == reflect.Int16 || r.Kind() == reflect.Int32: return []byte(fmt.Sprintf(`"%v"`, r.Int())), nil } return nil, fmt.Errorf("value '%v' couldn't be coerced as output for String", v) }, } )
Functions ¶
This section is empty.
Types ¶
type Argument ¶
type Argument struct { Name string DefaultValue interface{} Description string Depricated bool DepricationReason string Type Type }
Argument ...
type Enum ¶ added in v0.0.3
type Enum struct { Name string Description string Values EnumValues }
func (*Enum) InputCoercion ¶ added in v0.0.3
func (*Enum) Kind ¶ added in v0.0.3
func (e *Enum) Kind() TypeDefinition
func (*Enum) OutputCoercion ¶ added in v0.0.3
func (*Enum) Validate ¶ added in v0.0.3
func (e *Enum) Validate(ctx *ValidationContext) error
type EnumValues ¶ added in v0.0.3
type EnumValues []*EnumValue
type Field ¶
type Field struct { Name string Description string Depricated bool DepricationReason string Type Type Arguments []*Argument Resolver ResolverFunc }
Field ...
func (*Field) Validate ¶ added in v0.0.3
func (f *Field) Validate(ctx *ValidationContext) error
type InputCoercion ¶ added in v0.0.2
InputCoercion func
type InputFields ¶ added in v0.0.3
type InputFields []*InputObjectField
InputFields contains InputObjectFields
func (InputFields) Get ¶ added in v0.0.3
func (i InputFields) Get(name string) *InputObjectField
Get returns the InputObjectField with the given name
type InputObject ¶ added in v0.0.3
type InputObject struct { Name string Description string Fields InputFields }
InputObject ...
func (*InputObject) Kind ¶ added in v0.0.3
func (o *InputObject) Kind() TypeDefinition
Kind returns the kind of the type, which is InputObjectTypeDefinition
func (*InputObject) Unwrap ¶ added in v0.0.3
func (o *InputObject) Unwrap() Type
Unwrap is defined to implement the Type interface
func (*InputObject) Validate ¶ added in v0.0.3
func (o *InputObject) Validate(ctx *ValidationContext) error
Validate runs a check if everything is okay with the Type
type InputObjectField ¶ added in v0.0.3
InputObjectField describes a field of an InputObject
type Interface ¶ added in v0.0.3
type Interface struct { Name string Description string Fields Fields ResolveType TypeResolver }
Interface ...
func (*Interface) Kind ¶ added in v0.0.3
func (i *Interface) Kind() TypeDefinition
Kind returns InterfaceTypeDefinition
func (*Interface) Validate ¶ added in v0.0.3
func (i *Interface) Validate(ctx *ValidationContext) error
Validate the type
type List ¶ added in v0.0.2
type List struct {
Type Type
}
List ...
func (*List) Validate ¶ added in v0.0.3
func (l *List) Validate(ctx *ValidationContext) error
Validate ...
type NonNull ¶ added in v0.0.2
type NonNull struct {
Type Type
}
NonNull ...
func (*NonNull) Validate ¶ added in v0.0.3
func (nn *NonNull) Validate(ctx *ValidationContext) error
Validate ...
type Object ¶
type Object struct { Name string Description string Implements []*Interface Fields Fields // contains filtered or unexported fields }
Object ...
func (*Object) Kind ¶ added in v0.0.2
func (o *Object) Kind() TypeDefinition
Kind returns ObjectTypeDefinition
func (*Object) Validate ¶ added in v0.0.3
func (o *Object) Validate(ctx *ValidationContext) error
Validate returns any error caused by invalid object definition
type OutputCoercion ¶ added in v0.0.2
OutputCoercion func
type Params ¶ added in v0.0.3
type Params struct { Ctx context.Context `json:"-"` Query string `json:"query"` OperationName string `json:"operationName"` Variables map[string]interface{} `json:"variables"` }
Params ...
type ResolverFunc ¶
ResolverFunc ..
type Scalar ¶
type Scalar struct { Name string Description string InputCoercion InputCoercion OutputCoercion OutputCoercion }
Scalar ...
func (*Scalar) Validate ¶ added in v0.0.3
func (s *Scalar) Validate(ctx *ValidationContext) error
Validate validates the Type
type Type ¶
type Type interface { Unwrap() Type Kind() TypeDefinition Validate(*ValidationContext) error }
Type ...
type TypeDefinition ¶ added in v0.0.2
type TypeDefinition int
TypeDefinition ...
const ( // NonNullTypeDefinition NonNull type NonNullTypeDefinition TypeDefinition = iota // ListTypeDefinition List type ListTypeDefinition // ScalarTypeDefinition scalar type ScalarTypeDefinition // ObjectTypeDefinition object type ObjectTypeDefinition // InterfaceTypeDefinition interface type InterfaceTypeDefinition // UnionTypeDefinition union type UnionTypeDefinition // EnumTypeDefinition enum type EnumTypeDefinition // InputObjectTypeDefinition input object type InputObjectTypeDefinition )
type TypeResolver ¶ added in v0.0.3
TypeResolver resolves the Object for an Interface or Union based on the resolver's result
type ValidationContext ¶ added in v0.0.3
type ValidationContext struct {
// contains filtered or unexported fields
}
type Validator ¶ added in v0.0.3
type Validator struct {
// contains filtered or unexported fields
}