Skip to Content
GraphQL Tools
DocumentationAPI@graphql-tools/mocksrctype-aliasesRelayStylePaginationMockOptions

Type Alias: RelayStylePaginationMockOptions<TContext, TArgs>

RelayStylePaginationMockOptions<TContext, TArgs> = object

Defined in: packages/mock/src/pagination.ts:12

Type Parameters

TContext

TContext

TArgs

TArgs extends RelayPaginationParams

Properties

allNodesFn?

optional allNodesFn?: AllNodesFn<TContext, TArgs>

Defined in: packages/mock/src/pagination.ts:58

A function that’ll be used to get all the nodes used for pagination.

By default, it will use the nodes of the field this pagination is attached to.

This option is handy when several paginable fields should share the same base nodes:

{ User: { friends: mockedRelayStylePagination(store), maleFriends: mockedRelayStylePagination(store, { allNodesFn: (userRef) => store .get(userRef, ['friends', 'edges']) .map((e) => store.get(e, 'node')) .filter((userRef) => store.get(userRef, 'sex') === 'male') }) } }

applyOnNodes?

optional applyOnNodes?: (nodeRefs, args) => Ref[]

Defined in: packages/mock/src/pagination.ts:34

Use this option to apply filtering or sorting on the nodes given the arguments the paginated field receives.

{ User: { friends: mockedRelayStylePagination< unknown, RelayPaginationParams & { sortByBirthdateDesc?: boolean} >( store, { applyOnEdges: (edges, { sortByBirthdateDesc }) => { if (!sortByBirthdateDesc) return edges return _.sortBy(edges, (e) => store.get(e, ['node', 'birthdate'])) } }), } }

Parameters

nodeRefs

Ref[]

args

TArgs

Returns

Ref[]


cursorFn?

optional cursorFn?: (nodeRef) => string

Defined in: packages/mock/src/pagination.ts:66

The function that’ll be used to compute the cursor of a node.

By default, it’ll use MockStore internal reference Ref’s key as cursor.

Parameters

nodeRef

Ref

Returns

string