Documentation ¶
Index ¶
- Variables
- func ValidateQuery(ctx context.Context, typ Type, selectionSet *SelectionSet) error
- type BatchResolver
- type Directive
- type Enum
- type Executor
- type Field
- type FragmentDefinition
- type FragmentSpread
- type InputObject
- type Interface
- type List
- type NonNull
- type Object
- type Query
- type Resolver
- type Scalar
- type Schema
- type Selection
- type SelectionSet
- type Type
- type Union
Constants ¶
This section is empty.
Variables ¶
var ErrNoUpdate = errors.New("no update")
Functions ¶
func ValidateQuery ¶
func ValidateQuery(ctx context.Context, typ Type, selectionSet *SelectionSet) error
ValidateQuery checks that the given selectionSet matches the schema typ, and parses the args in selectionSet
Types ¶
type BatchResolver ¶
type BatchResolver func(ctx context.Context, sources []interface{}, args interface{}, selectionSet *SelectionSet) ([]interface{}, error)
A BatchResolver calculates the value of a field for a slice of objects.
type Field ¶
type Field struct { Resolve Resolver Type Type Args map[string]Type ParseArguments func(json interface{}) (interface{}, error) External bool Expensive bool LazyExecution bool LazyResolver func(ctx context.Context, fun interface{}) (interface{}, error) }
Field knows how to compute field values of an Object
Fields are responsible for computing their value themselves.
type FragmentDefinition ¶
type FragmentDefinition struct { Name string On string SelectionSet *SelectionSet }
A FragmentDefinition represents a reusable part of a GraphQL query
The On part of a FragmentDefinition represents the type of source object for which this FragmentDefinition should be used. That is not currently implemented in this package.
type FragmentSpread ¶
type FragmentSpread struct { Fragment *FragmentDefinition Directives []*Directive }
FragmentSpread represents a usage of a FragmentDefinition. Alongside the information about the fragment, it includes any directives used at that spread location.
type InputObject ¶
InputObject defines the object in argument of a query, mutation or subscription
func (*InputObject) String ¶
func (io *InputObject) String() string
type Interface ¶
type Interface struct { Name string Description string Types map[string]*Object Fields map[string]*Field }
Interface defines the graphql interface
type Object ¶
type Object struct { Name string Description string KeyField *Field Fields map[string]*Field Interfaces map[string]*Interface //For introspection only }
Object is a value with several fields
type Query ¶
type Query struct { Name string Kind string *SelectionSet }
func Parse ¶
Parse parses an input GraphQL string into a *Query
Parse validates that the query looks syntactically correct and contains no cycles or unused fragments or immediate conflicts. However, it does not validate that the query is legal under a given schema, which instead is done by ValidateQuery.
type Resolver ¶
type Resolver func(ctx context.Context, source, args interface{}, selectionSet *SelectionSet) (interface{}, error)
A Resolver calculates the value of a field of an object
type Scalar ¶
Scalar is a leaf value. A custom "Unwrapper" can be attached to the scalar so it can have a custom unwrapping (if nil we will use the default unwrapper).
type Selection ¶
type Selection struct { Name string Alias string Args interface{} SelectionSet *SelectionSet Directives []*Directive UseBatch bool // contains filtered or unexported fields }
Selection : A selection represents a part of a GraphQL query
The selection
me: user(id: 166) { name }
has name "user" (representing the source field to be queried), alias "me" (representing the name to be used in the output), args id: 166 (representing arguments passed to the source field to be queried), and subselection name representing the information to be queried from the resulting object.
func Flatten ¶
func Flatten(selectionSet *SelectionSet) ([]*Selection, error)
Flatten takes a SelectionSet and flattens it into an array of selections with unique aliases
A GraphQL query (the SelectionSet) is allowed to contain the same key multiple times, as well as fragments. For example,
{ groups { name } groups { name id } ... on Organization { groups { widgets { name } } } }
Flatten simplifies the query into an array of selections, merging fields, resulting in something like the new query
groups: { name name id { widgets { name } } }
Flatten does _not_ flatten out the inner queries, so the name above does not get flattened out yet.
type SelectionSet ¶
type SelectionSet struct { Selections []*Selection Fragments []*FragmentSpread }
SelectionSet represents a core GraphQL query
A SelectionSet can contain multiple fields and multiple fragments. For example, the query
{ name ... UserFragment memberships { organization { name } } }
results in a root SelectionSet with two selections (name and memberships), and one fragment (UserFragment). The subselection `organization { name }` is stored in the memberships selection.
Because GraphQL allows multiple fragments with the same name or alias, selections are stored in an array instead of a map.