/
todo.js
66 lines (63 loc) · 2.06 KB
/
todo.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// @flow
import { requestSubscription, graphql } from 'react-relay';
import { ConnectionHandler } from 'relay-runtime';
const subscription = graphql`
# relay-compiler: FindGraphQLTags: Operation names in graphql tags must be
# prefixed with the module name and end in "Mutation", "Query", or "Subscription".
# Got 'TodoxxxxxxSubscription' in module 'TodoSubscription' (file name).
subscription todoSubscription($input: TodoSubScriptionInput!) {
todoSubScription(input: $input) {
clientSubscriptionId
arg
todo {
id
text
completed
}
}
}
`;
const subscribeTodo = (environment, arg) => {
/**
* relay-muckaround/packages/relay-runtime/store/RelayModernEnvironment.js #sendSubscription
*RelayModernEnvironment#sendSubscription({
onCompleted,
onNext,
onError,
operation,
updater,
}: {
onCompleted?: ?(errors: ?Array<PayloadError>) => void,
onNext?: ?(payload: RelayResponsePayload) => void,
onError?: ?(error: Error) => void,
operation: OperationSelector,
updater?: ?SelectorStoreUpdater,
}): Disposable
*/
requestSubscription(environment, {
subscription,
variables: arg,
// after socket has been closed successfully
onCompleted: () => {
alert('done!'); /* need this if payload doesn't contain an id field*/
},
// connection_err ..etc
onError: error => console.error(error),
//end of pipe line; after store merged
onNext: response => {},
// begin of pipe line; before store merged
updater: (
store /*RelayRecordSourceSelectorProxy*/,
data /*selector data, raw json*/
) => {
//@see: relay-muckaround/packages/relay-runtime/store/RelayPublishQueue.js
/**
'RelayRecordSourceSelectorProxy.getResponse: This call is deprecated. ' +
'If you need need to access data from a mutation response, you ' +
'should use the mutation fragment data passed in as a second ' +
'argument to the mutation updater.'
*/
},
});
};
export default { subscribeTodo };