graphql

package
v0.0.8-b Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Boolean = &graphql.Definition{
	Kind:        graphql.Scalar,
	Name:        "Boolean",
	Description: "Represents true of false.",
}

Boolean is a scalar type that represents true or false.

View Source
var DateTime = &graphql.Definition{
	Kind: graphql.Scalar,
	Name: "DateTime",
}
View Source
var DefaultDecoder = new(Decoder)
View Source
var Float = &graphql.Definition{
	Kind:        graphql.Scalar,
	Name:        "Float",
	Description: "A signed double-precision finite value as specified by IEEE 754.",
}

Float is a scalar type that represents signed double-precision finite values as specified by IEEE 754.

View Source
var Int = &graphql.Definition{
	Kind:        graphql.Scalar,
	Name:        "Int",
	Description: "A signed 32-bit numeric non-fractional value.",
}

Int is a scalar type that represents a signed 32-bit numeric non-fractional value.

View Source
var String = &graphql.Definition{
	Kind:        graphql.Scalar,
	Name:        "String",
	Description: "A sequence of Unicode code points.",
}

String is a scalar type that represents a sequence of Unicode code points.

Functions

func CanonicalModelName

func CanonicalModelName(modelName string) string

func IntrospectionHandler

func IntrospectionHandler(rw ResponseWriter, r *Request)

func NewHandler

func NewHandler(h Handler, schema *graphql.Schema) http.HandlerFunc

NewHandler returns a new HTTP handler that attempts to parse GraphQL request from URL, body, or form and executes request using the specifies schema.

On failed request parsing and execution method writes plain error message as a response.

func UnmarshalBoolean

func UnmarshalBoolean(raw string) (interface{}, error)

func UnmarshalDateTime

func UnmarshalDateTime(raw string) (interface{}, error)

func UnmarshalFloat

func UnmarshalFloat(raw string) (interface{}, error)

func UnmarshalInt

func UnmarshalInt(raw string) (interface{}, error)

func UnmarshalString

func UnmarshalString(raw string) (interface{}, error)

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder decodes GraphQL values.

func (*Decoder) Decode

func (d *Decoder) Decode(v *graphql.Value) (interface{}, error)

func (*Decoder) RegisterName

func (d *Decoder) RegisterName(name string, unmarshaler Unmarshaler)

RegisterName registers the type unmarshaler under the given name.

type ErrConstraintNotFound

type ErrConstraintNotFound struct {
	Operation  string
	Name       string
	Constraint string
}

func (ErrConstraintNotFound) Error

func (e ErrConstraintNotFound) Error() string

type ErrUnsupportedType

type ErrUnsupportedType struct {
	*graphql.Type
}

ErrUnsupportedType is returned by Decoder when attempting to decode an unsupported value type.

func (ErrUnsupportedType) Error

func (e ErrUnsupportedType) Error() string

type Handler

type Handler interface {
	Serve(ResponseWriter, *Request)
}

Handler responds to a GraphQL request.

Serve would write the reply to the ResponseWriter and then returns. Returning signals that the request is finished.

type HandlerFunc

type HandlerFunc func(ResponseWriter, *Request)

func (HandlerFunc) Serve

func (fn HandlerFunc) Serve(rw ResponseWriter, r *Request)

type Mapper

type Mapper struct {
	// contains filtered or unexported fields
}

func (*Mapper) Map

func (m *Mapper) Map() (http.Handler, error)

func (*Mapper) Match

func (m *Mapper) Match(
	via, path string,
	action actioncontroller.Action,
	constraints ...actioncontroller.Constraints,
)

func (*Mapper) Resources

func (m *Mapper) Resources(
	model actioncontroller.AbstractModel, controller actioncontroller.AbstractController,
)

type Request

type Request struct {
	Query         string                 `json:"query"`
	Variables     map[string]interface{} `json:"variables"`
	OperationName string                 `json:"operationName"`

	// Header contains the request underlying HTTP header fields.
	//
	// These headers must be provided by the underlying HTTP request.
	Header http.Header
	// contains filtered or unexported fields
}

Request represents a GraphQL request received by server or to be sent by a client.

func ParseRequest

func ParseRequest(r *http.Request, schema *graphql.Schema) (gr *Request, err error)

ParseRequest parses HTTP request and returns GraphQL request instance that contains all required parameters.

This function supports requests provided as part of URL parameters, within body as pure GraphQL request, within body as JSON request, and as part of form request.

Method ensures that query contains a valid GraphQL document and returns an error if it's not true.

func (*Request) Context

func (r *Request) Context() context.Context

Context returns the request's context.

The returned context is always non-nil; it defaults to the background context.

func (*Request) Operation

func (r *Request) Operation() string

func (*Request) WithContext

func (r *Request) WithContext(ctx context.Context) *Request

TODO: create a shallow copy of the request.

type ResponseWriter

type ResponseWriter interface {
	WriteData(k string, v interface{})
	WriteError(err error)
}

ResponseWriter interface is used by a GraphQL handler to construct a response.

type RoutingTable

type RoutingTable struct {
	// contains filtered or unexported fields
}

func NewRoutingTable

func NewRoutingTable() *RoutingTable

func (*RoutingTable) AddOperation

func (rt *RoutingTable) AddOperation(name string, action actioncontroller.Action)

func (*RoutingTable) Dispatch

func (rt *RoutingTable) Dispatch(r *Request, field *graphql.Field) (
	interface{}, error,
)

type Schema

type Schema struct {
	// contains filtered or unexported fields
}

func (*Schema) AddCreateOp

func (s *Schema) AddCreateOp(
	model *activerecord.Relation, action actioncontroller.Action,
) *graphql.FieldDefinition

func (*Schema) AddDestroyOp

func (s *Schema) AddDestroyOp(model *activerecord.Relation) *graphql.FieldDefinition

func (*Schema) AddIndexOp

func (s *Schema) AddIndexOp(model *activerecord.Relation) *graphql.FieldDefinition

func (*Schema) AddModel

func (s *Schema) AddModel(model *activerecord.Relation) *graphql.Definition

func (*Schema) AddShowOp

func (s *Schema) AddShowOp(model *activerecord.Relation) *graphql.FieldDefinition

type SchemaReflect

type SchemaReflect struct {
	// contains filtered or unexported fields
}

type TypeReflect

type TypeReflect struct {
	// contains filtered or unexported fields
}

func MakeType

func MakeType(schema *graphql.Schema, t *graphql.Type) *TypeReflect

func (*TypeReflect) Introspect

func (t *TypeReflect) Introspect() activesupport.Hash

func (*TypeReflect) Kind

func (t *TypeReflect) Kind() string

type Unmarshaler

type Unmarshaler interface {
	Unmarshal(raw string) (interface{}, error)
}

type UnmarshalerFunc

type UnmarshalerFunc func(raw string) (interface{}, error)

UnmarshalerFunc is a function adapter for Unmarshaler interface.

func (UnmarshalerFunc) Unmarshal

func (fn UnmarshalerFunc) Unmarshal(raw string) (interface{}, error)

Jump to

Keyboard shortcuts

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