Skip to content

Commit 0b4a305

Browse files
committed
Merge pull request #119 from bigblind/relay-mutations-docs
Add documentation for relay mutations.
2 parents c0d64ef + b358e4c commit 0b4a305

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/pages/docs/relay.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,28 @@ class Query(graphene.ObjectType):
5454
node = relay.NodeField()
5555
```
5656

57+
## Mutations
58+
59+
Most APIs don't just allow you to read data, they also allow you to write. In GraphQL, this is done using mutations. Just like queries, Relay puts some additional requirements on mutations, but Graphene nicely manages that for you. All you need to do is make your mutation a subclass of `relay.ClientIDMutation`.
60+
61+
```python
62+
class IntroduceShip(relay.ClientIDMutation):
63+
64+
class Input:
65+
ship_name = graphene.String(required=True)
66+
faction_id = graphene.String(required=True)
67+
68+
ship = graphene.Field(Ship)
69+
faction = graphene.Field(Faction)
70+
71+
@classmethod
72+
def mutate_and_get_payload(cls, input, info):
73+
ship_name = input.get('ship_name')
74+
faction_id = input.get('faction_id')
75+
ship = create_ship(ship_name, faction_id)
76+
faction = get_faction(faction_id)
77+
return IntroduceShip(ship=ship, faction=faction)
78+
```
5779

5880
## Useful links
5981

0 commit comments

Comments
 (0)