mongoose-relay-connection
Easiest and lightweight way to create a Relay Connection from Mongoose query for paginate thru.
Install
npm i mongoose-relay-connection --save
Use
Import connectionFromMongooseQuery
function from package to file with your Relay Connection definition:
Use it inside resolver of your connection (don't forget to await
!):
const PostsConnection = type: PostsConnectionType args: connectionArgs resolve: async { const query = Post return await }
Example
Full working example could look like so:
const connectionType: PostsConnectionType = const PostsConnection = type: PostsConnectionType args: connectionArgs resolve: async { const query = Post // Here you can add any filtering or sorting to your query return await }