Skip to content

Commit

Permalink
Improved Mutation docs. Fixed #402
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Feb 21, 2017
1 parent 1a52cf9 commit 8b0cd48
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions docs/types/mutations.rst
Expand Up @@ -10,19 +10,20 @@ This example defines a Mutation:

.. code:: python
import graphene
import graphene

class CreatePerson(graphene.Mutation):
class Input:
name = graphene.String()
class CreatePerson(graphene.Mutation):
class Input:
name = graphene.String()

ok = graphene.Boolean()
person = graphene.Field(lambda: Person)
ok = graphene.Boolean()
person = graphene.Field(lambda: Person)

def mutate(self, args, context, info):
person = Person(name=args.get('name'))
ok = True
return CreatePerson(person=person, ok=ok)
@staticmethod
def mutate(root, args, context, info):
person = Person(name=args.get('name'))
ok = True
return CreatePerson(person=person, ok=ok)

**person** and **ok** are the output fields of the Mutation when is
resolved.
Expand All @@ -42,11 +43,16 @@ So, we can finish our schema like this:
class Person(graphene.ObjectType):
name = graphene.String()
age = graphene.Int()
class MyMutations(graphene.ObjectType):
create_person = CreatePerson.Field()
schema = graphene.Schema(mutation=MyMutations)
# We must define a query for our schema
class Query(graphene.ObjectType):
person = graphene.Field(Person)
schema = graphene.Schema(query=Query, mutation=MyMutations)
Executing the Mutation
----------------------
Expand Down Expand Up @@ -96,11 +102,12 @@ To use an InputField you define an InputObjectType that specifies the structure
class CreatePerson(graphene.Mutation):
class Input:
person_data = graphene.InputField(PersonInput)
person_data = graphene.Argument(PersonInput)
person = graphene.Field(lambda: Person)
def mutate(self, args, context, info):
@staticmethod
def mutate(root, args, context, info):
p_data = args.get('person_data')
name = p_data.get('name')
Expand Down

0 comments on commit 8b0cd48

Please sign in to comment.