Documentation ¶
Overview ¶
Package gqlserver provides a GraphQL server. It is a singleton and is initialized via init() functions.
Index ¶
- Variables
- func AddMutation(f *graphql.Field)
- func AddQuery(f *graphql.Field)
- func NewNonNullList(ofType graphql.Type, optionalNullable ...bool) graphql.Type
- func Optional(value interface{}, optionalValid ...bool) interface{}
- func RetrieveNodeOfType(expectedNodeType *NodeType, id, ptr interface{}) error
- func Start(uri string)
- type NodeType
Constants ¶
This section is empty.
Variables ¶
var ( JSON = tools_scalars.ScalarJSON NonNullJSON = graphql.NewNonNull(JSON) Bytes = go2gql_scalars.GraphQLBytesScalar NonNullID = graphql.NewNonNull(graphql.ID) NonNullBoolean = graphql.NewNonNull(graphql.Boolean) NonNullInt = graphql.NewNonNull(graphql.Int) NonNullString = graphql.NewNonNull(graphql.String) )
Scalar types.
var Schema = graphql.SchemaConfig{ Query: graphql.NewObject(graphql.ObjectConfig{ Name: "Query", Fields: graphql.Fields{}, }), Mutation: graphql.NewObject(graphql.ObjectConfig{ Name: "Mutation", Fields: graphql.Fields{}, }), }
Schema is the singleton of graphql.SchemaConfig.
Functions ¶
func NewNonNullList ¶
NewNonNullList constructs a non-null list type. NewNonNullList(T) returns [T!]!. NewNonNullList(T, true) returns [T]!.
func Optional ¶
func Optional(value interface{}, optionalValid ...bool) interface{}
Optional turns invalid value to nil.
Optional(value) considers the value invalid if it is zero. Optional(value, valid) considers the value invalid if valid is false.
func RetrieveNodeOfType ¶
RetrieveNodeOfType locates Node by full ID, ensures it has correct type, and assigns it to *ptr.
Types ¶
type NodeType ¶
type NodeType struct { // GetID extracts unprefixed ID from the source object. GetID func(source interface{}) string // Retrieve fetches an object from unprefixed ID. Retrieve func(id string) (interface{}, error) // Delete deletes the source object. Delete func(source interface{}) error // contains filtered or unexported fields }
NodeType defines a Node subtype.
func NewNodeTypeNamed ¶
NewNodeTypeNamed creates a NodeType with specified name.
func RetrieveNode ¶
RetrieveNode locates Node by full ID.
func (*NodeType) Annotate ¶
func (nt *NodeType) Annotate(oc graphql.ObjectConfig) graphql.ObjectConfig
Annotate updates ObjectConfig with Node interface and "id" field.
The 'id' can be resolved from:
- nt.GetID function.
- ObjectConfig 'nid' field of NonNullInt or NonNullString type.
If neither is present, this function panics.