Skip to content

Commit 97442f9

Browse files
authored
Fix code examples in queries.rst (#1265)
* Fix code examples in queries.rst Code example in Arguments section doesn't work as stated in its comment — if "foo" or "bar" are not declare in the graphql query, it will be an error, not they become None. Code example in Info section has invalid indentation, `resolve_questions()` seems to be a `Query` method, but it's indented as module-level function. * Fix indentation in query examples * Enable syntax highlight for graphql queries
1 parent 60b3032 commit 97442f9

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

docs/queries.rst

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ For example the following ``Model`` and ``DjangoObjectType``:
151151
152152
Results in the following GraphQL schema definition:
153153

154-
.. code::
154+
.. code:: graphql
155155
156156
type Pet {
157157
id: ID!
@@ -178,7 +178,7 @@ You can disable this automatic conversion by setting
178178
fields = ("id", "kind",)
179179
convert_choices_to_enum = False
180180
181-
.. code::
181+
.. code:: graphql
182182
183183
type Pet {
184184
id: ID!
@@ -313,7 +313,7 @@ Additionally, Resolvers will receive **any arguments declared in the field defin
313313
bar=graphene.Int()
314314
)
315315
316-
def resolve_question(root, info, foo, bar):
316+
def resolve_question(root, info, foo=None, bar=None):
317317
# If `foo` or `bar` are declared in the GraphQL query they will be here, else None.
318318
return Question.objects.filter(foo=foo, bar=bar).first()
319319
@@ -336,12 +336,12 @@ of Django's ``HTTPRequest`` in your resolve methods, such as checking for authen
336336
class Query(graphene.ObjectType):
337337
questions = graphene.List(QuestionType)
338338
339-
def resolve_questions(root, info):
340-
# See if a user is authenticated
341-
if info.context.user.is_authenticated():
342-
return Question.objects.all()
343-
else:
344-
return Question.objects.none()
339+
def resolve_questions(root, info):
340+
# See if a user is authenticated
341+
if info.context.user.is_authenticated():
342+
return Question.objects.all()
343+
else:
344+
return Question.objects.none()
345345
346346
347347
DjangoObjectTypes
@@ -418,29 +418,29 @@ the core graphene pages for more information on customizing the Relay experience
418418
You can now execute queries like:
419419

420420

421-
.. code:: python
421+
.. code:: graphql
422422
423423
{
424424
questions (first: 2, after: "YXJyYXljb25uZWN0aW9uOjEwNQ==") {
425425
pageInfo {
426-
startCursor
427-
endCursor
428-
hasNextPage
429-
hasPreviousPage
426+
startCursor
427+
endCursor
428+
hasNextPage
429+
hasPreviousPage
430430
}
431431
edges {
432-
cursor
433-
node {
434-
id
435-
question_text
436-
}
432+
cursor
433+
node {
434+
id
435+
question_text
436+
}
437437
}
438438
}
439439
}
440440
441441
Which returns:
442442

443-
.. code:: python
443+
.. code:: json
444444
445445
{
446446
"data": {

0 commit comments

Comments
 (0)