gqlconn

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package gqlconn provides utility types/functions for GraphQL Cursor Connections. <https://facebook.github.io/relay/graphql/connections.htm>

Index

Constants

View Source
const (
	// Both means bidirectional pagination.
	Both PaginationType = 0
	// Forward means forward pagination.
	Forward = 1
	// Backword means backword pagination.
	Backword = 2
)

Variables

View Source
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 Edges

type Edges []Edge

Edges provides array type of Edge.

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 PaginationType

type PaginationType int

PaginationType is directions of 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.

Jump to

Keyboard shortcuts

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