Documentation ¶
Overview ¶
Package gqlconn provides utility types/functions for GraphQL Cursor Connections. <https://facebook.github.io/relay/graphql/connections.htm>
Index ¶
Constants ¶
const ( // Both means bidirectional pagination. Both PaginationType = 0 // Forward means forward pagination. Forward = 1 // Backword means backword pagination. Backword = 2 )
Variables ¶
var PageInfoType = graphql.NewObject(graphql.ObjectConfig{ Name: "PageInfo", Fields: graphql.Fields{ "hasNextPage": &graphql.Field{ Type: graphql.NewNonNull(graphql.Boolean), Description: "whether more edges exist prior", }, "hasPrevPage": &graphql.Field{ Type: graphql.NewNonNull(graphql.Boolean), Description: "whether more edges exist following", }, "startCursor": &graphql.Field{ Type: graphql.NewNonNull(graphql.String), Description: "cursor of the top edge", }, "endCursor": &graphql.Field{ Type: graphql.NewNonNull(graphql.String), Description: "cursor of the tail edge", }, }, Description: "pagination information", })
PageInfoType provides named type for page information.
Functions ¶
func NewCollectionType ¶
func NewCollectionType(cfg CollectionConfig) *graphql.Object
NewCollectionType creates a name type for collection.
Types ¶
type CollectionConfig ¶
type CollectionConfig struct { NodeType graphql.Type ResolveCount ResolveCountFn ResolveEdges ResolveEdgesFn ResolvePageInfo ResolvePageInfoFn }
CollectionConfig is a configuration for the collection type.
type Edge ¶
type Edge struct { Node interface{} `json:"node"` Cursor string `json:"cursor"` }
Edge provides a struct for each edge in connection.
type PageInfo ¶
type PageInfo struct { HasNextPage bool `json:"hasNextPage"` HasPrevPage bool `json:"hasPrevPage"` StartCursor string `json:"startCursor"` EndCursor string `json:"endCursor"` }
PageInfo provides a struct for page information.
type PaginationConfig ¶
type PaginationConfig struct { Type PaginationType DefaultFirst int DefaultLast int }
PaginationConfig is configuration for pagination args.
func (PaginationConfig) FieldConfigArgument ¶
func (pc PaginationConfig) FieldConfigArgument() graphql.FieldConfigArgument
FieldConfigArgument creates FieldConfigArgument for pagination.
func (PaginationConfig) Parse ¶
func (pc PaginationConfig) Parse(args map[string]interface{}) (*PaginationParams, error)
Parse parses args as PaginationParams.
type PaginationParams ¶
type PaginationParams struct { // Backword is `true` for backward pagination, `false` for forward. Backword bool // Pivot is cursor of the exclusive pivot for pagination. Pivot string // Size is number of edges in a page. Size int }
PaginationParams is a parameter set for pagination.
type ResolveCountFn ¶
type ResolveCountFn func(graphql.ResolveParams) (int, error)
ResolveCountFn is a resolver for edge count.
type ResolveEdgesFn ¶
type ResolveEdgesFn func(graphql.ResolveParams) (Edges, error)
ResolveEdgesFn is a resolver for Edges ([]Edge).
type ResolvePageInfoFn ¶
type ResolvePageInfoFn func(graphql.ResolveParams) (*PageInfo, error)
ResolvePageInfoFn is a resolver for PageInfo.