...

Package graphb

import "github.com/udacity/graphb"
Overview
Index

Overview ▾

Index ▾

Constants
func StringFromChan(c <-chan string) string
type Argument
    func ArgumentAny(name string, value interface{}) (Argument, error)
    func ArgumentBool(name string, value bool) Argument
    func ArgumentBoolSlice(name string, values ...bool) Argument
    func ArgumentCustomType(name string, values ...Argument) Argument
    func ArgumentCustomTypeSlice(name string, values ...[]Argument) Argument
    func ArgumentCustomTypeSliceElem(values ...Argument) []Argument
    func ArgumentInt(name string, value int) Argument
    func ArgumentIntSlice(name string, values ...int) Argument
    func ArgumentString(name string, value string) Argument
    func ArgumentStringSlice(name string, values ...string) Argument
type ArgumentTypeNotSupportedErr
    func (e ArgumentTypeNotSupportedErr) Error() string
type CyclicFieldErr
    func (e CyclicFieldErr) Error() string
type Field
    func Fields(args ...string) []*Field
    func MakeField(name string) *Field
    func NewField(name string, options ...FieldOptionInterface) *Field
    func (f *Field) AddArguments(argument ...Argument) *Field
    func (f *Field) SetAlias(alias string) *Field
    func (f *Field) SetArguments(arguments ...Argument) *Field
    func (f *Field) SetFields(fs ...*Field) *Field
    func (f *Field) StringChan() (<-chan string, error)
type FieldContainerOption
    func OfField(name string, options ...FieldOptionInterface) FieldContainerOption
type FieldOption
    func OfAlias(alias string) FieldOption
    func OfArguments(arguments ...Argument) FieldOption
    func OfFields(name ...string) FieldOption
type FieldOptionInterface
type InvalidNameErr
    func (e InvalidNameErr) Error() string
type InvalidOperationTypeErr
    func (e InvalidOperationTypeErr) Error() string
type NilFieldErr
    func (e NilFieldErr) Error() string
type Query
    func MakeQuery(Type operationType) *Query
    func NewQuery(Type operationType, options ...QueryOptionInterface) *Query
    func (q *Query) AddFields(fields ...*Field) *Query
    func (q *Query) GetField(name string) *Field
    func (q *Query) JSON() (string, error)
    func (q *Query) SetFields(fields ...*Field) *Query
    func (q *Query) SetName(name string) *Query
    func (q *Query) StringChan() (<-chan string, error)
type QueryOption
    func OfName(name string) QueryOption
type QueryOptionInterface

Package files

argument.go error.go field.go operation_type.go private.go public.go query.go

Constants

3 types of operation.

const (
    TypeQuery        operationType = "query"
    TypeMutation     operationType = "mutation"
    TypeSubscription operationType = "subscription"
)

func StringFromChan

func StringFromChan(c <-chan string) string

StringFromChan builds a string from a channel, assuming the channel has been closed.

type Argument

type Argument struct {
    Name  string
    Value argumentValue
}

func ArgumentAny

func ArgumentAny(name string, value interface{}) (Argument, error)

func ArgumentBool

func ArgumentBool(name string, value bool) Argument

func ArgumentBoolSlice

func ArgumentBoolSlice(name string, values ...bool) Argument

func ArgumentCustomType

func ArgumentCustomType(name string, values ...Argument) Argument

ArgumentCustomType returns a custom GraphQL type's argument representation, which could be a recursive structure.

func ArgumentCustomTypeSlice

func ArgumentCustomTypeSlice(name string, values ...[]Argument) Argument

func ArgumentCustomTypeSliceElem

func ArgumentCustomTypeSliceElem(values ...Argument) []Argument

func ArgumentInt

func ArgumentInt(name string, value int) Argument

func ArgumentIntSlice

func ArgumentIntSlice(name string, values ...int) Argument

func ArgumentString

func ArgumentString(name string, value string) Argument

func ArgumentStringSlice

func ArgumentStringSlice(name string, values ...string) Argument

type ArgumentTypeNotSupportedErr

ArgumentTypeNotSupportedErr is returned when user tries to pass an unsupported type to ArgumentAny.

type ArgumentTypeNotSupportedErr struct {
    Value interface{}
}

func (ArgumentTypeNotSupportedErr) Error

func (e ArgumentTypeNotSupportedErr) Error() string

type CyclicFieldErr

CyclicFieldErr is returned when any field contains a loop which goes back to itself.

type CyclicFieldErr struct {
    Field Field
}

func (CyclicFieldErr) Error

func (e CyclicFieldErr) Error() string

type Field

Field is a recursive data struct which represents a GraphQL query field.

type Field struct {
    Name      string
    Alias     string
    Arguments []Argument
    Fields    []*Field
    E         error
}

func Fields

func Fields(args ...string) []*Field

Fields takes a list of strings and make them a slice of *Field. This is useful when you want fields with no sub fields. For example:

query { courses { id, key } }

can be written as:

Query{
	Type: "query",
	Fields: []*Field{
		{
			Name:      "courses",
			Fields:    Fields("id", "key"),
		},
	},
}

func MakeField

func MakeField(name string) *Field

MakeField constructs a Field of given name and return the pointer to this Field.

func NewField

func NewField(name string, options ...FieldOptionInterface) *Field

NewField uses functional options to construct a new Field and returns the pointer to it. On error, the pointer is nil. To know more about this design pattern, see https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis

func (*Field) AddArguments

func (f *Field) AddArguments(argument ...Argument) *Field

func (*Field) SetAlias

func (f *Field) SetAlias(alias string) *Field

SetAlias sets the alias of a Field and return the pointer to this Field.

func (*Field) SetArguments

func (f *Field) SetArguments(arguments ...Argument) *Field

SetArguments sets the arguments of a Field and return the pointer to this Field.

func (*Field) SetFields

func (f *Field) SetFields(fs ...*Field) *Field

SetFields sets the sub fields of a Field and return the pointer to this Field.

func (*Field) StringChan

func (f *Field) StringChan() (<-chan string, error)

StringChan returns read only string token channel or an error. It checks if there is a circle.

type FieldContainerOption

FieldContainerOption implements FieldOptionInterface and QueryOptionInterface, which means, it can be used as the functional option for both NewQuery() and NewField(). FieldContainerOption is a function which takes in a fieldContainer and config it. Both Query and Field are fieldContainer.

type FieldContainerOption func(fc fieldContainer) error

func OfField

func OfField(name string, options ...FieldOptionInterface) FieldContainerOption

OfField returns a FieldContainerOption and has the same parameter signature of NewField(name string, options ...FieldOptionInterface) (*Field, error)

type FieldOption

FieldOption implements FieldOptionInterface

type FieldOption func(field *Field) error

func OfAlias

func OfAlias(alias string) FieldOption

func OfArguments

func OfArguments(arguments ...Argument) FieldOption

OfArguments returns a FieldOption which sets the arguments of the targeting field.

func OfFields

func OfFields(name ...string) FieldOption

OfFields returns a FieldOption which sets a list of sub fields of given names of the targeting field. All the sub fields only have one level which is their names. That is, no sub fields have sub fields.

type FieldOptionInterface

FieldOptionInterface implements functional options for NewField().

type FieldOptionInterface interface {
    // contains filtered or unexported methods
}

type InvalidNameErr

InvalidNameErr is returned when an invalid name is used. In GraphQL, operation, alias, field and argument all have names. A valid name matches ^[_A-Za-z][_0-9A-Za-z]*$ exactly.

type InvalidNameErr struct {
    Type nameType
    Name string
}

func (InvalidNameErr) Error

func (e InvalidNameErr) Error() string

type InvalidOperationTypeErr

InvalidOperationTypeErr is returned when the operation is not one of query, mutation and subscription.

type InvalidOperationTypeErr struct {
    Type operationType
}

func (InvalidOperationTypeErr) Error

func (e InvalidOperationTypeErr) Error() string

type NilFieldErr

NilFieldErr is returned when any field is nil. Of course the author could choose to ignore nil fields. But, author chose a stricter construct.

type NilFieldErr struct{}

func (NilFieldErr) Error

func (e NilFieldErr) Error() string

type Query

Query represents a GraphQL query. Though all fields (Go struct field, not GraphQL field) of this struct is public, the author recommends you to use functions in public.go.

type Query struct {
    Type   operationType // The operation type is either query, mutation, or subscription.
    Name   string        // The operation name is a meaningful and explicit name for your operation.
    Fields []*Field
    E      error
}

func MakeQuery

func MakeQuery(Type operationType) *Query

MakeQuery constructs a Query of the given type and returns a pointer of it.

func NewQuery

func NewQuery(Type operationType, options ...QueryOptionInterface) *Query

NewQuery uses functional options to construct a new Query and returns the pointer to it. On error, the pointer is nil. Type is required. Other options such as operation name and alias are optional.

func (*Query) AddFields

func (q *Query) AddFields(fields ...*Field) *Query

AddFields adds to the Fields field of this Query.

func (*Query) GetField

func (q *Query) GetField(name string) *Field

GetField return the field identified by the name. Nil if not exist.

func (*Query) JSON

func (q *Query) JSON() (string, error)

JSON returns a json string with "query" field.

func (*Query) SetFields

func (q *Query) SetFields(fields ...*Field) *Query

SetFields sets the Fields field of this Query. If q.Fields already contains data, they will be replaced.

func (*Query) SetName

func (q *Query) SetName(name string) *Query

SetName sets the Name field of this Query.

func (*Query) StringChan

func (q *Query) StringChan() (<-chan string, error)

StringChan returns a string channel and an error. When error is not nil, the channel is nil. When error is nil, the channel is guaranteed to be closed. Warning: One should never receive from a nil channel for eternity awaits by a nil channel.

type QueryOption

QueryOption implements QueryOptionInterface

type QueryOption func(query *Query) error

func OfName

func OfName(name string) QueryOption

OfName returns a QueryOption which validates and sets the operation name of a query.

type QueryOptionInterface

QueryOptionInterface implements functional options for NewQuery().

type QueryOptionInterface interface {
    // contains filtered or unexported methods
}