Documentation ¶
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 ArgumentEnum(name string, value string) 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
- type CyclicFieldErr
- type Field
- type FieldContainerOption
- type FieldOption
- type FieldOptionInterface
- type InvalidNameErr
- type InvalidOperationTypeErr
- type NilFieldErr
- type Query
- func (q *Query) AddFields(fields ...*Field) *Query
- func (q *Query) GetField(name string) *Field
- func (q *Query) GraphString() (string, error)
- 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
- type QueryOptionInterface
Constants ¶
const ( TypeQuery operationType = "query" TypeMutation operationType = "mutation" TypeSubscription operationType = "subscription" )
3 types of operation.
const (
EnumValuePattern = "^[A-Z_][A-Z0-9_]*$"
)
Variables ¶
This section is empty.
Functions ¶
func StringFromChan ¶
StringFromChan builds a string from a channel, assuming the channel has been closed.
Types ¶
type Argument ¶
type Argument struct { Name string Value argumentValue }
func ArgumentAny ¶
func ArgumentBool ¶
func ArgumentBoolSlice ¶
func ArgumentCustomType ¶
ArgumentCustomType returns a custom GraphQL type's argument representation, which could be a recursive structure.
func ArgumentCustomTypeSlice ¶
func ArgumentEnum ¶
func ArgumentInt ¶
func ArgumentIntSlice ¶
func ArgumentString ¶
func ArgumentStringSlice ¶
type ArgumentTypeNotSupportedErr ¶
type ArgumentTypeNotSupportedErr struct {
Value interface{}
}
ArgumentTypeNotSupportedErr is returned when user tries to pass an unsupported type to ArgumentAny.
func (ArgumentTypeNotSupportedErr) Error ¶
func (e ArgumentTypeNotSupportedErr) Error() string
type CyclicFieldErr ¶
type CyclicFieldErr struct {
Field Field
}
CyclicFieldErr is returned when any field contains a loop which goes back to itself.
func (CyclicFieldErr) Error ¶
func (e CyclicFieldErr) Error() string
type Field ¶
Field is a recursive data struct which represents a GraphQL query field.
func Fields ¶
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 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 (*Field) SetArguments ¶
SetArguments sets the arguments of a Field and return the pointer to this Field.
func (*Field) SetFields ¶
SetFields sets the sub fields of a Field and return the pointer to this Field.
func (*Field) StringChan ¶
StringChan returns read only string token channel or an error. It checks if there is a circle.
type FieldContainerOption ¶
type FieldContainerOption func(fc fieldContainer) error
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.
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
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 ¶
type FieldOptionInterface interface {
// contains filtered or unexported methods
}
FieldOptionInterface implements functional options for NewField().
type InvalidNameErr ¶
type InvalidNameErr struct { Type nameType Name string }
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.
func (InvalidNameErr) Error ¶
func (e InvalidNameErr) Error() string
type InvalidOperationTypeErr ¶
type InvalidOperationTypeErr struct {
Type operationType
}
InvalidOperationTypeErr is returned when the operation is not one of query, mutation and subscription.
func (InvalidOperationTypeErr) Error ¶
func (e InvalidOperationTypeErr) Error() string
type NilFieldErr ¶
type NilFieldErr struct{}
NilFieldErr is returned when any field is nil. Of course the author could choose to ignore nil fields. But, author chose a stricter construct.
func (NilFieldErr) Error ¶
func (e NilFieldErr) Error() string
type Query ¶
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 }
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.
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) GraphString ¶
func (*Query) SetFields ¶
SetFields sets the Fields field of this Query. If q.Fields already contains data, they will be replaced.
func (*Query) StringChan ¶
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
func OfName ¶
func OfName(name string) QueryOption
OfName returns a QueryOption which validates and sets the operation name of a query.
type QueryOptionInterface ¶
type QueryOptionInterface interface {
// contains filtered or unexported methods
}
QueryOptionInterface implements functional options for NewQuery().