File tree Expand file tree Collapse file tree 1 file changed +40
-2
lines changed Expand file tree Collapse file tree 1 file changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ We should receive:
76
76
{
77
77
"createPerson" : {
78
78
"person" : {
79
- name: "Peter"
79
+ " name" : " Peter"
80
80
},
81
81
"ok" : true
82
82
}
@@ -116,7 +116,7 @@ Note that **name** and **age** are part of **person_data** now
116
116
117
117
Using the above mutation your new query would look like this:
118
118
119
- .. code :: json
119
+ .. code ::
120
120
121
121
mutation myFirstMutation {
122
122
createPerson(personData: {name:"Peter", age: 24}) {
@@ -143,3 +143,41 @@ as complex of input data as you need
143
143
name = graphene.String()
144
144
latlng = graphene.InputField(LatLngInput)
145
145
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
+ }
You can’t perform that action at this time.
0 commit comments