[ https://issues.apache.org/jira/browse/SLING-10309?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17342421#comment-17342421 ]
Bertrand Delacretaz commented on SLING-10309: --------------------------------------------- I have now added our own pagination interfaces in that branch. I don't think we need the relay stuff, those are simple and by using our own we avoid exposing the graphql-java APIs, as we have done so far. And I would argue that {{ResultsPage}} is a better name than {{Connection}} in this context. With this I'm getting results as shown below, in the {{PaginationTest}}. If we agree with this design I think the next is to generalize the "skip after desired cursor" logic from the {{HumansResultPage}} in that test class, and probably provide that logic as a utility class which takes a "skippable Stream" of objects as input. {code:java} { "data": { "paginatedQuery": { "pageInfo": { "startCursor": "aHVtYW4tNQ==", "endCursor": "aHVtYW4tMTE=", "hasPreviousPage": true, "hasNextPage": true }, "edges": [ { "cursor": "aHVtYW4tNg==", "node": { "id": "human-6", "name": "Luke-6" } }, { "cursor": "aHVtYW4tNw==", "node": { "id": "human-7", "name": "Luke-7" } }, { "cursor": "aHVtYW4tMTE=", "node": { "id": "human-11", "name": "Luke-11" } } ] } } } {code} > GraphQL results pagination > -------------------------- > > Key: SLING-10309 > URL: https://issues.apache.org/jira/browse/SLING-10309 > Project: Sling > Issue Type: Improvement > Components: GraphQL > Affects Versions: GraphQL Core 0.0.8 > Reporter: Bertrand Delacretaz > Assignee: Radu Cotescu > Priority: Major > > We need a way to paginate results in the GraphQL Core module. > We did some research with Radu around this, here are our initial findings: > * Pagination should be based on cursors, not offsets. There's a good > explanation of why at > https://uxdesign.cc/why-facebook-says-cursor-pagination-is-the-greatest-d6b98d86b6c0 > * Pagination cursors should be opaque. They are often encoded in Base64 to > express that, although that doesn't make much sense from a technical point of > view (being easy to decode) but helps convey the "consider this thing as > opaque" message. > * https://relay.dev/graphql/connections.htm defines a commonly accepted way > of expressing pagination in GraphQL results. > * Automatically generating the "plurals" types, like Articles for an Article > type, might be interesting and could include adding the required paging > fields. > * https://www.graphql-java-kickstart.com/tools/relay/ mentions the > {{RelayConnectionFactory}} as a useful tool to generate the "standard" paging > information > * The {{SlingDataFetcherEnvironment}} needs to provide paging information > such as the current cursor value and how many items are expected starting > after it > * The "Just the factoids" section of https://api.slack.com/docs/pagination > nicely describes pagination in the Slack API, we should have something like > that to clarify our "pagination pattern" and allow that pattern to be reused > in other parts of Sling if needed. -- This message was sent by Atlassian Jira (v8.3.4#803005)