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
/
ApolloLinks.re
109 lines (97 loc) · 2.87 KB
/
ApolloLinks.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
open ReasonApolloTypes;
/* Bind the method `from`, used to compose links together */
[@bs.module "apollo-link"]
external from: array(apolloLink) => apolloLink = "from";
/* Bind the method split. Based on a test send left or right */
[@bs.module "apollo-link"]
external split: (splitTest => bool, apolloLink, apolloLink) => apolloLink =
"split";
/* Bind the HttpLink class */
[@bs.module "apollo-link-http"] [@bs.new]
external createHttpLink: ApolloClient.linkOptions => apolloLink = "HttpLink";
/* Bind the setContext method */
[@bs.module "apollo-link-context"]
external apolloLinkSetContext: (unit => Js.t({..})) => apolloLink =
"setContext";
/* Bind the onError method */
[@bs.module "apollo-link-error"]
external apolloLinkOnError: (errorResponse => unit) => apolloLink = "onError";
/* bind apollo-link-ws */
[@bs.module "apollo-link-ws"] [@bs.new]
external webSocketLink: webSocketLinkT => apolloLink = "WebSocketLink";
/* Bind createUploadLink function from apollo upload link */
[@bs.module "apollo-upload-client"]
external createUploadLink: ApolloClient.uploadLinkOptions => apolloLink =
"createUploadLink";
// let webSocketLink = (~uri, ~reconnect=?, ~connectionParams=?, ()) => {
// uri,
// options: {
// reconnect,
// connectionParams,
// },
// };
/**
* CreateHttpLink
* https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-http
*/
let createHttpLink =
(
~uri,
~includeExtensions=?,
~fetch=?,
~headers=?,
~credentials=?,
~fetchOptions=?,
(),
) => {
createHttpLink({
uri,
includeExtensions: Js.Nullable.fromOption(includeExtensions),
fetch: Js.Nullable.fromOption(fetch),
headers: Js.Nullable.fromOption(headers),
credentials: Js.Nullable.fromOption(credentials),
fetchOptions: Js.Nullable.fromOption(fetchOptions),
});
};
/**
* CreateUploadLink
* https://github.com/jaydenseric/apollo-upload-client#function-createuploadlink
*/
let createUploadLink =
(
~uri=?,
~fetch=?,
~fetchOptions=?,
~credentials=?,
~headers=?,
~includeExtensions=?,
(),
) =>
createUploadLink(
Js.Nullable.{
uri: fromOption(uri),
fetch: fromOption(fetch),
fetchOptions: fromOption(fetchOptions),
credentials: fromOption(credentials),
headers: fromOption(headers),
includeExtensions: fromOption(includeExtensions),
},
);
/**
* CreateContextLink
* https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-context
*/
let createContextLink = contextHandler => {
/* Instanciate a new context link object */
apolloLinkSetContext(
contextHandler,
);
};
/**
* CreateErrorLink
* https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-error
*/
let createErrorLink = errorHandler => {
/* Instanciate a new error link object */
apolloLinkOnError(errorHandler);
};