graphql / graphql/graphql-relay-js
Run PageInfo.startCursor and endCursor through resolveCursor() ?
- Dominant language
- TypeScript
- Stars
- 1.5k
- Forks
- 177
- Avg merge
- 10m
- Merged PRs (30d)
- 1
Description
In the case that you have a custom cursor defined via `resolveCursor`, I would think the generated pageInfo should also be run through it, else the `pageInfo.startCursor` / `pageInfo.endCursor` will be the default cursors, not the custom ones.
I actually ended up getting around this issue by generating my own pageInfo from scratch, since in my case connectionFromArray wasn't doing anything special for me (I'm pulling data from a DB, and don't have access to allItems), but if this was an oversight but intended behavior, I thought I'd bring it to light.
```
export const {connectionType: messageConnection, edgeType: MessageEdge} = connectionDefinitions({
name: 'Message',
nodeType: MessageType,
resolveCursor: ({cursor, node}) => {
return Base64.encode('createdAt:'+moment(node.get('createdAt')).unix());
},
});
```
```
export const PostType = new GraphQLObjectType({
name: 'Post',
description: 'Post',
fields: () => ({
id: globalIdField('Post'),
messages: {
type: messageConnection,
args: connectionArgs,
resolve: async (post, args) => {
let messages = await getMessages(post.id, args)
let connection = connectionFromArray(messages, args);
// connection.edges is still using the default cursors, because resolveCursor will only get called after this resolve returns
// likewise, connection.pageInfo.startCursor and connection.pageInfo.endCursor are using the default cursors, but they won't be re-resolved using my custom resolveCursor()
return connection;
},
},
}),
interfaces: [nodeInterface],
});
```
Contributor guide
Assessment
This issue has not been assessed yet.