@@ -37,12 +37,12 @@ An example in Graphene
37
37
38
38
Let’s build a basic GraphQL schema to say "hello" and "goodbye" in Graphene.
39
39
40
- When we send a **Query ** requesting only one **Field **, ``hello ``, and specify a value for the ``name `` **Argument **...
40
+ When we send a **Query ** requesting only one **Field **, ``hello ``, and specify a value for the ``firstName `` **Argument **...
41
41
42
42
.. code ::
43
43
44
44
{
45
- hello(name : "friend")
45
+ hello(firstName : "friend")
46
46
}
47
47
48
48
...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:
79
79
from graphene import ObjectType, String, Schema
80
80
81
81
class Query (ObjectType ):
82
- # this defines a Field `hello` in our Schema with a single Argument `name`
83
- hello = String(name = String(default_value = " stranger" ))
82
+ # this defines a Field `hello` in our Schema with a single Argument `first_name`
83
+ # By default, the argument name will automatically be camel-based into firstName in the generated schema
84
+ hello = String(first_name = String(default_value = " stranger" ))
84
85
goodbye = String()
85
86
86
87
# our Resolver method takes the GraphQL context (root, info) as well as
87
- # Argument (name ) for the Field and returns data for the query Response
88
- def resolve_hello (root , info , name ):
89
- return f ' Hello { name } ! '
88
+ # Argument (first_name ) for the Field and returns data for the query Response
89
+ def resolve_hello (root , info , first_name ):
90
+ return f ' Hello { first_name } ! '
90
91
91
92
def resolve_goodbye (root , info ):
92
93
return ' See ya!'
@@ -110,7 +111,7 @@ In the `GraphQL Schema Definition Language`_, we could describe the fields defin
110
111
.. code ::
111
112
112
113
type Query {
113
- hello(name : String = "stranger"): String
114
+ hello(firstName : String = "stranger"): String
114
115
goodbye: String
115
116
}
116
117
@@ -130,7 +131,7 @@ Then we can start querying our **Schema** by passing a GraphQL query string to `
130
131
# "Hello stranger!"
131
132
132
133
# or passing the argument in the query
133
- query_with_argument = ' { hello(name : "GraphQL") }'
134
+ query_with_argument = ' { hello(firstName : "GraphQL") }'
134
135
result = schema.execute(query_with_argument)
135
136
print (result.data[' hello' ])
136
137
# "Hello GraphQL!"
0 commit comments