When I create a connection query and execute it with:
someQuery(first: 3) { ... }
This will give me the first 3 result and the cursors if I requested it.
Then if I do this:
someQuery(first: 3, after: "abcdefg12345"){ ... }
This will give the NEXT 3 items after the passed cursor.
But If I observer the server, I can see the resolver working and hitting the server. HOWEVER, if the first query returned only 3 due to a limit (i.e. MongoCollection.find(...).limit(args.first)), then the second query with the cursor will NOT return the next set of 3 even if a skip() was applied to the mongo query.
Yet I still see the request being made to the server and the resolver working.
Why??
If the output has changed because of other arguments, and if the request was still made to the server, why does the cursor prevent me from seeing the new data set??
Your question is not related to Relay.
Relay is wrapper for React on client side.
resolve functions work on server side via graphql module. This module is agnostic to any underlying data-source (eg. mongodb, postgresql, mysql, redis). So you need read graphql specification to implement resolving such types of queries. So your question is not related to graphql too.
You may read how connection works here:
For you, I can recommend use graffiti-mongoose - a wrapper for graphql and mongoose.
As first introduction you may read:
But graffiti-mongoose weakly implements pagination and cursors, you may read following issue: https://github.com/RisingStack/graffiti-mongoose/issues/99 Pagination with cursors works only with ordering by ID.
The brave implementation of cursors for mongodb I don't find yet.
Be aware with graffiti-mongoose right now it also weakly allow extend schema with custom types and resolvers. Right now I implement my own wrapper for mongoDB, but it not ready for OSS due continuously changing API while I developing and adopting it to my real app case. My wrapper also does not solve cursor problem for mongodb.
_So if you find good realisation for mongodb and cursors, please let me know._
Thanks for the question, @ashah888, and for the amazing answer @nodkz.
Most helpful comment
Your question is not related to Relay.
Relay is wrapper for React on client side.
resolvefunctions work on server side viagraphqlmodule. This module is agnostic to any underlying data-source (eg. mongodb, postgresql, mysql, redis). So you need readgraphqlspecification to implement resolving such types of queries. So your question is not related tographqltoo.You may read how connection works here:
For you, I can recommend use graffiti-mongoose - a wrapper for graphql and mongoose.
As first introduction you may read:
But
graffiti-mongooseweakly implements pagination and cursors, you may read following issue: https://github.com/RisingStack/graffiti-mongoose/issues/99 Pagination with cursors works only with ordering by ID.The brave implementation of cursors for mongodb I don't find yet.
Be aware with
graffiti-mongooseright now it also weakly allow extend schema with custom types and resolvers. Right now I implement my own wrapper for mongoDB, but it not ready for OSS due continuously changing API while I developing and adopting it to my real app case. My wrapper also does not solve cursor problem for mongodb._So if you find good realisation for mongodb and cursors, please let me know._