mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-16 19:40:39 +03:00
Updated Relay Pagination example (markdown)
parent
6eeafa9cd0
commit
28ab85d0eb
|
@ -4,7 +4,7 @@ For this example, we're going to assume a basic understanding of what `startCurs
|
|||
|
||||
In a nutshell, `pagination` is implemented via graphene relay's `Connection` and `ConnectionField` pairing. With these in place, you'll see `pageInfo` available within your queries. It looks something like this:
|
||||
|
||||
```
|
||||
```json
|
||||
"pageInfo": {
|
||||
"startCursor": "YXJyYXljb25uZWN0aW9uOjQx",
|
||||
"endCursor": "YXJyYXljb25uZWN0aW9uOjQz",
|
||||
|
@ -14,7 +14,7 @@ In a nutshell, `pagination` is implemented via graphene relay's `Connection` and
|
|||
```
|
||||
|
||||
In addition to a `cursor` element within `edges` that will show you the cursor id for each element, like so:
|
||||
```
|
||||
```graphql
|
||||
edges {
|
||||
cursor
|
||||
node {
|
||||
|
@ -25,7 +25,7 @@ In addition to a `cursor` element within `edges` that will show you the cursor i
|
|||
|
||||
The basic implementation below provides the elements for cursor-based pagination that you'll need to do your thing in your code. Hope this helps.
|
||||
|
||||
```
|
||||
```python
|
||||
from graphene import Connection, ConnectionField, Node, Int
|
||||
from graphene_django import DjangoObjectType
|
||||
from <wherever your models exist> import Place
|
||||
|
@ -52,7 +52,7 @@ class Query(object):
|
|||
return Place.objects.all()
|
||||
```
|
||||
The following query, (the pageInfo element is included for illustration, but isn't necessary for the query to resolve):
|
||||
```
|
||||
```graphql
|
||||
{
|
||||
places(first: 3, after: "YXJyYXljb25uZWN0aW9uOjQx") {
|
||||
pageInfo {
|
||||
|
@ -73,7 +73,7 @@ The following query, (the pageInfo element is included for illustration, but isn
|
|||
```
|
||||
|
||||
Gives us:
|
||||
```
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"places": {
|
||||
|
|
Loading…
Reference in New Issue
Block a user