From 708278e6dca72f39e769eec559b2eb01b6915986 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Tue, 26 Jun 2018 07:14:46 -0400 Subject: [PATCH] docs: mutation 'Output' example (closes #543) --- docs/types/mutations.rst | 42 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/docs/types/mutations.rst b/docs/types/mutations.rst index 70c80d0a..6949008f 100644 --- a/docs/types/mutations.rst +++ b/docs/types/mutations.rst @@ -76,7 +76,7 @@ We should receive: { "createPerson": { "person" : { - name: "Peter" + "name": "Peter" }, "ok": true } @@ -116,7 +116,7 @@ Note that **name** and **age** are part of **person_data** now Using the above mutation your new query would look like this: -.. code:: json +.. code:: mutation myFirstMutation { createPerson(personData: {name:"Peter", age: 24}) { @@ -143,3 +143,41 @@ as complex of input data as you need name = graphene.String() latlng = graphene.InputField(LatLngInput) +Output type example +------------------- +To return an existing ObjectType instead of a mutation-specific type, set the **Output** attribute to the desired ObjectType: + +.. code:: python + + import graphene + + class CreatePerson(graphene.Mutation): + class Arguments: + name = graphene.String() + + Output = Person + + def mutate(self, info, name): + return Person(name=name) + +Then, if we query (``schema.execute(query_str)``) the following: + +.. code:: + + mutation myFirstMutation { + createPerson(name:"Peter") { + name + __typename + } + } + +We should receive: + +.. code:: json + + { + "createPerson": { + "name": "Peter", + "__typename": "Person" + } + }