Documentation ¶
Index ¶
- Constants
- Variables
- func BoolPtr(i bool) *bool
- func Convert(args map[string]interface{}, typ reflect.Type) (interface{}, error)
- func DurationPtr(i time.Duration) *time.Duration
- func Float32Ptr(i float32) *float32
- func Float64Ptr(i float64) *float64
- func GetField(typ reflect.Value, name string) *reflect.Value
- func Int16Ptr(i int16) *int16
- func Int32Ptr(i int32) *int32
- func Int64Ptr(i int64) *int64
- func Int8Ptr(i int8) *int8
- func IntPtr(i int) *int
- func NewTranslator(t ut.Translator)
- func NewValidate() *validator.Validate
- func RelayKey(typ interface{}, key string)
- func StrPtr(i string) *string
- func StrSlicePtr(i ...string) []*string
- func UInt16Ptr(i int16) *int16
- func UInt32Ptr(i uint32) *uint32
- func UInt64Ptr(i int64) *int64
- func UInt8Ptr(i uint8) *uint8
- type Connection
- type ConnectionArgs
- type DescField
- type Directive
- type DirectiveFn
- type Edge
- type Enum
- type ExecuteFunc
- type FieldFuncOption
- type Id
- type InputObject
- type Interface
- type Map
- type Mutation
- type Object
- type PageInfo
- type PaginationInfo
- type Query
- type Scalar
- type Schema
- func (s *Schema) Build() (*internal.Schema, error)
- func (s *Schema) Directive(name string, locs []string, fn interface{}, desc ...string)
- func (s *Schema) Enum(name string, val interface{}, enum interface{}, desc ...string)
- func (s *Schema) GetInterface(name string) *Interface
- func (s *Schema) InputObject(name string, typ interface{}, desc ...string) *InputObject
- func (s *Schema) Interface(name string, typ interface{}, typeResolve interface{}, descs ...string) *Interface
- func (s *Schema) MustBuild() *internal.Schema
- func (s *Schema) Mutation() *Object
- func (s *Schema) Object(name string, typ interface{}, desc ...string) *Object
- func (s *Schema) Query() *Object
- func (s *Schema) Scalar(name string, tp interface{}, options ...interface{}) *Scalar
- func (s *Schema) Subscription() *Object
- func (s *Schema) Union(name string, union interface{}, desc string)
- type Subscription
- type Union
- type UnmarshalFunc
- type Upload
Constants ¶
const PREFIX = "arrayconnection:"
Variables ¶
var AnyScalar = &Scalar{ Name: "AnyScalar", Desc: "golang interface type", Type: nil, Serialize: func(value interface{}) (interface{}, error) { return value, nil }, ParseValue: func(value interface{}) (interface{}, error) { js := map[string]interface{}{"res": value} marshal, err := json.Marshal(js) if err != nil { return nil, err } res := make(map[string]interface{}) err = json.Unmarshal(marshal, &res) return res, err }, }
var Boolean = &Scalar{ Name: "Boolean", Desc: "bool is the set of boolean values, true and false.", Type: bool(false), Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { switch value := value.(type) { case bool: return value, nil case *bool: return value, nil default: if value == nil { return false, nil } else { return nil, errors.New("not a bool") } } }, }
var Bytes = &Scalar{ Name: "Bytes", Desc: "byte slice type", Type: []byte{}, Serialize: func(value interface{}) (interface{}, error) { data, err := json.Marshal(value.([]byte)) if err != nil { return nil, err } return data, nil }, ParseValue: func(value interface{}) (interface{}, error) { v, ok := value.(string) if !ok { return nil, errors.New("invalid type expected string") } return base64.StdEncoding.DecodeString(v) }, }
var DescFieldTyp = reflect.TypeOf(DescField{})
only use in enum definition can set description for enum value
var Float = &Scalar{ Name: "Float", Desc: "float is the set of all IEEE-754 32-bit floating-point numbers.", Type: float32(0), Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { var val float64 switch value := value.(type) { case float64: val = value case *float64: val = *value default: if value == nil { return float32(0), nil } else { return nil, errors.New("not a number") } } if val > math.MaxFloat32 { return nil, errors.New("value not float32") } return float32(val), nil }, }
var Float64 = &Scalar{ Name: "Float", Desc: "float is the set of all IEEE-754 32-bit floating-point numbers.", Type: float64(0), Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { var val float64 switch value := value.(type) { case float64: val = value case *float64: val = *value default: if value == nil { return int32(0), nil } else { return nil, errors.New("not a number") } } return val, nil }, }
var ID = &Scalar{ Name: "ID", Desc: "ID", Type: Id{}, Serialize: func(id interface{}) (interface{}, error) { switch id := id.(type) { case Id: return id.Value, nil case *Id: return id.Value, nil default: return nil, fmt.Errorf("unexpected type %v for Id", id) } }, ParseValue: func(value interface{}) (interface{}, error) { switch val := value.(type) { case string: return Id{Value: val}, nil case float64: return Id{Value: int(val)}, nil } return nil, errors.New("not a ID") }, }
var IncludeDirective = &Directive{ Name: "include", Desc: "Directs the executor to include this field or fragment only when the `if` argument is true.", Fn: func(ctx context.Context, args includeArg, fn DirectiveFn) (bool, interface{}, error) { if args.If { i, err := fn() return false, i, err } return true, nil, nil }, Locs: []string{ "FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT", }, }
var Int = &Scalar{ Name: "Int", Desc: "int is a signed integer type that is at least 32 bits in size.", Type: int(0), Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { var val float64 switch value := value.(type) { case float64: val = value case *float64: val = *value default: if value == nil { return int32(0), nil } else { return nil, errors.New("not a number") } } if val > math.MaxInt32 && val < math.MinInt32 { return nil, errors.New("value not int32") } return int(val), nil }, }
var Int16 = &Scalar{ Name: "Int16", Desc: "int16 is the set of all signed 16-bit integers. Range: -32768 through 32767.", Type: int16(0), Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { var val float64 switch value := value.(type) { case float64: val = value case *float64: val = *value default: if value == nil { return int16(0), nil } else { return nil, errors.New("not a number") } } if val > math.MaxInt16 && val < math.MinInt16 { return nil, errors.New("value not int16") } return int16(val), nil }, }
var Int32 = &Scalar{ Name: "Int32", Desc: "int32 is the set of all signed 32-bit integers. Range: -2147483648 through 2147483647.", Type: int32(0), Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { var val float64 switch value := value.(type) { case float64: val = value case *float64: val = *value default: if value == nil { return int32(0), nil } else { return nil, errors.New("not a number") } } if val > math.MaxInt32 && val < math.MinInt32 { return nil, errors.New("value not int32") } return int32(val), nil }, }
var Int64 = &Scalar{ Name: "Int64", Desc: "int64 is the set of all signed 64-bit integers. Range: -9223372036854775808 through 9223372036854775807.", Type: int64(0), Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { var val float64 switch value := value.(type) { case float64: val = value case *float64: val = *value default: if value == nil { return int64(0), nil } else { return nil, errors.New("not a number") } } if val > math.MaxInt64 && val < math.MinInt64 { return nil, errors.New("value not int8") } return int64(val), nil }, }
var Int8 = &Scalar{ Name: "Int8", Desc: "int8 is the set of all signed 8-bit integers. Range: -128 through 127.", Type: int8(0), Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { var val float64 switch value := value.(type) { case float64: val = value case *float64: val = *value default: if value == nil { return int8(0), nil } else { return nil, errors.New("not a number") } } if val > math.MaxInt8 && val < math.MinInt8 { return nil, errors.New("value not int8") } return int8(val), nil }, }
var MMap = &Scalar{ Name: "Map", Desc: `map type, use as {"a":value}`, Type: Map{}, Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { v, ok := value.(string) if !ok { if value == nil { v = "" } else { return nil, errors.New("not a string") } } mmap := Map{Value: v} return mmap, nil }, }
var NonNullField afterBuildFunc = func(param buildParam) error { param.f.Type = &internal.NonNull{Type: param.f.Type} return nil }
var NullBool = &Scalar{ Name: "NullBool", Desc: "Alias For Bool", Type: sql.NullBool{}, Serialize: func(value interface{}) (interface{}, error) { switch value := value.(type) { case sql.NullBool: return value.Bool, nil case bool: return value, nil default: return nil, fmt.Errorf("expected sql.NullBool but got %v", value) } }, ParseValue: func(value interface{}) (interface{}, error) { t, ok := value.(bool) if !ok { if value == nil { return sql.NullBool{Valid: false, Bool: false}, nil } return nil, fmt.Errorf("expected bool value for sql.NullBool, but got %v", value) } return sql.NullBool{Valid: true, Bool: t}, nil }, }
var NullFloat = &Scalar{ Name: "NullFloat", Desc: "Alias For Float", Type: sql.NullFloat64{}, Serialize: func(value interface{}) (interface{}, error) { switch value := value.(type) { case sql.NullFloat64: return value.Float64, nil case float64: return value, nil default: return nil, fmt.Errorf("expected sql.NullBool but got %v", value) } }, ParseValue: func(value interface{}) (interface{}, error) { t, ok := value.(float64) if !ok { if value == nil { return sql.NullFloat64{Valid: false, Float64: 0}, nil } return nil, fmt.Errorf("expected float value for sql.NullFloat, but got %v", value) } return sql.NullFloat64{Valid: true, Float64: t}, nil }, }
var NullInt32 = &Scalar{ Name: "NullInt32", Desc: "Alias For Int32", Type: sql.NullInt32{}, Serialize: func(value interface{}) (interface{}, error) { switch value := value.(type) { case sql.NullInt32: return value.Int32, nil case int32, int: return value, nil default: return nil, fmt.Errorf("expected sql.NullInt32 but got %v", value) } }, ParseValue: func(value interface{}) (interface{}, error) { t, ok := value.(float64) if !ok { if value == nil { return sql.NullInt32{Valid: false, Int32: 0}, nil } return nil, fmt.Errorf("expected int value for sql.NullInt32, but got %v", value) } if t > math.MaxInt32 || t < math.MinInt32 { return nil, fmt.Errorf("value not in int32 scope") } return sql.NullInt32{Valid: true, Int32: int32(t)}, nil }, }
var NullInt64 = &Scalar{ Name: "NullInt64", Desc: "Alias For Int64", Type: sql.NullInt64{}, Serialize: func(value interface{}) (interface{}, error) { switch value := value.(type) { case sql.NullInt64: return value.Int64, nil case int64, int: return value, nil default: return nil, fmt.Errorf("expected sql.NullInt64 but got %v", value) } }, ParseValue: func(value interface{}) (interface{}, error) { t, ok := value.(float64) if !ok { if value == nil { return sql.NullInt64{Valid: false, Int64: 0}, nil } return nil, fmt.Errorf("expected int value for sql.NullInt32, but got %v", value) } if t > math.MaxInt64 || t < math.MinInt64 { return nil, fmt.Errorf("value not in int64 scope") } return sql.NullInt64{Valid: true, Int64: int64(t)}, nil }, }
var NullString = &Scalar{ Name: "NullString", Desc: "Alias For String", Type: sql.NullString{}, Serialize: func(value interface{}) (interface{}, error) { switch value := value.(type) { case sql.NullString: return value.String, nil case string: return value, nil default: return nil, fmt.Errorf("expected sql.NullString but got %v", value) } }, ParseValue: func(value interface{}) (interface{}, error) { str, ok := value.(string) if !ok { if value == nil { return sql.NullString{Valid: false, String: ""}, nil } return nil, fmt.Errorf("expected string value for sql.NullString, but got %v", value) } return sql.NullString{Valid: true, String: str}, nil }, }
var NullTime = &Scalar{ Name: "NullTime", Desc: "Alias For Time", Type: sql.NullTime{}, Serialize: func(value interface{}) (interface{}, error) { switch value := value.(type) { case sql.NullTime: return value.Time, nil case time.Time: return value, nil default: return nil, fmt.Errorf("expected sql.NullTime but got %v", value) } }, ParseValue: func(value interface{}) (interface{}, error) { t, ok := value.(time.Time) if !ok { if value == nil { return sql.NullTime{Valid: false, Time: time.Time{}}, nil } return nil, fmt.Errorf("expected time value for sql.NullTime, but got %v", value) } return sql.NullTime{Valid: true, Time: t}, nil }, }
var RelayConnection afterBuildFunc = func(param buildParam) error { sb, field, fctx, fnresolve := param.sb, param.f, param.functx, param.fnresolve var argAnonymous, retAnonymous bool if fctx.hasArg { if cf, ok := fctx.argTyp.FieldByName(connectionArgsType.Elem().Name()); ok && cf.Type == connectionArgsType && cf.Anonymous { argAnonymous = true fnresolve.handleChain = append(fnresolve.handleChain, relayParseArg(true)) if !fctx.hasRet { return fmt.Errorf("if you use ConnectionArgs in your arg with anonymous,then you must return something") } ret := fctx.funcType.Out(0) if ret.Kind() != reflect.Ptr || ret.Elem().Kind() != reflect.Struct { return fmt.Errorf("if return Pagination in your object, then your object type must be a ptr of struct") } ret = ret.Elem() if pf, ok := ret.FieldByName(paginationInfoType.Elem().Name()); ok && pf.Type == paginationInfoType && pf.Anonymous { retAnonymous = true if ret.NumField() != 2 { return fmt.Errorf("for reutrn Pagination, your struct should have 2 field,one of pagination,and another is slice") } fnresolve.executeChain = append(fnresolve.executeChain, relayParseResult(true)) } else { return fmt.Errorf("if you use ConnectionArgs in your arg with anonymous,then you must return PaginationInfo in your return object") } } } var connectionArgs *internal.InputObject if argAnonymous { connectionArgs = field.Args[connectionArgsType.Elem().Name()].Type.(*internal.InputObject) delete(field.Args, connectionArgsType.Elem().Name()) } else { fnresolve.handleChain = append(fnresolve.handleChain, relayParseArg(false)) fnresolve.executeChain = append(fnresolve.executeChain, relayParseResult(false)) argType, err := sb.getType(connectionArgsType) if err != nil { return err } connectionArgs = argType.(*internal.InputObject) } for n, f := range connectionArgs.Fields { field.Args[n] = f } var sliceType *internal.List if retAnonymous { retobj := field.Type.(*internal.Object) delete(retobj.Fields, paginationInfoType.Elem().Name()) for _, f := range retobj.Fields { if _, ok := f.Type.(*internal.List); !ok { return fmt.Errorf("for pagination reutrn,another field should be slice") } sliceType = f.Type.(*internal.List) } } else { if _, ok := field.Type.(*internal.List); !ok { return fmt.Errorf("for pagination reutrn should be slice") } sliceType = field.Type.(*internal.List) } if sliceType == nil { return fmt.Errorf("must return slice for relay") } object, err := validateSliceType(sliceType) if err != nil { return err } if _, ok := relayKey[reflect.TypeOf(object.IsTypeOf)]; !ok { return fmt.Errorf("%s don't have a relay key", object.Name) } return buildConnectionType(object.Name, sb, sliceType, fctx, field) }
var Serialize = func(value interface{}) (interface{}, error) { switch v := value.(type) { case string, float64, int64, bool, int, int8, int16, int32, uint, uint8, uint16, uint32, uint64, float32, time.Time: return v, nil case *string, *float64, *int64, *bool, *int, *int8, *int16, *int32, *uint, *uint8, *uint16, *uint32, *uint64, *float32, *time.Time: return v, nil case []byte: return string(v), nil case *[]byte: return string(*v), nil default: marshal, err := json.Marshal(v) if err != nil { return nil, err } return string(marshal), nil } }
var SkipDirective = &Directive{ Name: "skip", Desc: "Directs the executor to skip this field or fragment when the `if` argument is true.", Fn: func(ctx context.Context, args skipArg, fn DirectiveFn) (bool, interface{}, error) { if args.If { return false, nil, nil } i, err := fn() return true, i, err }, Locs: []string{ "FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT", }, }
var String = &Scalar{ Name: "String", Desc: "string is the set of all strings of 8-bit bytes, conventionally but not necessarily representing " + "UTF-8-encoded text. A string may be empty, but not nil. Values of string type are immutable.", Type: string(""), Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { switch value := value.(type) { case string: return value, nil case *string: return *value, nil default: if value == nil { return "", nil } else { return nil, errors.New("not a string") } } }, }
var Time = &Scalar{ Name: "Time", Desc: "time type", Type: time.Time{}, Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { v, ok := value.(string) if !ok { return nil, errors.New("invalid type expected string") } return time.Parse(time.RFC3339, v) }, }
var Uint = &Scalar{ Name: "Uint", Desc: "uint is an unsigned integer type that is at least 32 bits in size.", Type: uint(0), Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { var val float64 switch value := value.(type) { case float64: val = value case *float64: val = *value default: if value == nil { return uint(0), nil } else { return nil, errors.New("not a number") } } if val > math.MaxUint32 && val < 0 { return nil, errors.New("value not uint32") } return uint(val), nil }, }
var Uint16 = &Scalar{ Name: "Uint16", Desc: "uint16 is the set of all unsigned 16-bit integers. Range: 0 through 65535.", Type: uint16(0), Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { var val float64 switch value := value.(type) { case float64: val = value case *float64: val = *value default: if value == nil { return uint16(0), nil } else { return nil, errors.New("not a number") } } if val > math.MaxUint16 && val < 0 { return nil, errors.New("value not uint16") } return uint16(val), nil }, }
var Uint32 = &Scalar{ Name: "Uint32", Desc: "uint32 is the set of all unsigned 32-bit integers. Range: 0 through 4294967295.", Type: uint32(0), Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { var val float64 switch value := value.(type) { case float64: val = value case *float64: val = *value default: if value == nil { return uint32(0), nil } else { return nil, errors.New("not a number") } } if val > math.MaxUint32 && val < 0 { return nil, errors.New("value not uint32") } return uint(val), nil }, }
var Uint64 = &Scalar{ Name: "Uint64", Desc: "uint64 is the set of all unsigned 64-bit integers. Range: 0 through 18446744073709551615.", Type: uint64(0), Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { var val float64 switch value := value.(type) { case float64: val = value case *float64: val = *value default: if value == nil { return uint64(0), nil } else { return nil, errors.New("not a number") } } if val > math.MaxUint64 && val < 0 { return nil, errors.New("value not uint64") } return uint64(val), nil }, }
var Uint8 = &Scalar{ Name: "Uint8", Desc: "uint8 is the set of all unsigned 8-bit integers. Range: 0 through 255.", Type: uint8(0), Serialize: Serialize, ParseValue: func(value interface{}) (interface{}, error) { var val float64 switch value := value.(type) { case float64: val = value case *float64: val = *value default: if value == nil { return uint8(0), nil } else { return nil, errors.New("not a number") } } if val > math.MaxUint8 && val < 0 { return nil, errors.New("value not uint8") } return uint8(val), nil }, }
var UnmarshalFuncTyp = reflect.TypeOf(*new(UnmarshalFunc))
Functions ¶
func DurationPtr ¶
DurationPtr transforms a time.Duration into a *time.Duration
func Float32Ptr ¶
Float32Ptr transforms a float32 into a *float32
func Float64Ptr ¶
Float64Ptr transforms a float64 into a *float64
func NewTranslator ¶ added in v1.0.11
func NewTranslator(t ut.Translator)
func NewValidate ¶
func NewValidate() *validator.Validate
func StrSlicePtr ¶
StrSlicePtr transforms a []string into a []*string
Types ¶
type Connection ¶
type Connection struct { TotalCount int `graphql:"totalCount"` Edges []Edge `graphql:"edges"` PageInfo PageInfo `graphql:"pageInfo"` }
Connection conforms to the GraphQL Connection type in the Relay Pagination spec.
type ConnectionArgs ¶
type ConnectionArgs struct { // first: n First *int64 `graphql:"first"` // last: n Last *int64 `graphql:"last"` // after: cursor After *string `graphql:"after"` // before: cursor Before *string `graphql:"before"` }
ConnectionArgs conform to the pagination arguments as specified by the Relay Spec for Connection types. https://facebook.github.io/relay/graphql/connections.htm#sec-Arguments
type Directive ¶
type Directive struct { Name string Desc string Fn interface{} Locs []string Fields map[string]*inputFieldResolve }
func (*Directive) FieldDefault ¶
FieldDefault is used to expose the fields of an input object
type DirectiveFn ¶
type DirectiveFn func() (interface{}, error)
type Edge ¶
type Edge struct { Node interface{} `graphql:"node"` Cursor string `graphql:"cursor"` }
Edge consists of a node paired with its b64 encoded cursor.
type Enum ¶
type Enum struct { Name string Desc string Type interface{} Map map[string]interface{} ReverseMap map[interface{}]string DescMap map[string]string }
Enum is a representation of an enum that includes both the mapping and reverse mapping.
type ExecuteFunc ¶
type FieldFuncOption ¶
type FieldFuncOption interface {
// contains filtered or unexported methods
}
type InputObject ¶
type InputObject struct { Name string Desc string Type interface{} Fields map[string]*inputFieldResolve }
InputObject represents the input objects passed in queries,mutations and subscriptions
func (*InputObject) FieldDefault ¶
func (io *InputObject) FieldDefault(name string, defaultValue interface{})
FieldDefault is used to expose the fields of an input object
type Interface ¶
type Interface struct { Name string Desc string Type interface{} Fn interface{} PossibleTypes map[string]*Object FieldResolve map[string]*fieldResolve Interface []*Interface }
Interface is a representation of graphql interface
func (*Interface) FieldFunc ¶
similar as object's func, but haven't middleware func , and given name must be same as interface's method
func (*Interface) InterfaceList ¶
InterfaceList exposes a interface on an Interface.
type Object ¶
type Object struct { Name string Desc string Type interface{} FieldResolve map[string]*fieldResolve Interface []*Interface }
A Object represents a Go type and set of methods to be converted into an Object in a GraphQL schema.
func (*Object) FieldFunc ¶
FieldDefault exposes a field on an object. The function f can take a number of optional arguments: func([ctx graphql.context], [o *Operation], [args struct {}]) ([Result], [error])
For example, for an object of type User, a fullName field might take just an instance of the object:
user.FieldDefault("fullName", func(u *User) string { return u.FirstName + " " + u.LastName })
An addUser Mutation field might take both a context and arguments:
Mutation.FieldFunc("addUser", func(ctx context.context, args struct{ FirstName string LastName string }) (int, error) { userID, err := db.AddUser(ctx, args.FirstName, args.LastName) return userID, err })
func (*Object) InterfaceList ¶
InterfaceList exposes a interface on an object.
type PageInfo ¶
type PageInfo struct { HasNextPage bool `graphql:"hasNextPage"` EndCursor *string `graphql:"endCursor"` HasPrevPage bool `graphql:"hasPrevPage"` StartCursor *string `graphql:"startCursor"` Pages []string `graphql:"pages"` }
PageInfo contains information for pagination on a connection type. The list of Pages is used for page-number based pagination where the ith index corresponds to the start cursor of (i+1)st page.
type PaginationInfo ¶
PaginationInfo can be returned in a PaginateFieldFunc. The TotalCount function returns the totalCount field on the connection Fn. If the resolver makes a SQL Query, then HasNextPage and HasPrevPage can be resolved in an efficient manner by requesting first/last:n + 1 items in the query. Then the flags can be filled in by checking the result size.
type Scalar ¶
type Scalar struct { Name string Desc string Type interface{} Serialize func(interface{}) (interface{}, error) ParseValue func(interface{}) (interface{}, error) ParseLiteral func(value ast.Value) error }
Scalar is a representation of graphql scalar
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
schema builder
use to build go type into graphql type system include:
struct->object/input enum interface scalar(int,float,string...eg.) union struct defined directive
func (*Schema) Build ¶
Build takes the schema we have built on our Query, Mutation and Subscription starting points and builds a full graphql.Schema We can use graphql.Schema to execute and run queries. Essentially we read through all the methods we've attached to our Query, Mutation and Subscription Objects and ensure that those functions are returning other Objects that we can resolve in our GraphQL graph.
func (*Schema) Enum ¶
Enum registers an enumType in the schema. The val should be any arbitrary value of the enumType to be used for reflection, and the enumMap should be the corresponding map of the enums.
For example a enum could be declared as follows:
type enumType int32 const ( one enumType = 1 two enumType = 2 three enumType = 3 )
Then the Enum can be registered as:
s.Enum("number",enumType(1), map[string]interface{}{ "one": DescField{one,"the first one"}, "two": two, "three": three, },"")
func (*Schema) GetInterface ¶
func (*Schema) InputObject ¶
func (s *Schema) InputObject(name string, typ interface{}, desc ...string) *InputObject
InputObject registers a struct as inout object which can be passed as an argument to a Query or Mutation We'll read through the fields of the struct and create argument parsers to fill the data from graphQL JSON input
func (*Schema) Interface ¶
func (s *Schema) Interface(name string, typ interface{}, typeResolve interface{}, descs ...string) *Interface
Interface registers a Interface as a GraphQL Interface in our Schema.
func (*Schema) Mutation ¶
Mutation returns an Object struct that we can use to register all the top level graphql mutations functions we'd like to expose.
func (*Schema) Object ¶
Object registers a struct as a GraphQL Object in our Schema. We'll read the fields of the struct to determine it's basic "Fields" and we'll return an Object struct that we can use to register custom relationships and fields on the object.
func (*Schema) Query ¶
Query returns an Object struct that we can use to register all the top level graphql Query functions we'd like to expose.
func (*Schema) Scalar ¶
Scalar is used to register custom scalars.
For example, to register a custom ID type,
type ID struct { Value string }
Implement JSON Marshalling
func (Id ID) MarshalJSON() ([]byte, error) { return strconv.AppendQuote(nil, string(Id.Value)), nil }
Register unmarshal func
func init() { builder:=schemabuilder.NewSchema() typ := reflect.TypeOf((*ID)(nil)).Elem() if err := scalar.Scalar(typ, "ID", "",func(value interface{}, d reflect.Value) error { v, ok := value.(string) if !ok { return errors.New("not a string type") } d.Field(0).SetString(v) return nil }); err != nil { panic(err) } }
func (*Schema) Subscription ¶
Subscription returns an Object struct that we can use to register all the top level graphql subscription functions we'd like to expose.
type Subscription ¶
type Subscription struct {
Payload []byte
}
type UnmarshalFunc ¶
UnmarshalFunc is used to unmarshal scalar value from JSON