I'm trying to implement Relay Connections in Apollo, but I have some problems with the specification.
Schema looks like this:
type PageInfo {
startCursor: String!,
endCursor: String!,
hasNextPage: Boolean!,
hasPreviousPage: Boolean!
}
type User : Node {
id: ID!
firstname: String
lastname: String
}
type UserConnection : Connection {
pageInfo: PageInfo!
edges: [UserEdge!]!
}
type UserEdge : Edge {
cursor: String!
node: User!
}
extend type Query {
users(first: Int, after: ID, order: String): UserConnection
}
Let's say I have 100 users in db; When I query with limit ex.users(first: 10), PageInfo.endCursor refers to the 10nth edge or the 100th?
More Questions:
1.Should I make another query to get hasPreviousPage, hasNextPage.
2.Are there any code examples(with resolvers) that have a similar structure?
3.Are there any graphql chats (gitter, irc)?
endCursor refers to the 10th, i.e. it's equal to the cursor field of the last edge in the result.
Generally-speaking, cursor-based pagination like this isn't bi-directional. So you can't know both hasNextPage
and hasPreviousPage
. But whichever you're fetching, you don't need to do issue it in another query, fetch as much data as you can in one query, that's the point!
There must be loads of examples of Relay's pagination around by now, I don't know any off the top of my head.
There's a slack team for Apollo and for GraphQL itself. apollographql.slack.com
and graphql.slack.com