Documentation
¶
Index ¶
- func IsBasicType(typ Type) bool
- func IsInputType(typ Type) bool
- func NewLexer(source string, useStringDescriptions ...bool) *lexer
- func ParseDocument(source string) (*ast.Document, *errors.GraphQLError)
- func ParseType(l *lexer) ast.Type
- func ParseValueLiteral(l *lexer, constOnly bool) ast.Value
- func ValueToJson(value ast.Value, vars map[string]interface{}) (interface{}, *errors.GraphQLError)
- type Directive
- type DirectiveFn
- type Document
- type Enum
- type Field
- type FieldResolve
- type FragmentDefinition
- type FragmentSpread
- type InputField
- type InputObject
- type Interface
- type List
- type NamedType
- type NonNull
- type Object
- type Scalar
- type Schema
- type Selection
- type SelectionSet
- type Type
- type TypeResolve
- type Union
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsBasicType ¶
func IsInputType ¶
func ParseDocument ¶
func ParseDocument(source string) (*ast.Document, *errors.GraphQLError)
func ParseValueLiteral ¶
*
- Value[Const] :
- - [~Const] Variable
- - IntValue
- - FloatValue
- - StringValue
- - BooleanValue
- - EnumValue
- - ListValue[?Const]
- - ObjectValue[?Const] *
- BooleanValue : one of `true` `false` *
- EnumValue : Name but not `true`, `false` or `null`
func ValueToJson ¶
func ValueToJson(value ast.Value, vars map[string]interface{}) (interface{}, *errors.GraphQLError)
Types ¶
type Directive ¶
type Directive struct { Name string `json:"name"` Desc string `json:"description"` Args map[string]*InputField `json:"arguments"` ArgVals map[string]interface{} `json:"-"` FnResolve DirectiveFn `json:"-"` Locs []string `json:"locations"` Loc errors.Location }
type DirectiveFn ¶
type DirectiveFn func(ctx context.Context, args interface{}, fieldFn FieldResolve, source interface{}, fieldArgs interface{}) (bool, interface{}, error)
type Document ¶
type Document struct { Operations []*ast.OperationDefinition Fragments []*ast.FragmentDefinition }
type Enum ¶
type Enum struct { Name string `json:"name"` Values []string `json:"values"` ValuesDesc map[string]string `json:"-"` ReverseMap map[string]interface{} `json:"-"` Map map[interface{}]string `json:"-"` Desc string `json:"description"` }
Some leaf values of requests and input values are Enums. GraphQL serializes Enum values as strings, however internally Enums can be represented by any kind of type, often integers.
Note: If a value is not provided in a definition, the name of the enum value will be used as its internal value.
func (*Enum) Description ¶
type Field ¶
type Field struct { Name string `json:"name"` Type Type `json:"type"` Args map[string]*InputField `json:"arguments"` Resolve FieldResolve `json:"-"` Desc string `json:"desc"` }
type FieldResolve ¶
type FragmentDefinition ¶
type FragmentDefinition struct { Name string On string SelectionSet *SelectionSet Loc errors.Location }
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 { Loc errors.Location 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 InputField ¶
type InputObject ¶
type InputObject struct { Name string `json:"name"` Fields map[string]*InputField `json:"fields"` Desc string `json:"description"` }
An input object defines a structured collection of fields which may be supplied to a field argument.
Using NonNull will ensure that a value must be provided by the query
func (*InputObject) Description ¶
func (t *InputObject) Description() string
func (*InputObject) IsType ¶
func (t *InputObject) IsType()
func (*InputObject) String ¶
func (t *InputObject) String() string
func (*InputObject) TypeName ¶
func (t *InputObject) TypeName() string
type Interface ¶
type Interface struct { Name string `json:"name"` Desc string `json:"description"` Fields map[string]*Field `json:"fields"` Interfaces map[string]*Interface `json:"interfaces"` PossibleTypes map[string]*Object `json:"-"` TypeResolve TypeResolve `json:"-"` }
When a field can return one of a heterogeneous set of types, a Interface type is used to describe what types are possible, what fields are in common across all types, as well as a function to determine which type is actually used when the field is resolved.
func (*Interface) Description ¶
type List ¶
type List struct {
Type Type
}
A list is a kind of type marker, a wrapping type which points to another type. Lists are often created within the context of defining the fields of an object type.
type NonNull ¶
type NonNull struct {
Type Type
}
A non-null is a kind of type marker, a wrapping type which points to another type. Non-null types enforce that their values are never null and can ensure an error is raised if this ever occurs during a request. It is useful for fields which you can make a strong guarantee on non-nullability, for example usually the id field of a database row will never be null.
type Object ¶
type Object struct { Name string `json:"name"` Desc string `json:"description"` Interfaces map[string]*Interface `json:"interfaces"` Fields map[string]*Field `json:"fields"` IsTypeOf interface{} `json:"-"` }
Almost all of the GraphQL types you define will be object types. Object types have a name, but most importantly describe their fields.
func (*Object) Description ¶
type Scalar ¶
type Scalar struct { Name string `json:"name"` Desc string `json:"description"` Serialize func(interface{}) (interface{}, error) `json:"-"` ParseValue func(interface{}) (interface{}, error) `json:"-"` ParseLiteral func(value ast.Value) error `json:"-"` }
The leaf values of any request and input values to arguments are Scalars (or Enums) and are defined with a name and a series of serialization functions used to ensure validity.
func (*Scalar) Description ¶
type Schema ¶
type Schema struct { TypeMap map[string]NamedType `json:"-"` Directives map[string]*Directive `json:"-"` Query Type `json:"query"` Mutation Type `json:"mutation"` Subscription Type `json:"subscription"` }
Schema used to validate and resolve the queries
type Selection ¶
type Selection struct { Name string Alias string Args interface{} SelectionSet *SelectionSet Directives []*Directive Loc errors.Location }
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.
type SelectionSet ¶
type SelectionSet struct { Loc errors.Location 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.
type Type ¶
type Type interface { String() string // IsType() is used to identify the interface that implements IsType, // preventing any interface from implementing IsType IsType() }
Operation corresponds to GraphQLType
type TypeResolve ¶
type Union ¶
type Union struct { Name string `json:"name"` Types map[string]*Object `json:"types"` Desc string `json:"description"` }
When a field can return one of a heterogeneous set of types, a Union type is used to describe what types are possible as well as providing a function to determine which type is actually used when the field is resolved.