graphene-django icon indicating copy to clipboard operation
graphene-django copied to clipboard

Fix code examples in queries.rst

Open belkka opened this issue 4 years ago • 2 comments

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.

belkka avatar Oct 12 '21 18:10 belkka

And explanation why first of edited code examples doesn't work properly:

import graphene


class Query(graphene.ObjectType):
    question = graphene.Field(
        graphene.String,
        foo=graphene.String(),
        bar=graphene.Int()
    )

    def resolve_question(root, info, foo, bar):
        # If `foo` or `bar` are declared in the GraphQL query they will be here, else None.
        return str(foo) + str(bar)


result = graphene.Schema(query=Query).execute('{question}')
error, = result.errors
assert error.message == "resolve_question() missing 2 required positional arguments: 'foo' and 'bar'"

belkka avatar Oct 12 '21 18:10 belkka

Added two more commits that fix indentation in another block and add syntax highlighting for graphql queries in code blocks

belkka avatar Oct 12 '21 19:10 belkka