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

Run PageInfo.startCursor and endCursor through resolveCursor() ? #91

Open
BlooJeans opened this issue May 31, 2016 · 1 comment
Open
Labels

Comments

@BlooJeans
Copy link

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],
});
@productdevbook
Copy link

iam new write library ts-relay-cursor-paging

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

No branches or pull requests

3 participants