Documentation ¶
Index ¶
- Constants
- func CreateConnection(ctx context.Context, socket JSONSocket, schema *Schema, ...) *conn
- func CreateJSONSocket(ctx context.Context, socket JSONSocket, schema *Schema, makeCtx MakeCtxFunc, ...) *conn
- func CreateJSONSocketWithMutationSchema(ctx context.Context, socket JSONSocket, schema, mutationSchema *Schema, ...) *conn
- func ErrorCause(err error) error
- func HTTPHandler(schema *Schema, middlewares ...MiddlewareFunc) http.Handler
- func Handler(schema *Schema) http.Handler
- func NewClientError(format string, a ...interface{}) error
- func NewSafeError(format string, a ...interface{}) error
- func PrepareQuery(typ Type, selectionSet *SelectionSet) error
- func ServeJSONSocket(ctx context.Context, socket JSONSocket, schema *Schema, makeCtx MakeCtxFunc, ...)
- type ClientError
- type ComputationInput
- type ComputationOutput
- type ConnectionOption
- func WithExecutionLogger(logger GraphqlLogger) ConnectionOption
- func WithMakeCtx(makeCtx MakeCtxFunc) ConnectionOption
- func WithMaxSubscriptions(max int) ConnectionOption
- func WithMinRerunInterval(d time.Duration) ConnectionOption
- func WithMinRerunIntervalFunc(fn RerunIntervalFunc) ConnectionOption
- func WithMutationSchema(schema *Schema) ConnectionOption
- func WithSubscriptionLogger(logger SubscriptionLogger) ConnectionOption
- type Enum
- type Executor
- type Field
- type Fragment
- type GraphqlLogger
- type InputObject
- type JSONSocket
- type List
- type MakeCtxFunc
- type MiddlewareFunc
- type MiddlewareNextFunc
- type NonNull
- type Object
- type Query
- type RerunIntervalFunc
- type Resolver
- type SafeError
- type SanitizedError
- type Scalar
- type Schema
- type Selection
- type SelectionSet
- type SubscriptionLogger
- type Type
- type Union
Constants ¶
const ( DefaultMaxSubscriptions = 200 DefaultMinRerunInterval = 5 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func CreateConnection ¶
func CreateConnection(ctx context.Context, socket JSONSocket, schema *Schema, opts ...ConnectionOption) *conn
func CreateJSONSocket ¶
func CreateJSONSocket(ctx context.Context, socket JSONSocket, schema *Schema, makeCtx MakeCtxFunc, logger GraphqlLogger) *conn
CreateJSONSocket is deprecated. Consider using CreateConnection instead.
func CreateJSONSocketWithMutationSchema ¶
func CreateJSONSocketWithMutationSchema(ctx context.Context, socket JSONSocket, schema, mutationSchema *Schema, makeCtx MakeCtxFunc, logger GraphqlLogger) *conn
CreateJSONSocketWithMutationSchema is deprecated. Consider using CreateConnection instead.
func ErrorCause ¶ added in v0.5.0
func HTTPHandler ¶
func HTTPHandler(schema *Schema, middlewares ...MiddlewareFunc) http.Handler
func NewClientError ¶
func NewSafeError ¶
func PrepareQuery ¶
func PrepareQuery(typ Type, selectionSet *SelectionSet) error
PrepareQuery checks that the given selectionSet matches the schema typ, and parses the args in selectionSet
func ServeJSONSocket ¶
func ServeJSONSocket(ctx context.Context, socket JSONSocket, schema *Schema, makeCtx MakeCtxFunc, logger GraphqlLogger)
ServeJSONSocket is deprecated. Consider using CreateConnection instead.
Types ¶
type ClientError ¶
type ClientError SafeError
func (ClientError) Error ¶
func (e ClientError) Error() string
func (ClientError) SanitizedError ¶
func (e ClientError) SanitizedError() string
type ComputationInput ¶
type ComputationOutput ¶
func RunMiddlewares ¶ added in v0.5.0
func RunMiddlewares(middlewares []MiddlewareFunc, input *ComputationInput) *ComputationOutput
type ConnectionOption ¶
type ConnectionOption func(*conn)
func WithExecutionLogger ¶
func WithExecutionLogger(logger GraphqlLogger) ConnectionOption
func WithMakeCtx ¶
func WithMakeCtx(makeCtx MakeCtxFunc) ConnectionOption
func WithMaxSubscriptions ¶
func WithMaxSubscriptions(max int) ConnectionOption
func WithMinRerunInterval ¶
func WithMinRerunInterval(d time.Duration) ConnectionOption
func WithMinRerunIntervalFunc ¶ added in v0.4.0
func WithMinRerunIntervalFunc(fn RerunIntervalFunc) ConnectionOption
WithMinRerunIntervalFunc is deprecated.
func WithMutationSchema ¶
func WithMutationSchema(schema *Schema) ConnectionOption
func WithSubscriptionLogger ¶
func WithSubscriptionLogger(logger SubscriptionLogger) ConnectionOption
type Field ¶
type Field struct { Resolve Resolver Type Type Args map[string]Type ParseArguments func(json interface{}) (interface{}, error) Expensive bool }
Field knows how to compute field values of an Object
Fields are responsible for computing their value themselves.
type Fragment ¶
type Fragment struct { On string SelectionSet *SelectionSet }
A Fragment represents a reusable part of a GraphQL query
The On part of a Fragment represents the type of source object for which this Fragment should be used. That is not currently implemented in this package.
type GraphqlLogger ¶
type InputObject ¶
func (*InputObject) String ¶
func (io *InputObject) String() string
type JSONSocket ¶
type MiddlewareFunc ¶
type MiddlewareFunc func(input *ComputationInput, next MiddlewareNextFunc) *ComputationOutput
type MiddlewareNextFunc ¶
type MiddlewareNextFunc func(input *ComputationInput) *ComputationOutput
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 PrepareQuery.
type RerunIntervalFunc ¶ added in v0.4.0
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 SafeError ¶
type SafeError struct {
// contains filtered or unexported fields
}
func (SafeError) SanitizedError ¶
type SanitizedError ¶
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 // contains filtered or unexported fields }
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
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 ¶
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 SubscriptionLogger ¶
type SubscriptionLogger interface { // Subscribe is called when a new subscription is started. Subscribe is not // called for queries that fail to parse or validate. Subscribe(ctx context.Context, id string, tags map[string]string) // Unsubscribe is called when a subscription ends. It is guaranteed // to be called even if the subscription ends due to the connection closing. // The id argument corresponds to the id tag. Unsubscribe(ctx context.Context, id string) }