GraphQL Cursor Based Pagination
# support
e
Hi Medplum Team! From what we're seeing it looks like cursor based pagination (described in FHIR standard here: https://hl7.org/fhir/graphql.html#searching) is not yet supported, or at least for all our queries the property
next
is always null, even when there are more items. Is this assessment accurate, and if so, is supporting cursor based pagination planned? i'm happy to create a ticket in github if that's the correct next step.
m
Hi @Elliot ! Cursor-based pagination is enabled by default if you
_sort=-_lastUpdated
, and you should be able to reach past the 10k resources mark. Our customers have been able to do with graphql when using this parameter (and nothing else added to _sort), it uses the same codepath as our normal search https://www.medplum.com/docs/search/paginated-search
e
Thanks @Maddy for taking a look. For non-graphQL search the
next
parameter (which contains the cursor) is packaged into the
Bundle
container and that's easy to find. The graphQL interface doesn't return this bundle structure but it does provider a
next
parameter on
*Connection
queries, for example:
Copy code
query {
  TaskConnection(_sort: "_lastUpdated") {
    next
    last
    first
    previous
    pageSize
    edges {
      resource {
        id
      }
    }
  }
}
running the above with
medplum.graphql
gives a response that looks like this:
Copy code
{
  "data": {
    "TaskConnection": {
      "next": null,
      "last": null,
      "first": null,
      "previous": null,
      "pageSize": 20,
      "edges": [...]
I checked the full http request to double check
next
wasn't returned in the headers or something. Can you tell the me the right way to access a cursor when using the graphQL interface? I checked all available docs and the original PR that implemented cursor search but it wasn't clear to me where the search links are exposed through GraphQL
m
Hi @Elliot , is there a chance that adding
link
to your query parameters might expose the next parameter?
e
link
isn't a parameter to the
TaskConnection
or
TaskList
query type, or a field of the`TaskConnection` or
TaskList
return types, so adding it anywhere on the query i shared above is just a type error:
Copy code
"details": {
              "text": "Cannot query field \"link\" on type \"TaskConnection\"."
            }
There is of course a
link
on the
Bundle
type and I assume this is what you're referencing (and also where we would find
_cursor
on a non-graphql query), but graphQL queries don't wrap the results in a Bundle by default and I don't see any way to construct a query where results for some arbitrary query are wrapped in a
Bundle
. if you have a basic working example of course please let me know.
c
Hi @Elliot - thanks for filing this. You are correct, it looks like the "next" link is absent from our implementation of the GraphQL Connection API. I filed a tracking ticket here with details on how to fix. The good news is that the
Bundle
has the values, it's just not being returned in the Connection API at the moment. https://github.com/medplum/medplum/issues/7428
Hi @Elliot - This has been fixed and merged. Can you please try again at your convenience? https://github.com/medplum/medplum/pull/7432
78 Views