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

add pagination guide #1345

Merged
merged 98 commits into from
Jan 13, 2023
Merged
Changes from 11 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
c76e86c
add schema to resolver info
aryaniyaps Oct 6, 2021
e258480
return strawberry schema instance
aryaniyaps Oct 7, 2021
9ff7be1
add tests for new info attribute
aryaniyaps Oct 7, 2021
1ecf168
update relevant docs
aryaniyaps Oct 7, 2021
d043928
Apply suggestions from code review
aryaniyaps Oct 10, 2021
9e87914
add documentation guide skeleton
aryaniyaps Oct 13, 2021
61020f4
Merge branch 'strawberry-graphql:main' into main
aryaniyaps Oct 13, 2021
fa560cc
update docs for cursor-based pagination
aryaniyaps Oct 13, 2021
0a6925c
Merge branch 'main' of https://github.com/codebyaryan/strawberry into…
aryaniyaps Oct 13, 2021
d423807
delete wrong RELEASE.md file
aryaniyaps Oct 13, 2021
d9d1130
update docs for cursor-based pagination
aryaniyaps Oct 13, 2021
5bd487a
replace json comments
aryaniyaps Oct 13, 2021
2bb2738
document offset-based pagination
aryaniyaps Oct 13, 2021
4c2e18d
mix up example names
aryaniyaps Oct 13, 2021
7322039
improve docs structure
aryaniyaps Oct 13, 2021
3847b0c
document how to implement offset based pagination
aryaniyaps Oct 13, 2021
ac5c046
remove empty codeblocks
aryaniyaps Oct 13, 2021
27923f1
make examples more readable
aryaniyaps Oct 13, 2021
5279b33
document schema types
aryaniyaps Oct 13, 2021
15b6b12
update syntax highlighting
aryaniyaps Oct 13, 2021
fc77db8
make code more readable
aryaniyaps Oct 13, 2021
f2da084
fix mistake in total pages calculation
aryaniyaps Oct 13, 2021
594c210
document argument limiting
aryaniyaps Oct 13, 2021
8bf6d1b
fix example indentation
aryaniyaps Oct 13, 2021
400c9a4
improve header names
aryaniyaps Oct 13, 2021
ef53a97
add skeleton in django integration
aryaniyaps Oct 13, 2021
bddbebb
document pagination with django
aryaniyaps Oct 14, 2021
be69ca7
document negative limit checking
aryaniyaps Oct 14, 2021
5544d6b
Merge branch 'strawberry-graphql:main' into main
aryaniyaps Oct 14, 2021
b26ad49
improve grammar
aryaniyaps Oct 14, 2021
7a84dba
insert IDs into the dataset
aryaniyaps Oct 14, 2021
98500d2
fix example queries
aryaniyaps Oct 14, 2021
867be34
update docs
aryaniyaps Oct 14, 2021
a64a69c
add cursor-pagination skeleton
aryaniyaps Oct 14, 2021
ac6bb5f
update examples
aryaniyaps Oct 14, 2021
b3df8e0
update cursor pagination docs
aryaniyaps Oct 14, 2021
ad4be32
fix typo
aryaniyaps Oct 14, 2021
51ab38a
update example cursor-based query
aryaniyaps Oct 14, 2021
9b0f3a2
Merge branch 'strawberry-graphql:main' into main
aryaniyaps Oct 20, 2021
4241630
Merge branch 'strawberry-graphql:main' into main
aryaniyaps Jan 3, 2022
dd22078
update cursor pagination example
aryaniyaps Jan 3, 2022
0dfc9e7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 3, 2022
c04902e
update cursor pagination example
aryaniyaps Jan 3, 2022
0a478e8
Merge branch 'main' of https://github.com/aryaniyaps/strawberry
aryaniyaps Jan 3, 2022
f1d56fb
add relay-based docs
aryaniyaps Jan 13, 2022
562deb0
Merge branch 'main' into main
aryaniyaps Jan 13, 2022
272ecd0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 13, 2022
2ef5d78
update head
aryaniyaps Jan 13, 2022
53383e3
Merge branch 'main' of https://github.com/aryaniyaps/strawberry
aryaniyaps Jan 13, 2022
78bc2b4
split up guide
aryaniyaps Jan 15, 2022
7096ca6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 15, 2022
bfe8d02
update note blocks
aryaniyaps Jan 19, 2022
725cb66
update index
aryaniyaps Jan 19, 2022
83529c5
update index
aryaniyaps Jan 19, 2022
711dbcd
format tip block
aryaniyaps Jan 19, 2022
c1dd020
split up docs
aryaniyaps Jan 19, 2022
2b9d798
update overview
aryaniyaps Jan 19, 2022
17628a7
update connection docs
aryaniyaps Jan 19, 2022
a95fa9f
format links
aryaniyaps Jan 19, 2022
01a62f0
highlight code blocks
aryaniyaps Jan 19, 2022
1d48881
Fix language
patrick91 Jan 19, 2022
74e81b5
update highlighting
aryaniyaps Jan 20, 2022
b137435
Merge branch 'main' of https://github.com/codebyaryan/strawberry into…
aryaniyaps Jan 20, 2022
801f593
update cursor pagination guide
aryaniyaps Jan 20, 2022
fa7aef2
update highlighting
aryaniyaps Jan 20, 2022
a155b49
update page: connections
aryaniyaps Jan 20, 2022
b48ac83
update codeblocks
aryaniyaps Jan 21, 2022
c461975
update codeblocks
aryaniyaps Jan 21, 2022
2f5d51d
Update django.md
aryaniyaps Jan 21, 2022
3dca82e
update django pagination docs
aryaniyaps Jan 22, 2022
e43c7f4
update tip block
aryaniyaps Jan 22, 2022
bb20b13
resolve conflict
aryaniyaps Jan 22, 2022
0569160
format tip and note blocks
aryaniyaps Jan 24, 2022
c8eb6fe
Apply suggestions from code review
aryaniyaps Jan 24, 2022
71815cf
fix suggestions
aryaniyaps Jan 24, 2022
3f39532
update implementation intro
aryaniyaps Jan 24, 2022
ef04cee
resolve conflict
aryaniyaps Jan 24, 2022
446f24d
add note about conceptual example
aryaniyaps Jan 24, 2022
db44b49
update highlighting
aryaniyaps Jan 24, 2022
527e3c2
update dataset
aryaniyaps Jan 24, 2022
a0db67e
update highlighting
aryaniyaps Jan 24, 2022
554bf4b
update highlighting
aryaniyaps Jan 24, 2022
2d1c827
Update docs/guides/pagination/connections.md
aryaniyaps Jan 24, 2022
3fe2ef3
Update docs/guides/pagination/connections.md
aryaniyaps Jan 24, 2022
69810f6
update guide
aryaniyaps Feb 4, 2022
2de6d9e
update guide
aryaniyaps Feb 4, 2022
72ad7f1
Merge branch 'main' of https://github.com/codebyaryan/strawberry into…
aryaniyaps Feb 4, 2022
1473d7b
update doc title
aryaniyaps Feb 4, 2022
bcc43ef
Update docs/guides/pagination/cursor-based.md
aryaniyaps Feb 5, 2022
8db2584
Merge branch 'strawberry-graphql:main' into main
aryaniyaps Feb 5, 2022
4abf5be
Update README.md
aryaniyaps Feb 5, 2022
1ac6375
Update cursor-based.md
aryaniyaps Feb 5, 2022
d1bad9d
Update connections.md
aryaniyaps Feb 5, 2022
9776806
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 5, 2022
a6cd6e0
fix code highlight
aryaniyaps Feb 9, 2022
459f432
add keyword: relay
aryaniyaps Feb 9, 2022
328153a
Merge branch 'strawberry-graphql:main' into main
aryaniyaps Feb 9, 2022
80f648c
Merge branch 'main' into aryaniyaps/main
patrick91 Jan 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion docs/guides/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,65 @@ title: Pagination

# Pagination

Documentation coming soon
Whenever we deal with lists in GraphQL, we usually need to limit the number of items returned. Surely, we don't want to send massive lists of
items that take a considerable toll on the server! The goal of this guide is to help you get going fast with pagination!

## Pagination at a glance

We have always dealt with pagination in different situations. Let us take a look at some of the common ways pagination
can be implemented today!

-> **Note** The Relay specification already has an established pattern for pagination, via "connection" types. If you're interested,
-> you can check it out [here](https://relay.dev/graphql/connections.htm)!

### Cursor based pagination

Cursor-based pagination works by returning a pointer to a specific item in the dataset. On subsequent requests, the server returns results
after the given pointer. This method addresses the drawbacks of using offset pagination, but does so by making certain trade offs:

- The cursor must be based on a unique, sequential identifier in the given source.
- There is no concept of the total number of pages or results in the dataset.
- The client can’t jump to a specific page.

Let us understand cursor based pagination better, with an example.
Let us assume that we want to request a list of users from a server.

```json
{
"limit": 10 # server returns 10 users at a time.
"cursor": null # we don't know the cursor initially
}
```

The response from the server would be:

```json
{
"users": [...],
"next_cursor": "11", # the user ID of the extra result.
}
```

Now, we can use the next cursor provided to get the next set of users from the server.

```json
{
"limit": 10
"cursor": "11" # we supply the previously obtained cursor
}
```

This is an example for forward pagination - pagination can be done backwards too!

-> **Note** The cursor used during pagination need not always be a number. It is an
-> opaque value that the client may use to page through the result set.

### Limit-offset pagination

documentation coming soon!

## Implementing pagination in GraphQL

Now that we know a few of the common ways to implement pagination, let us look at how we can implement them in GraphQL.

documentation coming soon!