Graphql-tools: How to do pagination?

Created on 28 Nov 2016  路  2Comments  路  Source: ardatan/graphql-tools

All the info I find is about Apollo client, with no information as to how this should work on the server.

Most helpful comment

@scf4 yeah, that's the way to do connections. graphql-tools doesn't contain any special helpers for this (yet?).

All 2 comments

I guess this is the way to do it...? I just thought maybe there was a simpler way:

  type Post { 
    comments: CommentContainer
  }
  type CommentContainer {
    edges: [CommentEdge],
    cursor: String,
  }
  type CommentEdge {
    node: Comment
  }

Resolvers:

Post: {
  comments(post, args, ctx) {
    return Post.find({ PostId: post.id })
  },
},
CommentContainer: {
  cursor() {
    return "...";
  },
  edges(container, args, ctx) {
    return container;
  }
},
CommentEdge: {
  node(edges, args, ctx) {
    return edges;
  },
}

Edit: the proper terminology is connection rather than "container".

@scf4 yeah, that's the way to do connections. graphql-tools doesn't contain any special helpers for this (yet?).

Was this page helpful?
0 / 5 - 0 ratings