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?
optionalallNodesFn?: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?
optionalapplyOnNodes?: (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?
optionalcursorFn?: (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
Returns
string