This repo is to show an example someone who wants to implement relay pagination on your project.
relayFunction
returns Connection
type which is needed for pagination, so you can use this function directly on your resolver.
const resolver: Resolver = {
Query: {
todos: async (_, args, {prisma}) => {
return await relayPagination({
prisma,
args,
type: 'todo',
options: {
orderBy: {id: 'desc'}
}
})
}
}
}
-
prisma :
relayPagination
function uses prisma client internally, you should pass prisma client instance. -
args:
args
is for cursor pagination input likefirst
,after
. Since this function is only support forward pagination, you just need to pass 2 args.first
is an amount of rows you want to query at first.after
is a cursor string that returns inedge
. -
type:
type
is prisma data model you want to. you should pass valid model name to type. -
options:
options
is for additional arguments for prismafindMany
method.
This function is only support forward pagination. If you want to know more about this, please check specification here.