relay

package module
v0.0.0-...-5ccb520 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2020 License: MIT Imports: 10 Imported by: 0

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 ENDBRACE = "}"

ENDBRACE : ENDBRACE is ending brace.

View Source
const INDCOL = "column"

INDCOL : INDCOL is column identifier.

View Source
const INDKEY = "key"

INDKEY : INDKEY is key identifier.

View Source
const INDOP = "op"

INDOP : INDCOP is operation identifier.

View Source
const NILQUERY = "NIL"

NILQUERY : NILQUERY is blank query.

View Source
const OPAND = "&"

OPAND : OPAND is and condition to join multile filer criteria.

View Source
const OPBLANK = ""

OPBLANK : OPBLANK is no operation specified.

View Source
const OPOR = "|"

OPOR : OPOR is or condition to join multile filer criteria.

View Source
const ORDASC = "ASC"

ORDASC : ORDASC is ascending Order.

View Source
const ORDDESC = "DESC"

ORDDESC : ORDDESC is descending Order.

View Source
const PREFIX = "arrayconnection:"
View Source
const ProfileKeyCheck = "profileScoreData.profileID"

KeyCheck : Profile ID needs column

View Source
const SEPDATA = ":"

SEPDATA : SEPDATA is data seperator.

View Source
const SEPENTRY = ","

SEPENTRY : SEPENTRY is entry seperator.

View Source
const SPACE = " "

SPACE : SPACE.

View Source
const STARTBRACE = "{"

STARTBRACE : STARTBRACE is starting brace.

Variables

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

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

Functions

func CleanConditions

func CleanConditions(str string) string

CleanConditions : Function to Clean Sort Filter Conditions

func CursorToOffset

func CursorToOffset(cursor ConnectionCursor) (int, error)

Re-derives the offset from the cursor string.

func ExtractConditions

func ExtractConditions(sFilter string, bExtractForward bool) (pendingFilter string, curCondition string, curOperator string)

ExtractConditions : Extracts simplest conditions from complex conditions.

func Filter

func Filter(filterConditions string, val reflect.Value, arraySlice []interface{}) ([]interface{}, error)

Filter : Filters data on given filterConditions.

func FilterProfiles

func FilterProfiles(filterConditions string, sortCond string, val reflect.Value, arraySlice []interface{}) ([]interface{}, int, error)

FilterProfiles : Filters Profile data on given filterConditions.

func GetBalancePosition

func GetBalancePosition(sFilter string) (iBalancePos int, iLength int)

GetBalancePosition : Gets balancing position for condition.

func GetOffsetWithDefault

func GetOffsetWithDefault(cursor ConnectionCursor, defaultOffset int) int

func GetProfilesSubQueries

func GetProfilesSubQueries(filterConditions string) ([]string, error)

GetProfilesSubQueries : Function to Get Sub Queries with ProfileIDs

func GetQueryDetails

func GetQueryDetails(Query string) (Key string, Column string, Op string)

GetQueryDetails : Function to Get Query Details

func GetSubQueries

func GetSubQueries(str, s1, s2 string) []string

GetSubQueries : Function to Get Sub Queries

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 IsColumnNameValid

func IsColumnNameValid(Column *string, val reflect.Value) bool

IsColumnNameValid : To validate Column Name

func MergeFilterResults

func MergeFilterResults(dataMapLeft, dataMapRight map[int]DataSet, curOperation string) (map[int]DataSet, error)

MergeFilterResults : Merges Filter Conditions results

func MutationWithClientMutationID

func MutationWithClientMutationID(config MutationConfig) *graphql.Field

func PluralIdentifyingRootField

func PluralIdentifyingRootField(config PluralIdentifyingRootFieldConfig) *graphql.Field

func PriorityFilter

func PriorityFilter(filterConditions string, val reflect.Value, arraySlice []interface{}) ([]interface{}, error)

PriorityFilter : Filters data based on priority of given complex filterConditions.

func ResolveFilterConditions

func ResolveFilterConditions(filter string, val reflect.Value, dataMap map[int]DataSet) (map[int]DataSet, error)

ResolveFilterConditions : Resolve Filter Conditions based on priority

func StringLessOp

func StringLessOp(strFirst, strSecond string) bool

StringLessOp : Function to check Strings less operation

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"`
	StaticInfo string   `json:"staticInfo"`
}

func ConnectionFromArray

func ConnectionFromArray(data []interface{}, args ConnectionArguments, staticInfo string) *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,
	staticInfo string,
) *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 int              `json:"before"`
	After  int              `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
	Sort   ConnectionCursor `json:"sort"`
	Filter ConnectionCursor `json:"filter"`
}

Use NewConnectionArguments() to properly initialize default values

func NewConnectionArguments

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

type ConnectionArgumentsConfig

type ConnectionArgumentsConfig struct {
	Before int `json:"before"`
	After  int `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"`

	Sort   ConnectionCursor `json:"sort"`
	Filter ConnectionCursor `json:"filter"`
}

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 DataSet

type DataSet struct {
	CurRec interface{}
	// contains filtered or unexported fields
}

DataSet : DataSet is data type used for filtering data.

type DataSorter

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

DataSorter : DataSorter combines SortBy function and data to sort

func (*DataSorter) Len

func (s *DataSorter) Len() int

Len : Len gives length of data to sort

func (*DataSorter) Less

func (s *DataSorter) Less(i, j int) bool

Less : Less will be called by calling SortBy closure in the sorter

func (*DataSorter) Swap

func (s *DataSorter) Swap(i, j int)

Swap : Swap is function to swap elements

type Edge

type Edge struct {
	Node   interface{} `json:"node"`
	Cursor int         `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     int  `json:"startCursor"`
	EndCursor       int  `json:"endCursor"`
	HasPreviousPage bool `json:"hasPreviousPage"`
	HasNextPage     bool `json:"hasNextPage"`
	TotalCount      int  `json:"totalCount"`
}

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.

type SortBy

type SortBy func(p1, p2 interface{}) bool

SortBy : SortBy is function type of less function

func (SortBy) Sort

func (sortBy SortBy) Sort(obj []interface{})

Sort : Sort is a function on functiontype

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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