gqlserver

package
v0.0.0-...-c2e30b8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2021 License: NIST-PD-fallback Imports: 14 Imported by: 0

Documentation

Overview

Package gqlserver provides a GraphQL server. It is a singleton and is initialized via init() functions.

Index

Constants

This section is empty.

Variables

Scalar types.

View Source
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 AddMutation

func AddMutation(f *graphql.Field)

AddMutation adds a top-level mutation field.

func AddQuery

func AddQuery(f *graphql.Field)

AddQuery adds a top-level query field.

func NewNonNullList

func NewNonNullList(ofType graphql.Type, optionalNullable ...bool) graphql.Type

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

func RetrieveNodeOfType(expectedNodeType *NodeType, id, ptr interface{}) error

RetrieveNodeOfType locates Node by full ID, ensures it has correct type, and assigns it to *ptr.

func Start

func Start(uri string)

Start starts the server.

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 NewNodeType

func NewNodeType(value interface{}) *NodeType

NewNodeType creates a NodeType.

func NewNodeTypeNamed

func NewNodeTypeNamed(name string, value interface{}) (nt *NodeType)

NewNodeTypeNamed creates a NodeType with specified name.

func RetrieveNode

func RetrieveNode(id interface{}) (*NodeType, interface{}, error)

RetrieveNode locates Node by full ID.

func (*NodeType) Annotate

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.

func (*NodeType) Register

func (nt *NodeType) Register(object *graphql.Object)

Register enables accessing Node of this type by ID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL