Nested pagination with relay graphql
Asked Answered
J

0

11

Currently having an issue with the relay approach to nested pagination. An example below to illustrate what I mean:

{
  "data": {
    "locations": {
      "edges": [
        {
          "node": {
            "id": "Location_254"
          }
        },
        {
          "node": {
            "id": "Location_247"
          }
        },
        {
          "node": {
            "id": "Location_217"
          }
        },
      ]
    }
  }

Here I have 3 locations returned from a query. Now I wanted to paginate on these locations and look at their 'history'.

query {
  locations {
    edges {
      node {
        history(
          first:10
          after:"eyJzbm9vemVJZCI6Mzg3fQ=="
        )
      }
    }
  }
}

This would paginate 10 results after the specified cursor. My issue is, is that this cursor is specific to the location it was obtained from. The cursor it is referring to paginate after, only applies to the location it came from.

Nested pagination tries to paginate on ALL locations here, when in actuality, the cursor being used, was grabbed from a specific location.

Am I seeing this incorrectly, or is there a better way I could be approaching this issue?

Regards, Sebastian

Jodhpur answered 8/12, 2017 at 4:8 Comment(5)
I'd try to split the paginations into separate components / queries. Create a single location component and do your history pagination there.Hysterogenic
Possible duplicate of Relay Modern nested paginationHysterogenic
Nested pagination is useful for reducing number of requests, but I didn't find any documentation. I guess facebook has never considered this use case.Ori
My solution to this (with GitHub's GraphQL) is to only walk the locations 1 at a time. Which is unfortunately slow.Nila
you need a custom resolver to deal with this I believeTriviality

© 2022 - 2024 — McMap. All rights reserved.