Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cursor-based pagination #373

Merged
merged 1 commit into from
Aug 8, 2021
Merged

Conversation

richmolj
Copy link
Contributor

@richmolj richmolj commented Aug 8, 2021

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.

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

```graphql
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.
@@ -733,6 +733,12 @@ def message
end
end

class UnsupportedBeforeCursor < Base
def message
"Passing in page[before] and page[number] is not supported. Please create an issue if you need it!"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@richmolj richmolj merged commit 5e7633a into graphiti-api:master Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants