This repository has been archived by the owner on May 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
/
Client.re
64 lines (56 loc) · 1.49 KB
/
Client.re
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
/* open ApolloLinks; */
open ApolloInMemoryCache;
/* Create an InMemoryCache */
let inMemoryCache = createInMemoryCache();
/*
OR with dataIdFromObject:
type dataObject = {
.
"__typename": string,
"id": string
};
createInMemoryCache(~dataIdFromObject=(obj: dataObject) => obj##id, ());
*/
/* Create a Link that puts an Authorization header in context */
let headerContextLink =
ApolloLinks.createContextLink(() =>
{
"headers": {
"authorization": "Bearer $123",
},
}
);
/* Create an HTTP Link */
let httpLink =
ApolloLinks.createHttpLink(
~uri="https://api.graph.cool/simple/v1/cjdgba1jw4ggk0185ig4bhpsn",
(),
);
let webSocketLinkT: ReasonApolloTypes.webSocketLinkT = {
uri: "wss://subscriptions.graph.cool/v1/cjdgba1jw4ggk0185ig4bhpsn",
options: {
reconnect: true,
connectionParams: None,
},
};
/* WebSocket client */
let webSocketLink = ApolloLinks.webSocketLink(webSocketLinkT);
/* based on test, execute left or right */
let webSocketHttpLink =
ApolloLinks.split(
operation => {
let operationDefinition =
ApolloUtilities.getMainDefinition(operation.query);
Js.log(operationDefinition);
operationDefinition.kind == "OperationDefinition"
&& operationDefinition.operation == "subscription";
},
webSocketLink,
httpLink,
);
let instance =
ReasonApollo.createApolloClient(
~link=ApolloLinks.from([|headerContextLink, webSocketHttpLink|]),
~cache=inMemoryCache,
(),
);