pagination

package
v0.0.0-...-b0093ec Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPageSize = 20

Variables

This section is empty.

Functions

func Slice

func Slice[T any](slice []T, p *Pagination) []T

Types

type Connection

type Connection[T any] struct {
	Edges    []Edge[T] `json:"edges"`
	PageInfo PageInfo  `json:"pageInfo"`
}

func EmptyConnection

func EmptyConnection[T any]() *Connection[T]

func NewConnection

func NewConnection[T any, I Integer](nodes []T, page *Pagination, total I) *Connection[T]

func NewConnectionWithoutPagination

func NewConnectionWithoutPagination[T any](nodes []T) *Connection[T]

func NewConvertConnection

func NewConvertConnection[T any, F any, I Integer](nodes []T, page *Pagination, total I, fn func(from T) F) *Connection[F]

func NewConvertConnectionWithError

func NewConvertConnectionWithError[T any, F any, I Integer](nodes []T, page *Pagination, total I, fn func(from T) (F, error)) (*Connection[F], error)

func (*Connection[T]) Nodes

func (c *Connection[T]) Nodes() []T

type Cursor

type Cursor struct {
	Offset int `json:"offset"`
	// contains filtered or unexported fields
}

func (Cursor) MarshalGQLContext

func (c Cursor) MarshalGQLContext(_ context.Context, w io.Writer) error

func (*Cursor) UnmarshalGQLContext

func (c *Cursor) UnmarshalGQLContext(_ context.Context, v interface{}) error

type Edge

type Edge[T any] struct {
	Node   T      `json:"node"`
	Cursor Cursor `json:"cursor"`
}

type Integer

type Integer interface {
	int64 | int32 | int
}

type PageInfo

type PageInfo struct {
	TotalCount      int     `json:"totalCount"`
	HasNextPage     bool    `json:"hasNextPage"`
	HasPreviousPage bool    `json:"hasPreviousPage"`
	StartCursor     *Cursor `json:"startCursor"`
	EndCursor       *Cursor `json:"endCursor"`
}

func (*PageInfo) PageEnd

func (p *PageInfo) PageEnd() int

func (*PageInfo) PageStart

func (p *PageInfo) PageStart() int

type Pagination

type Pagination struct {
	// contains filtered or unexported fields
}

func ParsePage

func ParsePage(first *int, after *Cursor, last *int, before *Cursor) (*Pagination, error)

func (*Pagination) Limit

func (p *Pagination) Limit() int32

func (*Pagination) Offset

func (p *Pagination) Offset() int32

Jump to

Keyboard shortcuts

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