relay

package module
v0.0.0-...-5435009 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2017 License: MIT Imports: 9 Imported by: 49

README

graphql-relay-go Build Status GoDoc Coverage Status

A Go/Golang library to help construct a graphql-go server supporting react-relay.

See a live demo here: http://bit.ly/try-graphql-go

Source code for demo can be found at https://github.com/graphql-go/playground

Notes:

This is based on alpha version of graphql-go and graphql-relay-go. Be sure to watch both repositories for latest changes.

Tutorial

Learn Golang + GraphQL + Relay Part 2: Your first Relay application

Test
$ go get github.com/graphql-go/relay
$ go build && go test ./...
TODO:
  • Starwars example
  • HTTP handler to easily create a Relay-compliant GraphQL server (Moved to: graphql-go-handler)
  • In-code documentation (godocs)
  • Usage guide / user documentation
  • Tutorial
  • End-to-end example (graphql-relay-go + react-relay)

Documentation

Index

Constants

View Source
const PREFIX = "arrayconnection:"

Variables

View Source
var ConnectionArgs = graphql.FieldConfigArgument{
	"before": &graphql.ArgumentConfig{
		Type: graphql.String,
	},
	"after": &graphql.ArgumentConfig{
		Type: graphql.String,
	},
	"first": &graphql.ArgumentConfig{
		Type: graphql.Int,
	},
	"last": &graphql.ArgumentConfig{
		Type: graphql.Int,
	},
}

Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field whose return type is a connection type.

Functions

func CursorToOffset

func CursorToOffset(cursor ConnectionCursor) (int, error)

Re-derives the offset from the cursor string.

func GetOffsetWithDefault

func GetOffsetWithDefault(cursor ConnectionCursor, defaultOffset int) int

func GlobalIDField

func GlobalIDField(typeName string, idFetcher GlobalIDFetcherFn) *graphql.Field

Creates the configuration for an id field on a node, using `toGlobalId` to construct the ID from the provided typename. The type-specific ID is fetcher by calling idFetcher on the object, or if not provided, by accessing the `id` property on the object.

func MutationWithClientMutationID

func MutationWithClientMutationID(config MutationConfig) *graphql.Field

func PluralIdentifyingRootField

func PluralIdentifyingRootField(config PluralIdentifyingRootFieldConfig) *graphql.Field

func ToGlobalID

func ToGlobalID(ttype string, id string) string

Takes a type name and an ID specific to that type name, and returns a "global ID" that is unique among all types.

Types

type ArraySliceMetaInfo

type ArraySliceMetaInfo struct {
	SliceStart  int `json:"sliceStart"`
	ArrayLength int `json:"arrayLength"`
}

type Connection

type Connection struct {
	Edges    []*Edge  `json:"edges"`
	PageInfo PageInfo `json:"pageInfo"`
}

func ConnectionFromArray

func ConnectionFromArray(data []interface{}, args ConnectionArguments) *Connection

A simple function that accepts an array and connection arguments, and returns a connection object for use in GraphQL. It uses array offsets as pagination, so pagination will only work if the array is static.

func ConnectionFromArraySlice

func ConnectionFromArraySlice(
	arraySlice []interface{},
	args ConnectionArguments,
	meta ArraySliceMetaInfo,
) *Connection

Given a slice (subset) of an array, returns a connection object for use in GraphQL.

This function is similar to `ConnectionFromArray`, but is intended for use cases where you know the cardinality of the connection, consider it too large to materialize the entire array, and instead wish pass in a slice of the total result large enough to cover the range specified in `args`.

func NewConnection

func NewConnection() *Connection

type ConnectionArguments

type ConnectionArguments struct {
	Before ConnectionCursor `json:"before"`
	After  ConnectionCursor `json:"after"`
	First  int              `json:"first"` // -1 for undefined, 0 would return zero results
	Last   int              `json:"last"`  //  -1 for undefined, 0 would return zero results
}

Use NewConnectionArguments() to properly initialize default values

func NewConnectionArguments

func NewConnectionArguments(filters map[string]interface{}) ConnectionArguments

type ConnectionArgumentsConfig

type ConnectionArgumentsConfig struct {
	Before ConnectionCursor `json:"before"`
	After  ConnectionCursor `json:"after"`

	// use pointers for `First` and `Last` fields
	// so constructor would know when to use default values
	First *int `json:"first"`
	Last  *int `json:"last"`
}

type ConnectionConfig

type ConnectionConfig struct {
	Name             string          `json:"name"`
	NodeType         *graphql.Object `json:"nodeType"`
	EdgeFields       graphql.Fields  `json:"edgeFields"`
	ConnectionFields graphql.Fields  `json:"connectionFields"`
}

type ConnectionCursor

type ConnectionCursor string

func CursorForObjectInConnection

func CursorForObjectInConnection(data []interface{}, object interface{}) ConnectionCursor

Return the cursor associated with an object in an array.

func OffsetToCursor

func OffsetToCursor(offset int) ConnectionCursor

Creates the cursor string from an offset

type Edge

type Edge struct {
	Node   interface{}      `json:"node"`
	Cursor ConnectionCursor `json:"cursor"`
}

type EdgeType

type EdgeType struct {
	Node   interface{}      `json:"node"`
	Cursor ConnectionCursor `json:"cursor"`
}

type GlobalIDFetcherFn

type GlobalIDFetcherFn func(obj interface{}, info graphql.ResolveInfo, ctx context.Context) (string, error)

type GraphQLConnectionDefinitions

type GraphQLConnectionDefinitions struct {
	EdgeType       *graphql.Object `json:"edgeType"`
	ConnectionType *graphql.Object `json:"connectionType"`
}

func ConnectionDefinitions

func ConnectionDefinitions(config ConnectionConfig) *GraphQLConnectionDefinitions

type IDFetcherFn

type IDFetcherFn func(id string, info graphql.ResolveInfo, ctx context.Context) (interface{}, error)

type MutationConfig

type MutationConfig struct {
	Name                string                            `json:"name"`
	InputFields         graphql.InputObjectConfigFieldMap `json:"inputFields"`
	OutputFields        graphql.Fields                    `json:"outputFields"`
	MutateAndGetPayload MutationFn                        `json:"mutateAndGetPayload"`
}

A description of a mutation consumable by mutationWithClientMutationId to create a GraphQLField for that mutation.

The inputFields and outputFields should not include `clientMutationId`, as this will be provided automatically.

An input object will be created containing the input fields, and an object will be created containing the output fields.

mutateAndGetPayload will receive an Object with a key for each input field, and it should return an Object with a key for each output field. It may return synchronously, or return a Promise.

type MutationFn

type MutationFn func(inputMap map[string]interface{}, info graphql.ResolveInfo, ctx context.Context) (map[string]interface{}, error)

type NodeDefinitions

type NodeDefinitions struct {
	NodeInterface *graphql.Interface
	NodeField     *graphql.Field
}

func NewNodeDefinitions

func NewNodeDefinitions(config NodeDefinitionsConfig) *NodeDefinitions
Given a function to map from an ID to an underlying object, and a function
to map from an underlying object to the concrete GraphQLObjectType it
corresponds to, constructs a `Node` interface that objects can implement,
and a field config for a `node` root field.

If the typeResolver is omitted, object resolution on the interface will be
handled with the `isTypeOf` method on object types, as with any GraphQL

interface without a provided `resolveType` method.

type NodeDefinitionsConfig

type NodeDefinitionsConfig struct {
	IDFetcher   IDFetcherFn
	TypeResolve graphql.ResolveTypeFn
}

type PageInfo

type PageInfo struct {
	StartCursor     ConnectionCursor `json:"startCursor"`
	EndCursor       ConnectionCursor `json:"endCursor"`
	HasPreviousPage bool             `json:"hasPreviousPage"`
	HasNextPage     bool             `json:"hasNextPage"`
}

type PluralIdentifyingRootFieldConfig

type PluralIdentifyingRootFieldConfig struct {
	ArgName            string               `json:"argName"`
	InputType          graphql.Input        `json:"inputType"`
	OutputType         graphql.Output       `json:"outputType"`
	ResolveSingleInput ResolveSingleInputFn `json:"resolveSingleInput"`
	Description        string               `json:"description"`
}

type ResolveSingleInputFn

type ResolveSingleInputFn func(input interface{}) interface{}

type ResolvedGlobalID

type ResolvedGlobalID struct {
	Type string `json:"type"`
	ID   string `json:"id"`
}

func FromGlobalID

func FromGlobalID(globalID string) *ResolvedGlobalID

Takes the "global ID" created by toGlobalID, and returns the type name and ID used to create it.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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