From e6da124783456d48d313523ae2248fb8be4c10e7 Mon Sep 17 00:00:00 2001 From: changeling Date: Wed, 15 May 2019 11:57:16 -0500 Subject: [PATCH] Add query example to queries.rst. Added query example in Relay section. Minor clean-up. --- docs/queries.rst | 64 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/docs/queries.rst b/docs/queries.rst index ab76322..0edd1dd 100644 --- a/docs/queries.rst +++ b/docs/queries.rst @@ -243,6 +243,8 @@ There is one additional import and a single line of code needed to adopt this: Full example ~~~~~~~~~~~~ +See the `Relay documentation `__ on +the core graphene pages for more information on customizing the Relay experience. .. code:: python @@ -268,5 +270,63 @@ Full example def resolve_questions(root, info, **kwargs): return Question.objects.all() -See the `Relay documentation `__ on -the core graphene pages for more information on customing the Relay experience. \ No newline at end of file + +You can now execute queries like: + + +.. code:: python + + { + questions (first: 2, after: "YXJyYXljb25uZWN0aW9uOjEwNQ==") { + pageInfo { + startCursor + endCursor + hasNextPage + hasPreviousPage + } + edges { + cursor + node { + id + question_text + } + } + } + } + +Which returns: + +.. code:: python + + { + "data": { + "questions": { + "pageInfo": { + "startCursor": "YXJyYXljb25uZWN0aW9uOjEwNg==", + "endCursor": "YXJyYXljb25uZWN0aW9uOjEwNw==", + "hasNextPage": true, + "hasPreviousPage": false + }, + "edges": [ + { + "cursor": "YXJyYXljb25uZWN0aW9uOjEwNg==", + "node": { + "id": "UGxhY2VUeXBlOjEwNw==", + "question_text": "How did we get here?" + } + }, + { + "cursor": "YXJyYXljb25uZWN0aW9uOjEwNw==", + "node": { + "id": "UGxhY2VUeXBlOjEwOA==", + "name": "Where are we?" + } + } + ] + } + } + } + +Note that relay implements :code:`pagination` capabilities automatically, adding a :code:`pageInfo` element, and including :code:`cursor` on nodes. These elements are included in the above example for illustration. + +To learn more about Pagination in general, take a look at `Pagination `__ on the GraphQL community site.