mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 11:33:55 +03:00
Merge pull request #845 from nive/master
quickstart example improvement
This commit is contained in:
commit
08c86f3def
|
@ -30,17 +30,18 @@ server with an associated set of resolve methods that know how to fetch
|
||||||
data.
|
data.
|
||||||
|
|
||||||
We are going to create a very simple schema, with a ``Query`` with only
|
We are going to create a very simple schema, with a ``Query`` with only
|
||||||
one field: ``hello`` and an input name. And when we query it, it should return ``"Hello {name}"``.
|
one field: ``hello`` and an input name. And when we query it, it should return ``"Hello
|
||||||
|
{argument}"``.
|
||||||
|
|
||||||
.. code:: python
|
.. code:: python
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
|
|
||||||
class Query(graphene.ObjectType):
|
class Query(graphene.ObjectType):
|
||||||
hello = graphene.String(name=graphene.String(default_value="stranger"))
|
hello = graphene.String(argument=graphene.String(default_value="stranger"))
|
||||||
|
|
||||||
def resolve_hello(self, info, name):
|
def resolve_hello(self, info, argument):
|
||||||
return 'Hello ' + name
|
return 'Hello ' + argument
|
||||||
|
|
||||||
schema = graphene.Schema(query=Query)
|
schema = graphene.Schema(query=Query)
|
||||||
|
|
||||||
|
@ -54,4 +55,8 @@ Then we can start querying our schema:
|
||||||
result = schema.execute('{ hello }')
|
result = schema.execute('{ hello }')
|
||||||
print(result.data['hello']) # "Hello stranger"
|
print(result.data['hello']) # "Hello stranger"
|
||||||
|
|
||||||
|
# or passing the argument in the query
|
||||||
|
result = schema.execute('{ hello (argument: "graph") }')
|
||||||
|
print(result.data['hello']) # "Hello graph"
|
||||||
|
|
||||||
Congrats! You got your first graphene schema working!
|
Congrats! You got your first graphene schema working!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user