Documentation ¶
Index ¶
- Variables
- func CursorToOffset(cursor ListCursor) (int, error)
- func GetOffsetWithDefault(cursor ListCursor, defaultOffset int) int
- func GlobalIDField(typeName string, idFetcher GlobalIDFetcherFn) *graphql.Field
- func MutationWithClientMutationID(config MutationConfig) *graphql.Field
- func NewListArgs(configMap graphql.FieldConfigArgument) graphql.FieldConfigArgument
- func PluralIdentifyingRootField(config PluralIdentifyingRootFieldConfig) *graphql.Field
- func ToGlobalID(ttype string, id string) string
- type ArraySliceMetaInfo
- type GlobalIDFetcherFn
- type GraphQLListDefinitions
- type IDFetcherFn
- type ItemDefinitions
- type ItemDefinitionsConfig
- type List
- type ListArguments
- type ListConfig
- type ListCursor
- type MutationConfig
- type MutationFn
- type PageInfo
- type PluralIdentifyingRootFieldConfig
- type ResolveSingleInputFn
- type ResolvedGlobalID
Constants ¶
This section is empty.
Variables ¶
var ListArgs = 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, }, }
ListArgs returns a GraphQLFieldConfigArgumentMap appropriate to include on a field whose return type is a list type.
Functions ¶
func CursorToOffset ¶
func CursorToOffset(cursor ListCursor) (int, error)
CursorToOffset re-derives the offset from the cursor string.
func GetOffsetWithDefault ¶
func GetOffsetWithDefault(cursor ListCursor, defaultOffset int) int
GetOffsetWithDefault extracts the offset of a cursor with a default value.
func GlobalIDField ¶
func GlobalIDField(typeName string, idFetcher GlobalIDFetcherFn) *graphql.Field
GlobalIDField creates the configuration for an id field on a Item, 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
MutationWithClientMutationID returns a GraphQLField for the mutation described by the provided MutationConfig.
func NewListArgs ¶
func NewListArgs(configMap graphql.FieldConfigArgument) graphql.FieldConfigArgument
NewListArgs adds pagination arguments to configMap
func PluralIdentifyingRootField ¶
func PluralIdentifyingRootField(config PluralIdentifyingRootFieldConfig) *graphql.Field
PluralIdentifyingRootField is ...
func ToGlobalID ¶
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 ArraySliceMetaInfo struct { SliceStart int `json:"sliceStart"` ArrayLength int `json:"arrayLength"` }
ArraySliceMetaInfo describes which part of array you want to work on.
type GlobalIDFetcherFn ¶
type GlobalIDFetcherFn func(obj interface{}, info graphql.ResolveInfo, ctx context.Context) (string, error)
GlobalIDFetcherFn returns the id of an object
type GraphQLListDefinitions ¶
GraphQLListDefinitions is the GraphQL object type for a list
func ListDefinitions ¶
func ListDefinitions(config ListConfig) *GraphQLListDefinitions
ListDefinitions returns a GraphQLObjectType for a list with the given name, and whose items are of the specified type.
type IDFetcherFn ¶
type IDFetcherFn func(id string, info graphql.ResolveInfo, ctx context.Context) (interface{}, error)
IDFetcherFn returns the the object from an id
type ItemDefinitions ¶
ItemDefinitions is the GraphQL object type for an item list
func NewItemDefinitions ¶
func NewItemDefinitions(config ItemDefinitionsConfig) *ItemDefinitions
NewItemDefinitions constructs a `Item` interface that objects can implement, and a field config for a `Item` root field, 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. 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 ItemDefinitionsConfig ¶
type ItemDefinitionsConfig struct { IDFetcher IDFetcherFn TypeResolve graphql.ResolveTypeFn }
ItemDefinitionsConfig is the configuration object for item list
type List ¶
type List struct { Items []interface{} `json:"items"` PageInfo PageInfo `json:"pageInfo"` TotalCount int `json:"totalCount"` }
List contains items with meta information about the content
func ListFromArray ¶
func ListFromArray(data []interface{}, args ListArguments) *List
ListFromArray is a simple function that accepts an array and list arguments, and returns a list object for use in GraphQL. It uses array offsets as pagination, so pagination will only work if the array is static.
func ListFromArraySlice ¶
func ListFromArraySlice( arraySlice []interface{}, args ListArguments, meta ArraySliceMetaInfo, ) *List
ListFromArraySlice returns a list object for use in GraphQL, given a slice (subset) of an array. This function is similar to `ListFromArray`, but is intended for use cases where you know the cardinality of the list, 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`.
type ListArguments ¶
type ListArguments struct { Before ListCursor `json:"before"` After ListCursor `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 }
ListArguments is pagination query arguments Use NewListArguments() to properly initialize default values
func NewListArguments ¶
func NewListArguments(filters map[string]interface{}) ListArguments
NewListArguments is a list arguments constructor
type ListConfig ¶
type ListConfig struct { Name string `json:"name"` ItemType *graphql.Object `json:"itemType"` ListFields graphql.Fields `json:"listFields"` }
ListConfig is the configuration object for list
type ListCursor ¶
type ListCursor string
ListCursor is an opaque index in a list
func CursorForObjectInList ¶
func CursorForObjectInList(data []interface{}, object interface{}) ListCursor
CursorForObjectInList returns the cursor associated with an object in an array.
func OffsetToCursor ¶
func OffsetToCursor(offset int) ListCursor
OffsetToCursor creates the cursor string from an offset
type MutationConfig ¶
type MutationConfig struct { Name string `json:"name"` InputFields graphql.InputObjectConfigFieldMap `json:"inputFields"` OutputFields graphql.Fields `json:"outputFields"` MutateAndGetPayload MutationFn `json:"mutateAndGetPayload"` }
MutationConfig description below 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)
MutationFn mutates and returns the payload
type PageInfo ¶
type PageInfo struct { StartCursor ListCursor `json:"startCursor"` EndCursor ListCursor `json:"endCursor"` HasPreviousPage bool `json:"hasPreviousPage"` HasNextPage bool `json:"hasNextPage"` }
PageInfo is the information about the current pagination of the list
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"` }
PluralIdentifyingRootFieldConfig is ...
type ResolveSingleInputFn ¶
type ResolveSingleInputFn func(input interface{}) interface{}
ResolveSingleInputFn is ...
type ResolvedGlobalID ¶
ResolvedGlobalID is the type and id of an object
func FromGlobalID ¶
func FromGlobalID(globalID string) *ResolvedGlobalID
FromGlobalID takes the "global ID" created by toGlobalID, and returns the type name and ID used to create it.