Documentation ¶
Index ¶
- Constants
- func MarshalMongoOidField(o primitive.ObjectID) (v string, err error)
- func MarshalTimeField(t time.Time) (v string, err error)
- type APICursor
- type Connection
- type CursorFieldType
- type CursorFilterField
- type CursorMarshaler
- type DocumentCursorText
- type Edge
- type ModelFactory
- type OrderDirection
- type PageInfo
Constants ¶
View Source
const ( GreaterThanFilterOperator = "$gt" LessThanFilterOperator = "$lt" )
View Source
const DefaultLimit = int32(10)
View Source
const MaxLimitAllowed = int32(1000)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APICursor ¶
type APICursor interface { // LoadFromAPIRequest loads a cursor from query input and sets the modelFactory. LoadFromAPIRequest(after *string, before *string, first *int, last *int, modelFactory ModelFactory) (err error) // AddCursorFilters adds an ordered list of cursor fields to the filter with logic and is intended to be called by a UnmarshalMongo() implementation. AddCursorFilters(findFilter bson.M, naturalSortDirection int, filterFields ...CursorFilterField) (err error) // SetTimeCursorFilter attempts to apply fieldName to the filter parsed as a time.Time // Deprecated: use AddCursorFilters SetTimeCursorFilter(findFilter bson.M, fieldName string, naturalSortDirection int) (err error) // SetUUIDCursorFilter attempts to apply fieldName to the filter parsed as a mongouuid.UUID // Deprecated: use AddCursorFilters SetUUIDCursorFilter(findFilter bson.M, fieldName string, naturalSortDirection int) (err error) // SetStringCursorFilter attempts to apply fieldName to the filter parsed as a string // Deprecated: use AddCursorFilters SetStringCursorFilter(findFilter bson.M, fieldName string, naturalSortDirection int) (err error) // FindLimit calculates the limit to a database query based on requested count FindLimit() int64 // CursorFilterSortDirection returns the sort direction (1 if ascending) or (-1 if descending) CursorFilterSortDirection(naturalSortDirection int) int // UnmarshalMongo unmarshals the cursor and applies it to a mongo map for use in a find filter. UnmarshalMongo(findFilter bson.M, naturalSortDirection int) (err error) // SetMarshaler sets the CursorMarshaler to use. This must be set before calling UnmarshalMongo or MarshalMongo, or they will return err. SetMarshaler(cursorMarshaler CursorMarshaler) // ConnectionFromMongoCursor takes a mongo cursor and returns a connection. SetMarshaler must be called first. ConnectionFromMongoCursor(ctx context.Context, mongoCursor *mongo.Cursor, totalDocsMatching int64) (connection Connection, err error) // SetModelFactory sets the modelFactory. SetModelFactory(modelFactory ModelFactory) // AfterCursor marshals the after cursor to a string. AfterCursor() (cursr string, err error) // BeforeCursor marshals the after cursor to a string. BeforeCursor() (cursr string, err error) }
type Connection ¶
type Connection interface { // SetEdges sets the edges on the current page. SetEdges(edges []Edge) // SetNodes sets the nodes for the current page. SetNodes(nodes []interface{}) // GetPageInfo returns the PageInfo GetPageInfo() *PageInfo // SetPageInfo sets the PageInfo SetPageInfo(pginfo *PageInfo) // GetTotalCount returns the total count of nodes in the connection (count of all nodes matching the query in all pages). GetTotalCount() uint64 // SetTotalCount sets the TotalCount. SetTotalCount(count uint64) }
Connection implements paging according to spec: https://relay.dev/graphql/connections.htm
type CursorFieldType ¶
type CursorFieldType int
const ( CursorFieldTypeTime CursorFieldType = iota CursorFieldTypeMongoOid CursorFieldTypeString )
func (CursorFieldType) Int ¶
func (t CursorFieldType) Int() int
type CursorFilterField ¶
type CursorFilterField struct { FieldName string FieldType CursorFieldType }
type CursorMarshaler ¶
type CursorMarshaler interface { // UnmarshalMongo attempts to apply cursors to a mongo filter map if they exist. Returns an error if the cursor is invalid. // c is the cursor to Unmarshal by calling SetTYPECursorFilter() functions. findFilter is the mongo find filter map to apply the cursor to. UnmarshalMongo(c APICursor, findFilter bson.M, naturalSortDirection int) (err error) // Marshal accepts a model type and returns an error or a map of key values for the document fields to serialize in the cursor. Marshal(obj interface{}) (cursorFields map[string]string, err error) }
CursorMarshaler is used to marshal and unmarshal cursors to and from data store query filters.
type DocumentCursorText ¶
type DocumentCursorText func(document interface{}) (err error)
type ModelFactory ¶
type ModelFactory interface { // New returns a new instance of the object New() interface{} NewConnection() Connection NewEdge() Edge }
ModelFactory is used to construct new objects when loading results
type OrderDirection ¶
type OrderDirection int
const ( ASC OrderDirection = 1 DESC OrderDirection = -1 )
func (OrderDirection) Int ¶
func (od OrderDirection) Int() int
type PageInfo ¶
type PageInfo struct { // When paginating forwards, the cursor to continue. EndCursor *string `json:"end_cursor"` // When paginating forwards, are there more items? HasNextPage bool `json:"has_next_page"` // When paginating backwards, are there more items? HasPreviousPage bool `json:"has_previous_page"` // When paginating backwards, the cursor to continue. StartCursor *string `json:"start_cursor"` }
Click to show internal directories.
Click to hide internal directories.