Documentation ¶
Index ¶
- Constants
- Variables
- func CursorToOffset(cursor ConnectionCursor) (int, error)
- func GetOffsetWithDefault(cursor ConnectionCursor, defaultOffset int) int
- func GlobalIDField(typeName string, idFetcher GlobalIDFetcherFn) *graphql.Field
- func MutationWithClientMutationID(config MutationConfig) *graphql.Field
- func NewConnectionArgs(configMap graphql.FieldConfigArgument) graphql.FieldConfigArgument
- func PluralIdentifyingRootField(config PluralIdentifyingRootFieldConfig) *graphql.Field
- func ToGlobalID(ttype string, id string) string
- type ArraySliceMetaInfo
- type Connection
- type ConnectionArguments
- type ConnectionArgumentsConfig
- type ConnectionConfig
- type ConnectionCursor
- type Edge
- type EdgeType
- type GlobalIDFetcherFn
- type GraphQLConnectionDefinitions
- type IDFetcherFn
- type MutationConfig
- type MutationFn
- type NodeDefinitions
- type NodeDefinitionsConfig
- type PageInfo
- type PluralIdentifyingRootFieldConfig
- type ResolveSingleInputFn
- type ResolvedGlobalID
Constants ¶
const PREFIX = "arrayconnection:"
Variables ¶
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 NewConnectionArgs ¶
func NewConnectionArgs(configMap graphql.FieldConfigArgument) graphql.FieldConfigArgument
func PluralIdentifyingRootField ¶
func PluralIdentifyingRootField(config PluralIdentifyingRootFieldConfig) *graphql.Field
func ToGlobalID ¶
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 Connection ¶
type Connection struct { Edges []*Edge `json:"edges"` PageInfo PageInfo `json:"pageInfo"` Total int `json:"total"` }
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 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 GraphQLConnectionDefinitions ¶
type GraphQLConnectionDefinitions struct { EdgeType *graphql.Object `json:"edgeType"` ConnectionType *graphql.Object `json:"connectionType"` }
func ConnectionDefinitions ¶
func ConnectionDefinitions(config ConnectionConfig) *GraphQLConnectionDefinitions
type IDFetcherFn ¶
type MutationConfig ¶
type MutationConfig struct { Name string `json:"name"` InputFields graphql.InputObjectConfigFieldMap `json:"inputFields"` OutputFields graphql.Fields `json:"outputFields"` MutateAndGetPayload MutationFn `json:"mutateAndGetPayload"` Description string `json:"description"` }
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 NodeDefinitions ¶
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 ResolveSingleInputFn ¶
type ResolveSingleInputFn func(input interface{}) interface{}
type ResolvedGlobalID ¶
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.