Skip to content

Commit 8b0cd48

Browse files
committed
Improved Mutation docs. Fixed #402
1 parent 1a52cf9 commit 8b0cd48

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

docs/types/mutations.rst

+20-13
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ This example defines a Mutation:
1010

1111
.. code:: python
1212
13-
import graphene
13+
import graphene
1414

15-
class CreatePerson(graphene.Mutation):
16-
class Input:
17-
name = graphene.String()
15+
class CreatePerson(graphene.Mutation):
16+
class Input:
17+
name = graphene.String()
1818

19-
ok = graphene.Boolean()
20-
person = graphene.Field(lambda: Person)
19+
ok = graphene.Boolean()
20+
person = graphene.Field(lambda: Person)
2121

22-
def mutate(self, args, context, info):
23-
person = Person(name=args.get('name'))
24-
ok = True
25-
return CreatePerson(person=person, ok=ok)
22+
@staticmethod
23+
def mutate(root, args, context, info):
24+
person = Person(name=args.get('name'))
25+
ok = True
26+
return CreatePerson(person=person, ok=ok)
2627

2728
**person** and **ok** are the output fields of the Mutation when is
2829
resolved.
@@ -42,11 +43,16 @@ So, we can finish our schema like this:
4243
4344
class Person(graphene.ObjectType):
4445
name = graphene.String()
46+
age = graphene.Int()
4547
4648
class MyMutations(graphene.ObjectType):
4749
create_person = CreatePerson.Field()
4850
49-
schema = graphene.Schema(mutation=MyMutations)
51+
# We must define a query for our schema
52+
class Query(graphene.ObjectType):
53+
person = graphene.Field(Person)
54+
55+
schema = graphene.Schema(query=Query, mutation=MyMutations)
5056
5157
Executing the Mutation
5258
----------------------
@@ -96,11 +102,12 @@ To use an InputField you define an InputObjectType that specifies the structure
96102
97103
class CreatePerson(graphene.Mutation):
98104
class Input:
99-
person_data = graphene.InputField(PersonInput)
105+
person_data = graphene.Argument(PersonInput)
100106
101107
person = graphene.Field(lambda: Person)
102108
103-
def mutate(self, args, context, info):
109+
@staticmethod
110+
def mutate(root, args, context, info):
104111
p_data = args.get('person_data')
105112
106113
name = p_data.get('name')

0 commit comments

Comments
 (0)