graphql

package
v0.0.0-...-3cc3ff2 Latest Latest
Warning

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

Go to latest
Published: May 17, 2021 License: MIT Imports: 18 Imported by: 0

README

GraphQL

The GraphQL transport allows to expose flows as query objects. All flows could be exposed with graphql endpoints and the following optional options.

endpoint "flow" "graphql" {
    path = "user.address"
    name = "address"
    base = "mutation"
}

Documentation

Index

Constants

View Source
const (
	// PathOption represents the object name option key
	PathOption = "path"
	// BaseOption represents the object base option key
	BaseOption = "base"
	// NameOption represents the object name option key
	NameOption = "name"
)

Variables

View Source
var (
	QueryObject    = "query"
	MutationObject = "mutation"
)

Schema base

View Source
var ErrInvalidObject = errors.New("graphql only supports object types as root elements")

ErrInvalidObject is thrown when the given property is not of type message

Functions

func IsNestedPath

func IsNestedPath(value string) bool

IsNestedPath checks whether the given value is a path

func NewArgs

NewArgs construct new field config arguments for the graphql schema

func NewEmptyObject

func NewEmptyObject(objects *Objects, name string) *graphql.Object

NewEmptyObject constructs a new empty object with the given name and stores it inside the objects collection. The object is claimed inside the object properties as nil. If the name is already claimed is the configured graphql object returned.

func NewInputArgObject

func NewInputArgObject(prop *specs.Property) (*graphql.InputObject, error)

NewInputArgObject constructs a new input argument object

func NewListener

func NewListener(addr string, opts specs.Options) transport.NewListener

NewListener constructs a new listener for the given addr

func NewObject

func NewObject(name string, description string, template specs.Template) (*graphql.Object, error)

NewObject constructs a new graphql object of the given specs

func NewPath

func NewPath(parts []string) string

NewPath constructs a new path of the given parts

func NewSchemaObject

func NewSchemaObject(objects *Objects, name string, object *transport.Object) (*graphql.Object, error)

NewSchemaObject constructs a new object for the given property with the given name. If a object with the same name already exists is it used instead.

func NewType

func NewType(name string, description string, property specs.Template) (graphql.Output, error)

NewType constructs a new output type from the given template.

func ParsePath

func ParsePath(path string) []string

ParsePath returns the path as steps

func ResponseObject

func ResponseObject(specs *specs.Property, store references.Store, tracker references.Tracker) (map[string]interface{}, error)

ResponseObject constructs the response value send back to the client

func ResponseValue

func ResponseValue(tmpl specs.Template, store references.Store, tracker references.Tracker) (interface{}, error)

ResponseValue constructs a new response used inside a response object

func SetField

func SetField(path string, fields graphql.Fields, field *graphql.Field) error

SetField sets the given field inside the given fields on the given path

func SetFieldPath

func SetFieldPath(object *graphql.Object, path string, field *graphql.Field) error

SetFieldPath sets the given field on the given path

Types

type EndpointOptions

type EndpointOptions struct {
	Name string
	Path string
	Base string
}

EndpointOptions represents the available HTTP options

func ParseEndpointOptions

func ParseEndpointOptions(endpoint *transport.Endpoint) (EndpointOptions, error)

ParseEndpointOptions parses the given specs options into HTTP options

type ErrDuplicateObject

type ErrDuplicateObject struct {
	Name string
	// contains filtered or unexported fields
}

ErrDuplicateObject occurs when a duplicate object is provided

func (ErrDuplicateObject) Error

func (e ErrDuplicateObject) Error() string

Error returns a description of the given error as a string

func (ErrDuplicateObject) Prettify

func (e ErrDuplicateObject) Prettify() prettyerr.Error

Prettify returns the prettified version of the given error

func (ErrDuplicateObject) Unwrap

func (i ErrDuplicateObject) Unwrap() error

type ErrFieldAlreadySet

type ErrFieldAlreadySet struct {
	Field string
	Path  string
	// contains filtered or unexported fields
}

ErrFieldAlreadySet occurs when field has already being set

func (ErrFieldAlreadySet) Error

func (e ErrFieldAlreadySet) Error() string

Error returns a description of the given error as a string

func (ErrFieldAlreadySet) Prettify

func (e ErrFieldAlreadySet) Prettify() prettyerr.Error

Prettify returns the prettified version of the given error

func (ErrFieldAlreadySet) Unwrap

func (i ErrFieldAlreadySet) Unwrap() error

type ErrTypeMismatch

type ErrTypeMismatch struct {
	Expected string
	Type     string
	// contains filtered or unexported fields
}

ErrTypeMismatch occurs when there is a mismatch in schema definations

func (ErrTypeMismatch) Error

func (e ErrTypeMismatch) Error() string

Error returns a description of the given error as a string

func (ErrTypeMismatch) Prettify

func (e ErrTypeMismatch) Prettify() prettyerr.Error

Prettify returns the prettified version of the given error

func (ErrTypeMismatch) Unwrap

func (i ErrTypeMismatch) Unwrap() error

type ErrUnexpectedType

type ErrUnexpectedType struct {
	Type     types.Type
	Expected types.Type
	// contains filtered or unexported fields
}

ErrUnexpectedType occurs when a non-object is passed as property

func (ErrUnexpectedType) Error

func (e ErrUnexpectedType) Error() string

Error returns a description of the given error as a string

func (ErrUnexpectedType) Prettify

func (e ErrUnexpectedType) Prettify() prettyerr.Error

Prettify returns the prettified version of the given error

func (ErrUnexpectedType) Unwrap

func (i ErrUnexpectedType) Unwrap() error

type ErrUnknownBase

type ErrUnknownBase struct {
	Base string
	// contains filtered or unexported fields
}

ErrUnknownBase occurs when an unknown base is provided

func (ErrUnknownBase) Error

func (e ErrUnknownBase) Error() string

Error returns a description of the given error as a string

func (ErrUnknownBase) Prettify

func (e ErrUnknownBase) Prettify() prettyerr.Error

Prettify returns the prettified version of the given error

func (ErrUnknownBase) Unwrap

func (i ErrUnknownBase) Unwrap() error

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

Listener represents a GraphQL listener

func (*Listener) Close

func (listener *Listener) Close() error

Close closes the given listener

func (*Listener) Handle

func (listener *Listener) Handle(ctx *broker.Context, endpoints []*transport.Endpoint, constructors map[string]codec.Constructor) error

Handle parses the given endpoints and constructs route handlers

func (*Listener) Name

func (listener *Listener) Name() string

Name returns the name of the given listener

func (*Listener) Schema

func (listener *Listener) Schema() graphql.Schema

Schema returns the schema of the given listner

func (*Listener) Serve

func (listener *Listener) Serve() error

Serve opens the GraphQL listener and calls the given handler function on reach request

type Objects

type Objects struct {
	// contains filtered or unexported fields
}

Objects represents a schema objects collection

func NewObjects

func NewObjects() *Objects

NewObjects constructs a new objects collection

Jump to

Keyboard shortcuts

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