Skip to content

Commit

Permalink
Add documentation for relay mutations.
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikcreemers committed Feb 15, 2016
1 parent c0d64ef commit b358e4c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/pages/docs/relay.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ class Query(graphene.ObjectType):
node = relay.NodeField()
```

## Mutations

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`.

```python
class IntroduceShip(relay.ClientIDMutation):

class Input:
ship_name = graphene.String(required=True)
faction_id = graphene.String(required=True)

ship = graphene.Field(Ship)
faction = graphene.Field(Faction)

@classmethod
def mutate_and_get_payload(cls, input, info):
ship_name = input.get('ship_name')
faction_id = input.get('faction_id')
ship = create_ship(ship_name, faction_id)
faction = get_faction(faction_id)
return IntroduceShip(ship=ship, faction=faction)
```

## Useful links

Expand Down

0 comments on commit b358e4c

Please sign in to comment.