graphql

package
Version: v0.0.0-...-f795d1e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2021 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BooleanType = schema.BooleanType

BooleanType implements the Boolean type as defined by the GraphQL spec.

View Source
var FloatType = schema.FloatType

FloatType implements the Float type as defined by the GraphQL spec.

View Source
var IDType = schema.IDType

IDType implements the ID type as defined by the GraphQL spec. It can be deserialized from a string or an integer type, but always serializes to a string.

View Source
var IncludeDirective = schema.IncludeDirective

IncludeDirective implements the @include directive as defined by the GraphQL spec.

View Source
var IntType = schema.IntType

IntType implements the Int type as defined by the GraphQL spec.

View Source
var SkipDirective = schema.SkipDirective

SkipDirective implements the @skip directive as defined by the GraphQL spec.

View Source
var StringType = schema.StringType

StringType implements the String type as defined by the GraphQL spec.

Functions

func FieldResolverCost

func FieldResolverCost(n int) func(*FieldCostContext) FieldCost

Returns a cost function which returns a constant resolver cost with no multiplier.

func IsSubscription

func IsSubscription(doc *ast.Document, operationName string) bool

IsSubscription returns true if the operation with the given name is a subscription operation. operationName can be "", in which case true will be returned if the only operation in the document is a subscription. In any error case (such as multiple matching subscriptions), false is returned.

Types

type Directive

type Directive = schema.Directive

Directive represents a GraphQL directive.

type DirectiveDefinition

type DirectiveDefinition = schema.DirectiveDefinition

DirectiveDefinition defines a directive.

type EnumType

type EnumType = schema.EnumType

EnumType represents a GraphQL enum type.

type EnumValueDefinition

type EnumValueDefinition = schema.EnumValueDefinition

EnumValueDefinition defines a possible value for an enum type.

type Error

type Error struct {
	Message   string        `json:"message"`
	Locations []Location    `json:"locations,omitempty"`
	Path      []interface{} `json:"path,omitempty"`

	// To populate this field, your resolvers can return errors that implement ExtendedError.
	Extensions map[string]interface{} `json:"extensions,omitempty"`
}

Error represents a GraphQL error as defined by the spec.

func ParseAndValidate

func ParseAndValidate(query string, schema *Schema, additionalRules ...ValidatorRule) (*ast.Document, []*Error)

ParseAndValidate parses and validates a query.

func Subscribe

func Subscribe(r *Request) (interface{}, []*Error)

Subscribe is used to implement subscription support. For subscribe operations (as indicated via IsSubscription), this should be invoked on Execute. On success it will return the result of executing the subscription field's resolver.

func (*Error) Error

func (err *Error) Error() string

type ExtendedError

type ExtendedError interface {
	error
	Extensions() map[string]interface{}
}

ExtendedError can be used to add data to a GraphQL error. If a resolver returns an error that implements this interface, the error's extensions property will be populated.

type FieldContext

type FieldContext = schema.FieldContext

FieldContext is provided to field resolvers and contains important context such as the current object and arguments.

type FieldCost

type FieldCost = schema.FieldCost

FieldCost describes the cost of resolving a field, enabling rate limiting and metering.

type FieldCostContext

type FieldCostContext = schema.FieldCostContext

FieldCostContext contains important context passed to field cost functions.

type FieldDefinition

type FieldDefinition = schema.FieldDefinition

FieldDefinition defines a field on an object type.

type InputObjectType

type InputObjectType = schema.InputObjectType

InputObjectType represents a GraphQL input object type.

type InputValueDefinition

type InputValueDefinition = schema.InputValueDefinition

InputValueDefinition defines an input value such as an argument.

type InterfaceType

type InterfaceType = schema.InterfaceType

InterfaceType represents a GraphQL interface type.

type ListType

type ListType = schema.ListType

ListType represents a GraphQL list type.

func NewListType

func NewListType(t Type) *ListType

NewListType creates a new list type with the given element type.

type Location

type Location struct {
	Line   int `json:"line"`
	Column int `json:"column"`
}

Location represents the location of a character within a query's source text.

type NamedType

type NamedType = schema.NamedType

NamedType represents any GraphQL named type.

type NonNullType

type NonNullType = schema.NonNullType

NonNullType represents a non-null GraphQL type.

func NewNonNullType

func NewNonNullType(t Type) *NonNullType

NewNonNullType creates a new non-null type with the given wrapped type.

type ObjectType

type ObjectType = schema.ObjectType

ObjectType represents a GraphQL object type.

type Request

type Request struct {
	Context context.Context

	Query string

	// In some cases, you may want to optimize by providing the parsed and validated AST document
	// instead of Query.
	Document *ast.Document

	Schema         *Schema
	OperationName  string
	VariableValues map[string]interface{}
	Extensions     map[string]interface{}
	InitialValue   interface{}
	IdleHandler    func()
}

Request defines all of the inputs required to execute a GraphQL query.

func NewRequestFromHTTP

func NewRequestFromHTTP(r *http.Request) (req *Request, code int, err error)

NewRequestFromHTTP constructs a Request from an HTTP request. Requests may be GET requests using query string parameters or POST requests with either the application/json or application/graphql content type. If the request is malformed, an HTTP error code and error are returned.

func (*Request) ValidateCost

func (r *Request) ValidateCost(max int, actual *int, defaultCost schema.FieldCost) ValidatorRule

Calculates the cost of the requested operation and ensures it is not greater than max. If max is -1, no limit is enforced. If actual is non-nil, it is set to the actual cost of the operation. Queries with costs that are too high to calculate due to overflows always result in an error when max is non-negative, and actual will be set to the maximum possible value.

type ResolvePromise

type ResolvePromise = executor.ResolvePromise

ResolvePromise can be used to resolve fields asynchronously. You may return ResolvePromise from the field's resolve function. If you do, you must define an IdleHandler for the request. Any time request execution is unable to proceed, the idle handler will be invoked. Before the idle handler returns, a result must be sent to at least one previously returned ResolvePromise.

type ResolveResult

type ResolveResult = executor.ResolveResult

ResolveResult represents the result of a field resolver. This type is generally used with ResolvePromise to pass around asynchronous results.

type Response

type Response struct {
	Data   *interface{} `json:"data,omitempty"`
	Errors []*Error     `json:"errors,omitempty"`
}

Response represents the result of executing a GraphQL query.

func Execute

func Execute(r *Request) *Response

Execute executes a query. If the request does not have a Document defined, the Query field will be parsed and validated.

type ScalarType

type ScalarType = schema.ScalarType

ScalarType represents a GraphQL scalar type.

type Schema

type Schema = schema.Schema

Schema represents a GraphQL schema.

func NewSchema

func NewSchema(def *SchemaDefinition) (*Schema, error)

NewSchema validates a schema definition and builds a Schema from it.

type SchemaDefinition

type SchemaDefinition = schema.SchemaDefinition

SchemaDefinition defines a GraphQL schema.

type Type

type Type = schema.Type

Type represents a GraphQL type.

type UnionType

type UnionType = schema.UnionType

UnionType represents a GraphQL union type.

type ValidatorRule

type ValidatorRule = validator.Rule

ValidatorRule defines a rule that the validator will evaluate.

func ValidateCost

func ValidateCost(operationName string, variableValues map[string]interface{}, max int, actual *int, defaultCost schema.FieldCost) ValidatorRule

Calculates the cost of the given operation and ensures it is not greater than max. If max is -1, no limit is enforced. If actual is non-nil, it is set to the actual cost of the operation. Queries with costs that are too high to calculate due to overflows always result in an error when max is non-negative, and actual will be set to the maximum possible value.

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL