@@ -37,12 +37,12 @@ An example in Graphene
3737
3838Let’s build a basic GraphQL schema to say "hello" and "goodbye" in Graphene.
3939
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 **...
4141
4242.. code ::
4343
4444 {
45- hello(name : "friend")
45+ hello(firstName : "friend")
4646 }
4747
4848 ...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:
7979 from graphene import ObjectType, String, Schema
8080
8181 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" ))
8485 goodbye = String()
8586
8687 # 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 } ! '
9091
9192 def resolve_goodbye (root , info ):
9293 return ' See ya!'
@@ -110,7 +111,7 @@ In the `GraphQL Schema Definition Language`_, we could describe the fields defin
110111.. code ::
111112
112113 type Query {
113- hello(name : String = "stranger"): String
114+ hello(firstName : String = "stranger"): String
114115 goodbye: String
115116 }
116117
@@ -130,7 +131,7 @@ Then we can start querying our **Schema** by passing a GraphQL query string to `
130131 # "Hello stranger!"
131132
132133 # or passing the argument in the query
133- query_with_argument = ' { hello(name : "GraphQL") }'
134+ query_with_argument = ' { hello(firstName : "GraphQL") }'
134135 result = schema.execute(query_with_argument)
135136 print (result.data[' hello' ])
136137 # "Hello GraphQL!"
0 commit comments