graphiti-api / graphiti

Stylish Graph APIs
https://www.graphiti.dev/
MIT License
960 stars 138 forks source link

Support cursor-based pagination #372

Closed richmolj closed 2 years ago

richmolj commented 2 years ago

We currently support a page[offset] parameter. This updates the codebase to accept before and after cursors, applying the relevant offset logic as appropriate.

When JSON:API we're render meta: { cursor: <cursor> } for each entity, and when flat JSON/GraphQL we'll render _cursor: <cursor>. This is to support GQL queries like

employees {
  nodes {
    firstName
    _cursor
  }
}

We're not doing a full edges implementation because A) I just kinda hate it and B) to value here is metadata about the relationship, mostly for M2M relationships, which Graphiti doesn't support yet anyway.

The cursor is Base64 encoded JSON of {offset: <offset>}.

In addition, we accept ?fields[page_info]=has_next_page,etc to render the relevant pageInfo section. This uses the same code already used to populate pagination links and cursors.