Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please explain how cursors/connections work #1150

Closed
ashah888 opened this issue May 19, 2016 · 2 comments
Closed

Please explain how cursors/connections work #1150

ashah888 opened this issue May 19, 2016 · 2 comments

Comments

@ashah888
Copy link

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??

@nodkz
Copy link
Contributor

nodkz commented May 19, 2016

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: RisingStack/graffiti-mongoose#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.

@wincent
Copy link
Contributor

wincent commented May 19, 2016

Thanks for the question, @ashah888, and for the amazing answer @nodkz.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants