mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-06-16 19:43:13 +03:00
Corrected docs/queries.rst. (#633)
* Corrected typos in docs/queries.rst. * Add basic resolvers to Relay Full example in docs/queries.rst. Added basic resolvers to Full example in Relay section. * Remove question and question resolver. * Add query example to queries.rst. Added query example in Relay section. Minor clean-up.
This commit is contained in:
parent
96908beaf7
commit
04fe299a6e
|
@ -30,7 +30,7 @@ Full example
|
||||||
|
|
||||||
class Query:
|
class Query:
|
||||||
questions = graphene.List(QuestionType)
|
questions = graphene.List(QuestionType)
|
||||||
question = graphene.Field(Question, question_id=graphene.String())
|
question = graphene.Field(QuestionType, question_id=graphene.String())
|
||||||
|
|
||||||
def resolve_questions(self, info, **kwargs):
|
def resolve_questions(self, info, **kwargs):
|
||||||
# Querying a list
|
# Querying a list
|
||||||
|
@ -243,6 +243,8 @@ There is one additional import and a single line of code needed to adopt this:
|
||||||
|
|
||||||
Full example
|
Full example
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
See the `Relay documentation <https://docs.graphene-python.org/en/latest/relay/nodes/>`__ on
|
||||||
|
the core graphene pages for more information on customizing the Relay experience.
|
||||||
|
|
||||||
.. code:: python
|
.. code:: python
|
||||||
|
|
||||||
|
@ -254,7 +256,7 @@ Full example
|
||||||
class QuestionType(DjangoObjectType):
|
class QuestionType(DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Question
|
model = Question
|
||||||
interaces = (relay.Node,)
|
interfaces = (relay.Node,)
|
||||||
|
|
||||||
|
|
||||||
class QuestionConnection(relay.Connection):
|
class QuestionConnection(relay.Connection):
|
||||||
|
@ -263,8 +265,68 @@ Full example
|
||||||
|
|
||||||
|
|
||||||
class Query:
|
class Query:
|
||||||
question = graphene.Field(QuestionType)
|
|
||||||
questions = relay.ConnectionField(QuestionConnection)
|
questions = relay.ConnectionField(QuestionConnection)
|
||||||
|
|
||||||
See the `Relay documentation <https://docs.graphene-python.org/en/latest/relay/nodes/>`__ on
|
def resolve_questions(root, info, **kwargs):
|
||||||
the core graphene pages for more information on customing the Relay experience.
|
return Question.objects.all()
|
||||||
|
|
||||||
|
|
||||||
|
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 <https://graphql.org/learn/pagination/>`__ on the GraphQL community site.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user