Comments (2)
Is it easy to implement this feature? Do you have plan to implement it? Could you give us a guideline to implement it if you have no time?
from graphql-compose-relay.
No, I have not plan to implement it, cause does not use RANGE_ADD
. For simplicity, I completely reload relay connection in my app.
But with pleasure share ideas how it should be implemented.
Before, let look on what is it cursor
and how it works under the hood:
- for every document cursor keeps values from fields, by which you make the sort (e.g.
.sort({ _id: 1, age: 1}
) then you should construct such cursorbase64({_id: 34ef85...34, age: 28})
- sort can be proceeded only by
unique indexes
(to avoid overlapping) - when proceeding
before
andafter
arguments with the cursor, you should parse values from it and use them via search with operators.where({ _id: {$gt: 34ef85...34}, age: {$gt: 28}})
So the most tricky part is determining correct cursor
value for the nodeEdge. It can not be calculated in mutation without knowledge of how your connection (with which order/sorting) fetched your data on the client. And when you sending a mutation, you should provide sort
fields as arg to nodeEdge
for gathering correct cursor value.
The code will look something like this:
UserTC.get('$createOne').getTypeComposer().setField('nodeEdge', {
args: {
sort: UserTC.get('$connection.@sort'),
},
type: UserTC.get('$connection.edges'),
resolve: (source, args, context, info) => {
// PREPARE `node`
// console.dir(source, { depth: 4, color: true });
const node = source.record;
// PREPARE `cursor`
// console.dir(args, { depth: 4, color: true });
// see how constructed cursor https://github.com/nodkz/graphql-compose-connection/blob/master/src/connectionResolver.js#L190
const cursor = ...;
return {
cursor,
node
};
},
});
from graphql-compose-relay.
Related Issues (4)
- Relay-Modern Mutations? HOT 1
- Using Global Ids in *ById(s) Resolvers HOT 2
- not working? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-compose-relay.