Skip to content

Commit 708278e

Browse files
authored
docs: mutation 'Output' example (closes #543)
1 parent 9efdf4c commit 708278e

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

docs/types/mutations.rst

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ We should receive:
7676
{
7777
"createPerson": {
7878
"person" : {
79-
name: "Peter"
79+
"name": "Peter"
8080
},
8181
"ok": true
8282
}
@@ -116,7 +116,7 @@ Note that **name** and **age** are part of **person_data** now
116116

117117
Using the above mutation your new query would look like this:
118118

119-
.. code:: json
119+
.. code::
120120
121121
mutation myFirstMutation {
122122
createPerson(personData: {name:"Peter", age: 24}) {
@@ -143,3 +143,41 @@ as complex of input data as you need
143143
name = graphene.String()
144144
latlng = graphene.InputField(LatLngInput)
145145
146+
Output type example
147+
-------------------
148+
To return an existing ObjectType instead of a mutation-specific type, set the **Output** attribute to the desired ObjectType:
149+
150+
.. code:: python
151+
152+
import graphene
153+
154+
class CreatePerson(graphene.Mutation):
155+
class Arguments:
156+
name = graphene.String()
157+
158+
Output = Person
159+
160+
def mutate(self, info, name):
161+
return Person(name=name)
162+
163+
Then, if we query (``schema.execute(query_str)``) the following:
164+
165+
.. code::
166+
167+
mutation myFirstMutation {
168+
createPerson(name:"Peter") {
169+
name
170+
__typename
171+
}
172+
}
173+
174+
We should receive:
175+
176+
.. code:: json
177+
178+
{
179+
"createPerson": {
180+
"name": "Peter",
181+
"__typename": "Person"
182+
}
183+
}

0 commit comments

Comments
 (0)