-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmutations.js
45 lines (41 loc) · 954 Bytes
/
mutations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// @flow
import { curry } from 'ramda';
import { cursorForObjectInConnection } from './connection';
export const addEdgeToMutationResult = (response: any) => {
// TODO: cursors?
return {
edge: {
node: response,
},
};
};
export const addEdgeAndCursorToMutationResult = curry(
(connectionGetter: () => Promise<*>, obj: Object) => {
return connectionGetter().then(connection => {
return {
edge: {
node: obj,
cursor: cursorForObjectInConnection(connection, obj),
},
};
});
},
);
export const optimisticResponse = curry(
(
operationName: string,
payloadName: string,
response: Object => Object,
variables: Object,
) => {
const result =
typeof response === 'function' ? response(variables) : response;
return {
__typename: 'Mutation',
[operationName]: {
__typename: payloadName,
...result,
},
};
},
);