connections

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package connections implement a generic GraphQL relay connection

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connection

func Connection[NodeType any, EdgeType Edge, ConType any](
	source []NodeType,
	edgeMaker EdgeMaker[NodeType],
	conMaker ConMaker[NodeType, EdgeType, ConType],
	input models.ConnectionInput) (*ConType, error)

Connection will paginate a source according to the input of a relay connection

func CursorToOffset

func CursorToOffset(cursor string) (int, error)

CursorToOffset re-derives the offset from the cursor string.

func OffsetToCursor

func OffsetToCursor(offset int) string

OffsetToCursor create the cursor string from an offset

Types

type ConMaker

type ConMaker[NodeType any, EdgeType Edge, ConType any] func(
	edges []*EdgeType,
	nodes []NodeType,
	info *models.PageInfo,
	totalCount int) (*ConType, error)

ConMaker defines a function that creates a ConnectionType

type Edge

type Edge interface {
	GetCursor() string
}

Edge define the contract for an edge in a relay connection

type EdgeMaker

type EdgeMaker[NodeType any] func(value NodeType, offset int) Edge

EdgeMaker defines a function that takes a NodeType and an offset and create an Edge.

type LazyBugEdge

type LazyBugEdge struct {
	Id     entity.Id
	Cursor string
}

LazyBugEdge is a special relay edge used to implement a lazy loading connection

func (LazyBugEdge) GetCursor

func (lbe LazyBugEdge) GetCursor() string

GetCursor return the cursor of a LazyBugEdge

type LazyIdentityEdge

type LazyIdentityEdge struct {
	Id     entity.Id
	Cursor string
}

LazyIdentityEdge is a special relay edge used to implement a lazy loading connection

func (LazyIdentityEdge) GetCursor

func (lbe LazyIdentityEdge) GetCursor() string

GetCursor return the cursor of a LazyIdentityEdge

Jump to

Keyboard shortcuts

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