graphql

package
v5.10.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT, MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultResolver

func DefaultResolver(source interface{}, fieldName string) (interface{}, error)

DefaultResolver uses reflection to attempt to resolve the result of a given field.

Heavily borrows from: https://github.com/graphql-go/graphql/blob/9b68c99d07d901738c15564ec1a0f57d07d884a7/executor.go#L823-L881

func InputType

func InputType(name string) graphql.Input

InputType mocks a type (InputObject, Scalar, Enum, etc.)

func Interface

func Interface(name string) *graphql.Interface

Interface mocks an interface

func Object

func Object(name string) *graphql.Object

Object mocks an interface

func OutputType

func OutputType(name string) graphql.Output

OutputType mocks a type (Object, Scalar, Enum, etc.)

Types

type EnumDesc

type EnumDesc struct {
	// Config thunk returns copy of config
	Config func() graphql.EnumConfig
}

EnumDesc describes enum configuration and handlers for use by service.

type FieldHandler

type FieldHandler func(impl interface{}) graphql.FieldResolveFn

FieldHandler given implementation configures field resolver

type InputDesc

type InputDesc struct {
	// Config thunk returns copy of config
	Config func() graphql.InputObjectConfig
}

InputDesc describes input configuration and handlers for use by service.

type InterfaceDesc

type InterfaceDesc struct {
	// Config thunk returns copy of config
	Config func() graphql.InterfaceConfig
}

InterfaceDesc describes interface configuration and handlers for use by service.

type InterfaceTypeResolver

type InterfaceTypeResolver interface {
	ResolveType(interface{}, ResolveTypeParams) *Type
}

InterfaceTypeResolver represents a collection of methods whose products represent the input and response values of a interface type.

== Example input SDL

"Pets are the bestest family members"
interface Pet {
  "name of this fine beast."
  name: String!
}

== Example implementation

// PetResolver implements InterfaceTypeResolver
type PetResolver struct {
  logger    logrus.LogEntry
}

// ResolveType should return type reference
func (r *PetResolver) ResolveType(val interface {}, _ graphql.ResolveTypeParams) graphql.Type {
  // ... implementation details ...
  switch pet := val.(type) {
  when *Dog:
    return schema.DogType // Handled by type identified by 'Dog'
  when *Cat:
    return schema.CatType // Handled by type identified by 'Cat'
  }
  panic("Unimplemented")
}`,

type IsTypeOfParams

type IsTypeOfParams = graphql.IsTypeOfParams

IsTypeOfParams used in IsTypeOf fn

type Kind

type Kind uint16

Kind is an unsigned 16-bit integer used for defining kinds.

const (
	// EnumKind identifies enum config
	EnumKind Kind = iota
	// InputKind identifies input object config
	InputKind
	// InterfaceKind identifies interface config
	InterfaceKind
	// ObjectKind identifies object config
	ObjectKind
	// ScalarKind identifies scalar config
	ScalarKind
	// SchemaKind identifies schema config
	SchemaKind
	// UnionKind identifies union config
	UnionKind
)

type ObjectDesc

type ObjectDesc struct {
	// Config thunk returns copy of config
	Config func() graphql.ObjectConfig
	// FieldHandlers handlers that wrap each field resolver.
	FieldHandlers map[string]FieldHandler
}

ObjectDesc describes object configuration and handlers for use by service.

type ResolveInfo

type ResolveInfo = graphql.ResolveInfo

ResolveInfo is a collection of information about the current execution state

type ResolveParams

type ResolveParams = graphql.ResolveParams

ResolveParams params for field resolvers

type ResolveTypeParams

type ResolveTypeParams = graphql.ResolveTypeParams

ResolveTypeParams used in ResolveType fn

type ScalarDesc

type ScalarDesc struct {
	// Config thunk returns copy of config
	Config func() graphql.ScalarConfig
}

ScalarDesc describes scalar configuration and handlers for use by service.

type ScalarResolver

type ScalarResolver interface {
	// Serialize an internal value to include in a response.
	Serialize(interface{}) interface{}

	// ParseValue parses an externally provided value to use as an input.
	ParseValue(interface{}) interface{}

	// ParseLiteral parses an externally provided literal value to use as an input.
	ParseLiteral(ast.Value) interface{}
}

ScalarResolver represents a collection of methods whose products represent the input and response values of a scalar type.

== Example input SDL

"""
Timestamps are great.
"""
scalar Timestamp

== Example implementation

// MyTimestampResolver implements ScalarResolver interface
type MyTimestampResolver struct {
  defaultTZ *time.Location
  logger    logrus.LogEntry
}

// Serialize serializes given date into RFC 943 compatible string.
func (r *MyTimestampResolver) Serialize(val interface{}) interface{} {
  // ... implementation details ...
}

// ParseValue takes given value and coerces it into an instance of Time.
func (r *MyTimestampResolver) ParseValue(val interface{}) interface{} {
  // ... implementation details ...
  // eg. if val is an int use time.At(), if string time.Parse(), etc.
}

// ParseValue takes given value and coerces it into an instance of Time.
func (r *MyTimestampResolver) ParseValue(val ast.Value) interface{} {
  // ... implementation details ...
  //
  // eg.
  //
  // if string value return value,
  // if IntValue Atoi and return value,
  // etc.
}`

type SchemaDesc

type SchemaDesc struct {
	// Config thunk returns copy of config
	Config func() graphql.SchemaConfig
}

SchemaDesc describes schema configuration and handlers for use by service.

type Service

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

Service ...TODO...

func NewService

func NewService() *Service

NewService returns new instance of Service

func (*Service) Do

func (service *Service) Do(
	ctx context.Context,
	q string,
	vars map[string]interface{},
) *graphql.Result

Do executes request given query string

func (*Service) Regenerate

func (service *Service) Regenerate() error

Regenerate generates new schema given registered types.

func (*Service) RegisterEnum

func (service *Service) RegisterEnum(t EnumDesc)

RegisterEnum registers a GraphQL type with the service.

func (*Service) RegisterInput

func (service *Service) RegisterInput(t InputDesc)

RegisterInput registers a GraphQL type with the service.

func (*Service) RegisterInterface

func (service *Service) RegisterInterface(t InterfaceDesc, impl InterfaceTypeResolver)

RegisterInterface registers a GraphQL type with the service.

func (*Service) RegisterObject

func (service *Service) RegisterObject(t ObjectDesc, impl interface{})

RegisterObject registers a GraphQL type with the service.

func (*Service) RegisterObjectExtension

func (service *Service) RegisterObjectExtension(t ObjectDesc, impl interface{})

RegisterObjectExtension registers a GraphQL type with the service.

func (*Service) RegisterScalar

func (service *Service) RegisterScalar(t ScalarDesc, impl ScalarResolver)

RegisterScalar registers a GraphQL type with the service.

func (*Service) RegisterSchema

func (service *Service) RegisterSchema(t SchemaDesc)

RegisterSchema registers given GraphQL schema with the service.

func (*Service) RegisterUnion

func (service *Service) RegisterUnion(t UnionDesc, impl UnionTypeResolver)

RegisterUnion registers a GraphQL type with the service.

type Type

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

Type represents base description of GraphQL type

func NewType

func NewType(name string, kind Kind) Type

NewType returns new instance of Type

func (Type) Kind

func (t Type) Kind() Kind

Kind of GraphQL type represented

func (Type) Name

func (t Type) Name() string

Name of GraphQL type represented

type UnionDesc

type UnionDesc struct {
	// Config thunk returns copy of config
	Config func() graphql.UnionConfig
}

UnionDesc describes union configuration and handlers for use by service.

type UnionTypeResolver

type UnionTypeResolver interface {
	ResolveType(interface{}, ResolveTypeParams) *Type
}

UnionTypeResolver represents a collection of methods whose products represent the input and response values of a union type.

== Example input SDL

"""
Feed includes all stuff and things.
"""
union Feed = Story | Article | Advert

== Example implementation

// FeedResolver implements UnionTypeResolver
type FeedResolver struct {
  logger logrus.LogEntry
}

// ResolveType should return type reference
func (r *FeedResolver) ResolveType(val interface {}, _ graphql.ResolveTypeParams) graphql.Type {
  // ... implementation details ...
  switch entity := val.(type) {
  when *Article:
    return schema.ArticleType
  when *Story:
    return schema.StoreType
  when *Advert:
    return schema.AdvertType
  }
  panic("Unimplemented")
}

Directories

Path Synopsis
Package contains only tests.
Package contains only tests.

Jump to

Keyboard shortcuts

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