mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-14 05:36:45 +03:00
Merge pull request #119 from bigblind/relay-mutations-docs
Add documentation for relay mutations.
This commit is contained in:
commit
0b4a3051a0
|
@ -54,6 +54,28 @@ class Query(graphene.ObjectType):
|
||||||
node = relay.NodeField()
|
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
|
## Useful links
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user