mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 12:44:15 +03:00
docs: Disambiguate argument name in quickstart docs (#1474)
This commit is contained in:
parent
a2b63d8d84
commit
f891a3683d
|
@ -37,12 +37,12 @@ An example in Graphene
|
||||||
|
|
||||||
Let’s build a basic GraphQL schema to say "hello" and "goodbye" in Graphene.
|
Let’s build a basic GraphQL schema to say "hello" and "goodbye" in Graphene.
|
||||||
|
|
||||||
When we send a **Query** requesting only one **Field**, ``hello``, and specify a value for the ``name`` **Argument**...
|
When we send a **Query** requesting only one **Field**, ``hello``, and specify a value for the ``firstName`` **Argument**...
|
||||||
|
|
||||||
.. code::
|
.. code::
|
||||||
|
|
||||||
{
|
{
|
||||||
hello(name: "friend")
|
hello(firstName: "friend")
|
||||||
}
|
}
|
||||||
|
|
||||||
...we would expect the following Response containing only the data requested (the ``goodbye`` field is not resolved).
|
...we would expect the following Response containing only the data requested (the ``goodbye`` field is not resolved).
|
||||||
|
@ -79,14 +79,15 @@ In Graphene, we can define a simple schema using the following code:
|
||||||
from graphene import ObjectType, String, Schema
|
from graphene import ObjectType, String, Schema
|
||||||
|
|
||||||
class Query(ObjectType):
|
class Query(ObjectType):
|
||||||
# this defines a Field `hello` in our Schema with a single Argument `name`
|
# this defines a Field `hello` in our Schema with a single Argument `first_name`
|
||||||
hello = String(name=String(default_value="stranger"))
|
# By default, the argument name will automatically be camel-based into firstName in the generated schema
|
||||||
|
hello = String(first_name=String(default_value="stranger"))
|
||||||
goodbye = String()
|
goodbye = String()
|
||||||
|
|
||||||
# our Resolver method takes the GraphQL context (root, info) as well as
|
# our Resolver method takes the GraphQL context (root, info) as well as
|
||||||
# Argument (name) for the Field and returns data for the query Response
|
# Argument (first_name) for the Field and returns data for the query Response
|
||||||
def resolve_hello(root, info, name):
|
def resolve_hello(root, info, first_name):
|
||||||
return f'Hello {name}!'
|
return f'Hello {first_name}!'
|
||||||
|
|
||||||
def resolve_goodbye(root, info):
|
def resolve_goodbye(root, info):
|
||||||
return 'See ya!'
|
return 'See ya!'
|
||||||
|
@ -110,7 +111,7 @@ In the `GraphQL Schema Definition Language`_, we could describe the fields defin
|
||||||
.. code::
|
.. code::
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
hello(name: String = "stranger"): String
|
hello(firstName: String = "stranger"): String
|
||||||
goodbye: String
|
goodbye: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +131,7 @@ Then we can start querying our **Schema** by passing a GraphQL query string to `
|
||||||
# "Hello stranger!"
|
# "Hello stranger!"
|
||||||
|
|
||||||
# or passing the argument in the query
|
# or passing the argument in the query
|
||||||
query_with_argument = '{ hello(name: "GraphQL") }'
|
query_with_argument = '{ hello(firstName: "GraphQL") }'
|
||||||
result = schema.execute(query_with_argument)
|
result = schema.execute(query_with_argument)
|
||||||
print(result.data['hello'])
|
print(result.data['hello'])
|
||||||
# "Hello GraphQL!"
|
# "Hello GraphQL!"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user