You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library wraps the `graphql` function from [react-apollo](https://github.com/apollographql/react-apollo) function by also dispatching redux actions when a mutation is called.
4
+
5
+
If you were using
6
+
```
7
+
import { graphql } from 'react-apollo';
8
+
```
9
+
you may now do
10
+
```
11
+
import { graphql } from 'react-apollo-redux';
12
+
```
13
+
14
+
### Usage
15
+
16
+
When a mutation is called, an action bearing the same name (snake and upper cased) and prefixed with `@@MUTATION` is dispatched. For example, a mutation like this
17
+
```
18
+
const FollowItems = gql`
19
+
mutation followItems($itemIds: [ID]!) {
20
+
followItems(item_ids: $itemIds) {
21
+
id,
22
+
},
23
+
}
24
+
`;
25
+
26
+
27
+
graphql(FollowItems, {
28
+
name: 'followItems',
29
+
}),
30
+
```
31
+
Will dispatch the following actions with respective types:
32
+
33
+
#### type @@MUTATION/FOLLOW_ITEMS
34
+
`@@MUTATION/[name]` contains the arguments to the mutation in its payload. For example, if the mutation was called this way
35
+
```
36
+
followItems({
37
+
variables: {
38
+
itemIds: itemIds,
39
+
},
40
+
extra: {
41
+
user,
42
+
references,
43
+
},
44
+
});
45
+
```
46
+
The payload will contain that object.
47
+
48
+
#### type @@MUTATION/FOLLOW_ITEMS_SUCCESS
49
+
`@@MUTATION/[name]_SUCCESS` is dispatched once the mutation result is successfully returned from the server. The action payload contains two things:
50
+
- The `result` from the server (as specified in the mutation)
51
+
- The arguments (`args`) passed to the mutation, like above
52
+
53
+
54
+
#### type @@MUTATION/FOLLOW_ITEMS_FAIL
55
+
`@@MUTATION/[name]_FAIL` is dispatched if the server returns an error. This action contains the same payload as the initial action `@@MUTATION/FOLLOW_ITEMS`, and has an additional `meta` property with the error returned from the server.
0 commit comments