rescript-relay 0.0.0-autocodesplit-09ee6f6c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +942 -0
- package/README.md +111 -0
- package/cli/cli.js +472 -0
- package/compiler.js +11 -0
- package/package.json +65 -0
- package/postinstall.js +189 -0
- package/ppx-linux +0 -0
- package/ppx-macos-arm64 +0 -0
- package/ppx-macos-latest +0 -0
- package/ppx-windows-latest +0 -0
- package/relay-compiler-linux-musl/relay +0 -0
- package/relay-compiler-linux-x64/relay +0 -0
- package/relay-compiler-macos-arm64/relay +0 -0
- package/relay-compiler-macos-x64/relay +0 -0
- package/relay-compiler-win-x64/relay.exe +0 -0
- package/rescript.json +19 -0
- package/src/ReactDOMExperimental.bs.js +23 -0
- package/src/ReactDOMExperimental.res +16 -0
- package/src/ReactExperimental.bs.js +23 -0
- package/src/ReactExperimental.res +21 -0
- package/src/ReactExperimental.resi +18 -0
- package/src/RescriptRelay.bs.js +329 -0
- package/src/RescriptRelay.res +858 -0
- package/src/RescriptRelay.resi +897 -0
- package/src/RescriptRelayUtils.bs.js +76 -0
- package/src/RescriptRelayUtils.res +89 -0
- package/src/RescriptRelayUtils.resi +36 -0
- package/src/RescriptRelay_Fragment.bs.js +122 -0
- package/src/RescriptRelay_Fragment.res +243 -0
- package/src/RescriptRelay_Fragment.resi +85 -0
- package/src/RescriptRelay_Internal.bs.js +102 -0
- package/src/RescriptRelay_Internal.res +71 -0
- package/src/RescriptRelay_Internal.resi +20 -0
- package/src/RescriptRelay_Mutation.bs.js +57 -0
- package/src/RescriptRelay_Mutation.res +144 -0
- package/src/RescriptRelay_Mutation.resi +52 -0
- package/src/RescriptRelay_Query.bs.js +101 -0
- package/src/RescriptRelay_Query.res +177 -0
- package/src/RescriptRelay_Query.resi +62 -0
- package/src/RescriptRelay_RelayResolvers.bs.js +13 -0
- package/src/RescriptRelay_RelayResolvers.res +21 -0
- package/src/RescriptRelay_RelayResolvers.resi +10 -0
- package/src/RescriptRelay_Subscriptions.bs.js +24 -0
- package/src/RescriptRelay_Subscriptions.res +50 -0
- package/src/RescriptRelay_Subscriptions.resi +14 -0
- package/src/utils.js +418 -0
- package/src/utils.mjs +418 -0
|
@@ -0,0 +1,858 @@
|
|
|
1
|
+
type arguments
|
|
2
|
+
type allFieldsMasked = {.}
|
|
3
|
+
|
|
4
|
+
type any
|
|
5
|
+
|
|
6
|
+
type queryNode<'node>
|
|
7
|
+
type fragmentNode<'node>
|
|
8
|
+
type mutationNode<'node>
|
|
9
|
+
type subscriptionNode<'node>
|
|
10
|
+
|
|
11
|
+
type fragmentRefs<'fragments>
|
|
12
|
+
type resolverFragmentRefs<'fragments>
|
|
13
|
+
type updatableFragmentRefs<'fragments>
|
|
14
|
+
|
|
15
|
+
type dataId
|
|
16
|
+
type dataIdObject = {id: dataId}
|
|
17
|
+
type recordSourceRecords = Js.Json.t
|
|
18
|
+
type uploadables
|
|
19
|
+
|
|
20
|
+
module SuspenseSentinel = {
|
|
21
|
+
type t
|
|
22
|
+
|
|
23
|
+
@module("relay-runtime") external suspend: t => 'any = "suspenseSentinel"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type liveStateCallback = unit => unit
|
|
27
|
+
type liveStateUnsubscribeCallback = unit => unit
|
|
28
|
+
|
|
29
|
+
type liveState<'value> = {
|
|
30
|
+
read: SuspenseSentinel.t => 'value,
|
|
31
|
+
subscribe: liveStateCallback => liveStateUnsubscribeCallback,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
external dataIdToString: dataId => string = "%identity"
|
|
35
|
+
external makeDataId: string => dataId = "%identity"
|
|
36
|
+
external makeArguments: {..} => arguments = "%identity"
|
|
37
|
+
external makeUploadables: Js.Dict.t<'file> => uploadables = "%identity"
|
|
38
|
+
external unwrapUploadables: uploadables => Js.Dict.t<'file> = "%identity"
|
|
39
|
+
|
|
40
|
+
@module("relay-runtime/experimental")
|
|
41
|
+
external resolverDataInjector: ('a, 'b, 'c, 'd) => 'return = "resolverDataInjector"
|
|
42
|
+
|
|
43
|
+
@module("relay-runtime")
|
|
44
|
+
external generateClientID: (~dataId: dataId, ~storageKey: string, ~index: int=?) => dataId =
|
|
45
|
+
"generateClientID"
|
|
46
|
+
|
|
47
|
+
@module("relay-runtime")
|
|
48
|
+
external generateUniqueClientID: unit => dataId = "generateUniqueClientID"
|
|
49
|
+
|
|
50
|
+
@module("relay-runtime")
|
|
51
|
+
external isClientID: dataId => bool = "isClientID"
|
|
52
|
+
|
|
53
|
+
type featureFlags = {
|
|
54
|
+
@as("DELAY_CLEANUP_OF_PENDING_PRELOAD_QUERIES")
|
|
55
|
+
mutable delayCleanupOfPendingPreloadQueries: bool,
|
|
56
|
+
@as("ENABLE_CLIENT_EDGES")
|
|
57
|
+
mutable enableClientEdges: bool,
|
|
58
|
+
@as("ENABLE_VARIABLE_CONNECTION_KEY")
|
|
59
|
+
mutable enableVariableConnectionKey: bool,
|
|
60
|
+
@as("ENABLE_PARTIAL_RENDERING_DEFAULT")
|
|
61
|
+
mutable enablePartialRenderingDefault: bool,
|
|
62
|
+
@as("ENABLE_REACT_FLIGHT_COMPONENT_FIELD")
|
|
63
|
+
mutable enableReactFlightComponentField: bool,
|
|
64
|
+
@as("ENABLE_RELAY_RESOLVERS")
|
|
65
|
+
mutable enableRelayResolvers: bool,
|
|
66
|
+
@as("ENABLE_GETFRAGMENTIDENTIFIER_OPTIMIZATION")
|
|
67
|
+
mutable enableGetFragmentIdentifierOptimization: bool,
|
|
68
|
+
@as("ENABLE_FRIENDLY_QUERY_NAME_GQL_URL")
|
|
69
|
+
mutable enableFriendlyQueryNameGqlUrl: bool,
|
|
70
|
+
@as("ENABLE_LOAD_QUERY_REQUEST_DEDUPING")
|
|
71
|
+
mutable enableLoadQueryRequestDeduping: bool,
|
|
72
|
+
@as("ENABLE_DO_NOT_WRAP_LIVE_QUERY")
|
|
73
|
+
mutable enableDoNotWrapLiveQuery: bool,
|
|
74
|
+
@as("ENABLE_NOTIFY_SUBSCRIPTION")
|
|
75
|
+
mutable enableNotifySubscription: bool,
|
|
76
|
+
@as("ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT")
|
|
77
|
+
mutable enableContainersSubscribeOnCommit: bool,
|
|
78
|
+
@as("ENABLE_QUERY_RENDERER_OFFSCREEN_SUPPORT")
|
|
79
|
+
mutable enableQueryRendererOffscreenSupport: bool,
|
|
80
|
+
@as("MAX_DATA_ID_LENGTH")
|
|
81
|
+
mutable maxDataIdLength: option<int>,
|
|
82
|
+
@as("REFACTOR_SUSPENSE_RESOURCE")
|
|
83
|
+
mutable refactorSuspenseResource: bool,
|
|
84
|
+
@as("STRING_INTERN_LEVEL")
|
|
85
|
+
mutable stringInternLevel: int,
|
|
86
|
+
@as("USE_REACT_CACHE")
|
|
87
|
+
mutable useReactCache: bool,
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@module("relay-runtime")
|
|
91
|
+
external relayFeatureFlags: featureFlags = "RelayFeatureFlags"
|
|
92
|
+
|
|
93
|
+
@module("./utils")
|
|
94
|
+
external convertObj: ('a, Js.Dict.t<Js.Dict.t<Js.Dict.t<string>>>, 'b, 'c) => 'd = "traverser"
|
|
95
|
+
|
|
96
|
+
let optArrayOfNullableToOptArrayOfOpt: option<array<Js.Nullable.t<'a>>> => option<
|
|
97
|
+
array<option<'a>>,
|
|
98
|
+
> = x =>
|
|
99
|
+
switch x {
|
|
100
|
+
| None => None
|
|
101
|
+
| Some(arr) => Some(arr->Belt.Array.map(Js.Nullable.toOption))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@module("relay-runtime") external storeRootId: dataId = "ROOT_ID"
|
|
105
|
+
@module("relay-runtime") external storeRootType: string = "ROOT_TYPE"
|
|
106
|
+
|
|
107
|
+
module RecordProxy = {
|
|
108
|
+
type t
|
|
109
|
+
|
|
110
|
+
@send
|
|
111
|
+
external copyFieldsFrom: (t, ~sourceRecord: t) => unit = "copyFieldsFrom"
|
|
112
|
+
|
|
113
|
+
@send external getDataId: t => dataId = "getDataID"
|
|
114
|
+
|
|
115
|
+
@send @return(nullable)
|
|
116
|
+
external getLinkedRecord: (t, ~name: string, ~arguments: arguments=?) => option<t> =
|
|
117
|
+
"getLinkedRecord"
|
|
118
|
+
|
|
119
|
+
@send @return(nullable)
|
|
120
|
+
external getLinkedRecords: (t, string, option<arguments>) => option<array<Js.Nullable.t<t>>> =
|
|
121
|
+
"getLinkedRecords"
|
|
122
|
+
|
|
123
|
+
let getLinkedRecords = (t, ~name, ~arguments=?): option<array<option<t>>> =>
|
|
124
|
+
getLinkedRecords(t, name, arguments)->optArrayOfNullableToOptArrayOfOpt
|
|
125
|
+
|
|
126
|
+
@send
|
|
127
|
+
external getOrCreateLinkedRecord: (
|
|
128
|
+
t,
|
|
129
|
+
~name: string,
|
|
130
|
+
~typeName: string,
|
|
131
|
+
~arguments: arguments=?,
|
|
132
|
+
) => t = "getOrCreateLinkedRecord"
|
|
133
|
+
|
|
134
|
+
@send external getType: t => string = "getType"
|
|
135
|
+
|
|
136
|
+
@send @return(nullable)
|
|
137
|
+
external getValueString: (t, ~name: string, ~arguments: arguments=?) => option<string> =
|
|
138
|
+
"getValue"
|
|
139
|
+
|
|
140
|
+
@send @return(nullable)
|
|
141
|
+
external getValueStringArray: (
|
|
142
|
+
t,
|
|
143
|
+
~name: string,
|
|
144
|
+
~arguments: arguments=?,
|
|
145
|
+
) => option<array<option<string>>> = "getValue"
|
|
146
|
+
|
|
147
|
+
@send @return(nullable)
|
|
148
|
+
external getValueInt: (t, ~name: string, ~arguments: arguments=?) => option<int> = "getValue"
|
|
149
|
+
|
|
150
|
+
@send @return(nullable)
|
|
151
|
+
external getValueIntArray: (
|
|
152
|
+
t,
|
|
153
|
+
~name: string,
|
|
154
|
+
~arguments: arguments=?,
|
|
155
|
+
) => option<array<option<int>>> = "getValue"
|
|
156
|
+
|
|
157
|
+
@send @return(nullable)
|
|
158
|
+
external getValueFloat: (t, ~name: string, ~arguments: arguments=?) => option<float> = "getValue"
|
|
159
|
+
|
|
160
|
+
@send @return(nullable)
|
|
161
|
+
external getValueFloatArray: (
|
|
162
|
+
t,
|
|
163
|
+
~name: string,
|
|
164
|
+
~arguments: arguments=?,
|
|
165
|
+
) => option<array<option<float>>> = "getValue"
|
|
166
|
+
|
|
167
|
+
@send @return(nullable)
|
|
168
|
+
external getValueBool: (t, ~name: string, ~arguments: arguments=?) => option<bool> = "getValue"
|
|
169
|
+
|
|
170
|
+
@send @return(nullable)
|
|
171
|
+
external getValueBoolArray: (
|
|
172
|
+
t,
|
|
173
|
+
~name: string,
|
|
174
|
+
~arguments: arguments=?,
|
|
175
|
+
) => option<array<option<bool>>> = "getValue"
|
|
176
|
+
|
|
177
|
+
@send
|
|
178
|
+
external setLinkedRecord: (t, ~record: t, ~name: string, ~arguments: arguments=?) => t =
|
|
179
|
+
"setLinkedRecord"
|
|
180
|
+
|
|
181
|
+
// `setLinkedRecord` can't be used for "deleting" linked record fields.
|
|
182
|
+
// It throws an error if anything besides `record` is received:
|
|
183
|
+
// https://github.com/facebook/relay/blob/bd2e4173ef726804b2ed4e76d88a7bcc1753c496/packages/relay-runtime/mutations/RelayRecordProxy.js#L92
|
|
184
|
+
// However, `setValue` can be used for this purpose instead.
|
|
185
|
+
@send
|
|
186
|
+
external setLinkedRecordToUndefined: (
|
|
187
|
+
t,
|
|
188
|
+
@as(json`undefined`) _,
|
|
189
|
+
~name: string,
|
|
190
|
+
~arguments: arguments=?,
|
|
191
|
+
) => t = "setValue"
|
|
192
|
+
|
|
193
|
+
@send
|
|
194
|
+
external setLinkedRecordToNull: (
|
|
195
|
+
t,
|
|
196
|
+
@as(json`null`) _,
|
|
197
|
+
~name: string,
|
|
198
|
+
~arguments: arguments=?,
|
|
199
|
+
) => t = "setValue"
|
|
200
|
+
|
|
201
|
+
@send
|
|
202
|
+
external setLinkedRecords: (
|
|
203
|
+
t,
|
|
204
|
+
~records: array<option<t>>,
|
|
205
|
+
~name: string,
|
|
206
|
+
~arguments: arguments=?,
|
|
207
|
+
) => t = "setLinkedRecords"
|
|
208
|
+
|
|
209
|
+
// `setLinkedRecords` can't be used for "deleting" linked records.
|
|
210
|
+
// It throws an error if anything besides an array of `records` is received:
|
|
211
|
+
// https://github.com/facebook/relay/blob/bd2e4173ef726804b2ed4e76d88a7bcc1753c496/packages/relay-runtime/mutations/RelayRecordProxy.js#L140
|
|
212
|
+
// However, `setValue` can be used for this purpose instead.
|
|
213
|
+
@send
|
|
214
|
+
external setLinkedRecordsToUndefined: (
|
|
215
|
+
t,
|
|
216
|
+
@as(json`undefined`) _,
|
|
217
|
+
~name: string,
|
|
218
|
+
~arguments: arguments=?,
|
|
219
|
+
) => t = "setValue"
|
|
220
|
+
|
|
221
|
+
@send
|
|
222
|
+
external setLinkedRecordsToNull: (
|
|
223
|
+
t,
|
|
224
|
+
@as(json`null`) _,
|
|
225
|
+
~name: string,
|
|
226
|
+
~arguments: arguments=?,
|
|
227
|
+
) => t = "setValue"
|
|
228
|
+
|
|
229
|
+
@send
|
|
230
|
+
external setValueToUndefined: (
|
|
231
|
+
t,
|
|
232
|
+
@as(json`undefined`) _,
|
|
233
|
+
~name: string,
|
|
234
|
+
~arguments: arguments=?,
|
|
235
|
+
) => t = "setValue"
|
|
236
|
+
|
|
237
|
+
@send
|
|
238
|
+
external setValueToNull: (t, @as(json`null`) _, ~name: string, ~arguments: arguments=?) => t =
|
|
239
|
+
"setValue"
|
|
240
|
+
|
|
241
|
+
@send
|
|
242
|
+
external setValueString: (t, ~value: string, ~name: string, ~arguments: arguments=?) => t =
|
|
243
|
+
"setValue"
|
|
244
|
+
|
|
245
|
+
@send
|
|
246
|
+
external setValueStringArray: (
|
|
247
|
+
t,
|
|
248
|
+
~value: array<string>,
|
|
249
|
+
~name: string,
|
|
250
|
+
~arguments: arguments=?,
|
|
251
|
+
) => t = "setValue"
|
|
252
|
+
|
|
253
|
+
@send
|
|
254
|
+
external setValueInt: (t, ~value: int, ~name: string, ~arguments: arguments=?) => t = "setValue"
|
|
255
|
+
|
|
256
|
+
@send
|
|
257
|
+
external setValueIntArray: (t, ~value: array<int>, ~name: string, ~arguments: arguments=?) => t =
|
|
258
|
+
"setValue"
|
|
259
|
+
|
|
260
|
+
@send
|
|
261
|
+
external setValueFloat: (t, ~value: float, ~name: string, ~arguments: arguments=?) => t =
|
|
262
|
+
"setValue"
|
|
263
|
+
|
|
264
|
+
@send
|
|
265
|
+
external setValueFloatArray: (
|
|
266
|
+
t,
|
|
267
|
+
~value: array<float>,
|
|
268
|
+
~name: string,
|
|
269
|
+
~arguments: arguments=?,
|
|
270
|
+
) => t = "setValue"
|
|
271
|
+
|
|
272
|
+
@send
|
|
273
|
+
external setValueBool: (t, ~value: bool, ~name: string, ~arguments: arguments=?) => t = "setValue"
|
|
274
|
+
|
|
275
|
+
@send
|
|
276
|
+
external setValueBoolArray: (
|
|
277
|
+
t,
|
|
278
|
+
~value: array<bool>,
|
|
279
|
+
~name: string,
|
|
280
|
+
~arguments: arguments=?,
|
|
281
|
+
) => t = "setValue"
|
|
282
|
+
|
|
283
|
+
@send external invalidateRecord: t => unit = "invalidateRecord"
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
module RecordSourceSelectorProxy = {
|
|
287
|
+
type t
|
|
288
|
+
|
|
289
|
+
@send
|
|
290
|
+
external batchLiveStateUpdates: (t, unit => unit) => unit = "batchLiveStateUpdates"
|
|
291
|
+
|
|
292
|
+
@send
|
|
293
|
+
external create: (t, ~dataId: dataId, ~typeName: string) => RecordProxy.t = "create"
|
|
294
|
+
|
|
295
|
+
@send external delete: (t, ~dataId: dataId) => unit = "delete"
|
|
296
|
+
|
|
297
|
+
@send @return(nullable)
|
|
298
|
+
external get: (t, ~dataId: dataId) => option<RecordProxy.t> = "get"
|
|
299
|
+
|
|
300
|
+
@send external getRoot: t => RecordProxy.t = "getRoot"
|
|
301
|
+
|
|
302
|
+
@send @return(nullable)
|
|
303
|
+
external getRootField: (t, ~fieldName: string) => option<RecordProxy.t> = "getRootField"
|
|
304
|
+
|
|
305
|
+
@send @return(nullable)
|
|
306
|
+
external getPluralRootField: (
|
|
307
|
+
t,
|
|
308
|
+
~fieldName: string,
|
|
309
|
+
) => option<array<Js.Nullable.t<RecordProxy.t>>> = "getPluralRootField"
|
|
310
|
+
|
|
311
|
+
let getPluralRootField = (t, ~fieldName): option<array<option<RecordProxy.t>>> =>
|
|
312
|
+
getPluralRootField(t, ~fieldName)->optArrayOfNullableToOptArrayOfOpt
|
|
313
|
+
|
|
314
|
+
@send external invalidateStore: t => unit = "invalidateStore"
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
module ReadOnlyRecordSourceProxy = {
|
|
318
|
+
type t
|
|
319
|
+
|
|
320
|
+
@send @return(nullable)
|
|
321
|
+
external get: (t, ~dataId: dataId) => option<RecordProxy.t> = "get"
|
|
322
|
+
|
|
323
|
+
@send external getRoot: t => RecordProxy.t = "getRoot"
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
module MissingFieldHandler = {
|
|
327
|
+
@@warning("-30")
|
|
328
|
+
type t
|
|
329
|
+
|
|
330
|
+
type normalizationArgumentWrapped = {kind: [#ListValue | #Literal | #ObjectValue | #Variable]}
|
|
331
|
+
|
|
332
|
+
type rec normalizationListValueArgument = {
|
|
333
|
+
name: string,
|
|
334
|
+
items: array<Js.Nullable.t<normalizationArgumentWrapped>>,
|
|
335
|
+
}
|
|
336
|
+
and normalizationLiteralArgument = {
|
|
337
|
+
name: string,
|
|
338
|
+
@as("type") type_: Js.Nullable.t<string>,
|
|
339
|
+
value: Js.Json.t,
|
|
340
|
+
}
|
|
341
|
+
and normalizationObjectValueArgument = {
|
|
342
|
+
name: string,
|
|
343
|
+
fields: Js.Nullable.t<array<normalizationArgumentWrapped>>,
|
|
344
|
+
}
|
|
345
|
+
and normalizationVariableArgument = {
|
|
346
|
+
name: string,
|
|
347
|
+
@as("type") type_: Js.Nullable.t<string>,
|
|
348
|
+
variableName: string,
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
type normalizationArgument =
|
|
352
|
+
| ListValue(normalizationListValueArgument)
|
|
353
|
+
| Literal(normalizationLiteralArgument)
|
|
354
|
+
| ObjectValue(normalizationObjectValueArgument)
|
|
355
|
+
| Variable(normalizationVariableArgument)
|
|
356
|
+
|
|
357
|
+
let unwrapNormalizationArgument = wrapped =>
|
|
358
|
+
switch wrapped.kind {
|
|
359
|
+
| #ListValue => ListValue(Obj.magic(wrapped))
|
|
360
|
+
| #Literal => Literal(Obj.magic(wrapped))
|
|
361
|
+
| #ObjectValue => ObjectValue(Obj.magic(wrapped))
|
|
362
|
+
| #Variable => Variable(Obj.magic(wrapped))
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
type normalizationScalarField = {
|
|
366
|
+
alias: Js.Nullable.t<string>,
|
|
367
|
+
name: string,
|
|
368
|
+
args: Js.Nullable.t<array<normalizationArgumentWrapped>>,
|
|
369
|
+
storageKey: Js.Nullable.t<string>,
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
let makeScalarMissingFieldHandler = handle =>
|
|
373
|
+
Obj.magic({
|
|
374
|
+
"kind": #scalar,
|
|
375
|
+
"handle": handle,
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
type normalizationLinkedField = {
|
|
379
|
+
alias: Js.Nullable.t<string>,
|
|
380
|
+
name: string,
|
|
381
|
+
storageKey: Js.Nullable.t<string>,
|
|
382
|
+
args: Js.Nullable.t<array<normalizationArgument>>,
|
|
383
|
+
concreteType: Js.Nullable.t<string>,
|
|
384
|
+
plural: bool,
|
|
385
|
+
selections: array<Js.Json.t>,
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
let makeLinkedMissingFieldHandler = handle =>
|
|
389
|
+
Obj.magic({
|
|
390
|
+
"kind": #linked,
|
|
391
|
+
"handle": handle,
|
|
392
|
+
})
|
|
393
|
+
|
|
394
|
+
let makePluralLinkedMissingFieldHandler = handle =>
|
|
395
|
+
Obj.magic({
|
|
396
|
+
"kind": #pluralLinked,
|
|
397
|
+
"handle": handle,
|
|
398
|
+
})
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// This handler below enables automatic resolution of all cached items through the Node interface
|
|
402
|
+
let nodeInterfaceMissingFieldHandler = MissingFieldHandler.makeLinkedMissingFieldHandler((
|
|
403
|
+
field,
|
|
404
|
+
record,
|
|
405
|
+
args,
|
|
406
|
+
_store,
|
|
407
|
+
) =>
|
|
408
|
+
switch (Js.Nullable.toOption(record), field["name"], Js.Nullable.toOption(args["id"])) {
|
|
409
|
+
| (Some(record), "node", argsId) if record->RecordProxy.getType == storeRootType => argsId
|
|
410
|
+
| _ => None
|
|
411
|
+
}
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
module ConnectionHandler = {
|
|
415
|
+
@module("relay-runtime") @scope("ConnectionHandler") @return(nullable)
|
|
416
|
+
external getConnection: (
|
|
417
|
+
~record: RecordProxy.t,
|
|
418
|
+
~key: string,
|
|
419
|
+
~filters: arguments=?,
|
|
420
|
+
) => option<RecordProxy.t> = "getConnection"
|
|
421
|
+
|
|
422
|
+
@module("relay-runtime") @scope("ConnectionHandler")
|
|
423
|
+
external createEdge: (
|
|
424
|
+
~store: RecordSourceSelectorProxy.t,
|
|
425
|
+
~connection: RecordProxy.t,
|
|
426
|
+
~node: RecordProxy.t,
|
|
427
|
+
~edgeType: string,
|
|
428
|
+
) => RecordProxy.t = "createEdge"
|
|
429
|
+
|
|
430
|
+
@module("relay-runtime") @scope("ConnectionHandler")
|
|
431
|
+
external insertEdgeBefore: (
|
|
432
|
+
~connection: RecordProxy.t,
|
|
433
|
+
~newEdge: RecordProxy.t,
|
|
434
|
+
~cursor: string=?,
|
|
435
|
+
) => unit = "insertEdgeBefore"
|
|
436
|
+
|
|
437
|
+
@module("relay-runtime") @scope("ConnectionHandler")
|
|
438
|
+
external insertEdgeAfter: (
|
|
439
|
+
~connection: RecordProxy.t,
|
|
440
|
+
~newEdge: RecordProxy.t,
|
|
441
|
+
~cursor: string=?,
|
|
442
|
+
) => unit = "insertEdgeAfter"
|
|
443
|
+
|
|
444
|
+
@module("relay-runtime") @scope("ConnectionHandler")
|
|
445
|
+
external deleteNode: (~connection: RecordProxy.t, ~nodeId: dataId) => unit = "deleteNode"
|
|
446
|
+
|
|
447
|
+
@module("relay-runtime") @scope("ConnectionHandler")
|
|
448
|
+
external getConnectionID: (dataId, string, 'filters) => dataId = "getConnectionID"
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
type operationDescriptor
|
|
452
|
+
|
|
453
|
+
module Disposable = {
|
|
454
|
+
type t
|
|
455
|
+
|
|
456
|
+
@send external dispose: t => unit = "dispose"
|
|
457
|
+
external ignore: t => unit = "%ignore"
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
type cacheConfig = {
|
|
461
|
+
force: option<bool>,
|
|
462
|
+
poll: option<int>,
|
|
463
|
+
liveConfigId: option<string>,
|
|
464
|
+
transactionId: option<string>,
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
module Observable = {
|
|
468
|
+
type t<'response>
|
|
469
|
+
|
|
470
|
+
type subscription = {
|
|
471
|
+
unsubscribe: unit => unit,
|
|
472
|
+
closed: bool,
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
type sink<'response> = {
|
|
476
|
+
next: 'response => unit,
|
|
477
|
+
error: Js.Exn.t => unit,
|
|
478
|
+
complete: unit => unit,
|
|
479
|
+
closed: bool,
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
type observer<'response>
|
|
483
|
+
|
|
484
|
+
@obj
|
|
485
|
+
external makeObserver: (
|
|
486
|
+
~start: subscription => unit=?,
|
|
487
|
+
~next: 'response => unit=?,
|
|
488
|
+
~error: Js.Exn.t => unit=?,
|
|
489
|
+
~complete: unit => unit=?,
|
|
490
|
+
~unsubscribe: subscription => unit=?,
|
|
491
|
+
) => observer<'response> = ""
|
|
492
|
+
|
|
493
|
+
@module("relay-runtime") @scope("Observable")
|
|
494
|
+
external make: (sink<'response> => option<subscription>) => t<'response> = "create"
|
|
495
|
+
|
|
496
|
+
@send
|
|
497
|
+
external subscribe: (t<'response>, observer<'response>) => subscription = "subscribe"
|
|
498
|
+
|
|
499
|
+
@send external toPromise: t<'t> => Js.Promise.t<'t> = "toPromise"
|
|
500
|
+
|
|
501
|
+
external ignoreSubscription: subscription => unit = "%ignore"
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
module Network = {
|
|
505
|
+
type t
|
|
506
|
+
|
|
507
|
+
type codesplitsMetadata = (string, unit => unit)
|
|
508
|
+
|
|
509
|
+
type operationMetadata = {codesplits?: array<codesplitsMetadata>}
|
|
510
|
+
|
|
511
|
+
type operation = {
|
|
512
|
+
id: string,
|
|
513
|
+
text: string,
|
|
514
|
+
name: string,
|
|
515
|
+
operationKind: string,
|
|
516
|
+
metadata: Js.Nullable.t<operationMetadata>,
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
type subscribeFn = (operation, Js.Json.t, cacheConfig) => Observable.t<Js.Json.t>
|
|
520
|
+
|
|
521
|
+
type fetchFunctionPromise = (
|
|
522
|
+
operation,
|
|
523
|
+
Js.Json.t,
|
|
524
|
+
cacheConfig,
|
|
525
|
+
Js.Nullable.t<uploadables>,
|
|
526
|
+
) => Js.Promise.t<Js.Json.t>
|
|
527
|
+
|
|
528
|
+
type fetchFunctionObservable = (
|
|
529
|
+
operation,
|
|
530
|
+
Js.Json.t,
|
|
531
|
+
cacheConfig,
|
|
532
|
+
Js.Nullable.t<uploadables>,
|
|
533
|
+
) => Observable.t<Js.Json.t>
|
|
534
|
+
|
|
535
|
+
@module("relay-runtime") @scope("Network")
|
|
536
|
+
external makePromiseBased: (
|
|
537
|
+
~fetchFunction: fetchFunctionPromise,
|
|
538
|
+
~subscriptionFunction: subscribeFn=?,
|
|
539
|
+
) => t = "create"
|
|
540
|
+
|
|
541
|
+
@module("relay-runtime") @scope("Network")
|
|
542
|
+
external makeObservableBased: (
|
|
543
|
+
~observableFunction: fetchFunctionObservable,
|
|
544
|
+
~subscriptionFunction: subscribeFn=?,
|
|
545
|
+
) => t = "create"
|
|
546
|
+
|
|
547
|
+
let preloadResources: (
|
|
548
|
+
~operation: operation,
|
|
549
|
+
~variables: Js.Json.t,
|
|
550
|
+
~response: Js.Json.t,
|
|
551
|
+
) => unit = %raw(`
|
|
552
|
+
function preloadResources(operation, variables, response) {
|
|
553
|
+
let metadata = operation.metadata;
|
|
554
|
+
if (metadata == null) return;
|
|
555
|
+
let codesplits = metadata.codesplits;
|
|
556
|
+
if (codesplits == null) return;
|
|
557
|
+
let data = response.data;
|
|
558
|
+
|
|
559
|
+
function pathExists(obj, path) {
|
|
560
|
+
let current = obj;
|
|
561
|
+
|
|
562
|
+
for (let i = 0; i < path.length; i++) {
|
|
563
|
+
let segment = path[i];
|
|
564
|
+
|
|
565
|
+
if (Array.isArray(current)) {
|
|
566
|
+
return current.some((item) => pathExists(item, path.slice(i)));
|
|
567
|
+
} else if (current != null && current.hasOwnProperty(segment)) {
|
|
568
|
+
current = current[segment];
|
|
569
|
+
} else if (current != null && (segment.startsWith("$$u$$") || segment.startsWith("$$i$$"))) {
|
|
570
|
+
let isInterface = segment.startsWith("$$i$$");
|
|
571
|
+
let expectedTypename = segment.slice(5);
|
|
572
|
+
if (
|
|
573
|
+
(
|
|
574
|
+
!isInterface &&
|
|
575
|
+
current.hasOwnProperty("__typename") &&
|
|
576
|
+
current.__typename === expectedTypename) ||
|
|
577
|
+
(
|
|
578
|
+
isInterface &&
|
|
579
|
+
current.hasOwnProperty("__is" + expectedTypename) &&
|
|
580
|
+
current["__is" + expectedTypename] != null
|
|
581
|
+
)
|
|
582
|
+
) {
|
|
583
|
+
if (i + 1 === path.length) {
|
|
584
|
+
// End
|
|
585
|
+
return true;
|
|
586
|
+
} else {
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
} else {
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
} else {
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
return current != null;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function run() {
|
|
601
|
+
for (let instruction of codesplits) {
|
|
602
|
+
let path = instruction[0];
|
|
603
|
+
let func = instruction[1];
|
|
604
|
+
if (pathExists(data, path.split("."))) {
|
|
605
|
+
func(variables);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
if ("requestIdleCallback" in window) {
|
|
611
|
+
requestIdleCallback(run);
|
|
612
|
+
} else {
|
|
613
|
+
setTimeout(() => {
|
|
614
|
+
Promise.resolve().then(run);
|
|
615
|
+
}, 1);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
`)
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
module RecordSource = {
|
|
622
|
+
type t
|
|
623
|
+
|
|
624
|
+
@module("relay-runtime") @new
|
|
625
|
+
external make: (~records: recordSourceRecords=?) => t = "RecordSource"
|
|
626
|
+
|
|
627
|
+
@send external toJSON: t => recordSourceRecords = "toJSON"
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
module Store = {
|
|
631
|
+
type t
|
|
632
|
+
|
|
633
|
+
type storeConfig = {
|
|
634
|
+
gcReleaseBufferSize: option<int>,
|
|
635
|
+
queryCacheExpirationTime: option<int>,
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
@module @new
|
|
639
|
+
external makeLiveStoreCjs: (RecordSource.t, storeConfig) => t =
|
|
640
|
+
"relay-runtime/lib/store/experimental-live-resolvers/LiveResolverStore"
|
|
641
|
+
|
|
642
|
+
@module("relay-runtime/lib/store/experimental-live-resolvers/LiveResolverStore") @new
|
|
643
|
+
external makeLiveStore: (RecordSource.t, storeConfig) => t = "default"
|
|
644
|
+
|
|
645
|
+
@module("relay-runtime") @new
|
|
646
|
+
external make: (RecordSource.t, storeConfig) => t = "Store"
|
|
647
|
+
|
|
648
|
+
let make = (~source, ~gcReleaseBufferSize=?, ~queryCacheExpirationTime=?) =>
|
|
649
|
+
make(
|
|
650
|
+
source,
|
|
651
|
+
{
|
|
652
|
+
gcReleaseBufferSize,
|
|
653
|
+
queryCacheExpirationTime,
|
|
654
|
+
},
|
|
655
|
+
)
|
|
656
|
+
|
|
657
|
+
let makeLiveStore = (~source, ~gcReleaseBufferSize=?, ~queryCacheExpirationTime=?) =>
|
|
658
|
+
makeLiveStore(
|
|
659
|
+
source,
|
|
660
|
+
{
|
|
661
|
+
gcReleaseBufferSize,
|
|
662
|
+
queryCacheExpirationTime,
|
|
663
|
+
},
|
|
664
|
+
)
|
|
665
|
+
|
|
666
|
+
let _makeLiveStoreCjs = (~source, ~gcReleaseBufferSize=?, ~queryCacheExpirationTime=?) =>
|
|
667
|
+
makeLiveStoreCjs(
|
|
668
|
+
source,
|
|
669
|
+
{
|
|
670
|
+
gcReleaseBufferSize,
|
|
671
|
+
queryCacheExpirationTime,
|
|
672
|
+
},
|
|
673
|
+
)
|
|
674
|
+
|
|
675
|
+
@send external getSource: t => RecordSource.t = "getSource"
|
|
676
|
+
@send external publish: (t, RecordSource.t) => unit = "publish"
|
|
677
|
+
@send external holdGC: t => unit = "holdGC"
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
module RelayFieldLogger = {
|
|
681
|
+
@tag("kind")
|
|
682
|
+
type arg =
|
|
683
|
+
| @as("missing_field.log") MissingFieldLog({owner: string, fieldPath: string})
|
|
684
|
+
| @as("missing_field.throw") MissingFieldThrow({owner: string, fieldPath: string})
|
|
685
|
+
| @as("relay_resolver.error")
|
|
686
|
+
RelayResolverError({
|
|
687
|
+
owner: string,
|
|
688
|
+
fieldPath: string,
|
|
689
|
+
error: Js.Exn.t,
|
|
690
|
+
})
|
|
691
|
+
|
|
692
|
+
type t = arg => unit
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
module Environment = {
|
|
696
|
+
type t
|
|
697
|
+
|
|
698
|
+
type environmentConfig<'a> = {
|
|
699
|
+
network: Network.t,
|
|
700
|
+
store: Store.t,
|
|
701
|
+
getDataID?: (~nodeObj: 'a, ~typeName: string) => string,
|
|
702
|
+
treatMissingFieldsAsNull?: bool,
|
|
703
|
+
missingFieldHandlers: array<MissingFieldHandler.t>,
|
|
704
|
+
relayFieldLogger?: RelayFieldLogger.t,
|
|
705
|
+
isServer?: bool,
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
@module("relay-runtime") @new
|
|
709
|
+
external make: environmentConfig<'a> => t = "Environment"
|
|
710
|
+
|
|
711
|
+
let make = (
|
|
712
|
+
~network,
|
|
713
|
+
~store,
|
|
714
|
+
~getDataID=?,
|
|
715
|
+
~treatMissingFieldsAsNull=?,
|
|
716
|
+
~missingFieldHandlers=?,
|
|
717
|
+
~relayFieldLogger=?,
|
|
718
|
+
~isServer=?,
|
|
719
|
+
) =>
|
|
720
|
+
make({
|
|
721
|
+
network,
|
|
722
|
+
store,
|
|
723
|
+
?getDataID,
|
|
724
|
+
?treatMissingFieldsAsNull,
|
|
725
|
+
missingFieldHandlers: switch missingFieldHandlers {
|
|
726
|
+
| Some(handlers) => handlers->Belt.Array.concat([nodeInterfaceMissingFieldHandler])
|
|
727
|
+
| None => [nodeInterfaceMissingFieldHandler]
|
|
728
|
+
},
|
|
729
|
+
?relayFieldLogger,
|
|
730
|
+
?isServer,
|
|
731
|
+
})
|
|
732
|
+
|
|
733
|
+
@send external getStore: t => Store.t = "getStore"
|
|
734
|
+
@send
|
|
735
|
+
external commitPayload: (t, operationDescriptor, 'payload) => unit = "commitPayload"
|
|
736
|
+
@send external retain: (t, operationDescriptor) => Disposable.t = "retain"
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
module Context = {
|
|
740
|
+
type t
|
|
741
|
+
|
|
742
|
+
type contextShape = {"environment": Environment.t}
|
|
743
|
+
|
|
744
|
+
@module("react-relay")
|
|
745
|
+
external context: React.Context.t<option<contextShape>> = "ReactRelayContext"
|
|
746
|
+
|
|
747
|
+
module Provider = {
|
|
748
|
+
@react.component
|
|
749
|
+
let make = (~environment: Environment.t, ~children) => {
|
|
750
|
+
let provider = React.Context.provider(context)
|
|
751
|
+
React.createElement(provider, {value: Some({"environment": environment}), children})
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
exception EnvironmentNotFoundInContext
|
|
757
|
+
|
|
758
|
+
let useEnvironmentFromContext = () => {
|
|
759
|
+
let context = React.useContext(Context.context)
|
|
760
|
+
|
|
761
|
+
switch context {
|
|
762
|
+
| Some(ctx) => ctx["environment"]
|
|
763
|
+
| None => raise(EnvironmentNotFoundInContext)
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
type fetchPolicy =
|
|
768
|
+
| @as("store-only") StoreOnly
|
|
769
|
+
| @as("store-or-network") StoreOrNetwork
|
|
770
|
+
| @as("store-and-network") StoreAndNetwork
|
|
771
|
+
| @as("network-only") NetworkOnly
|
|
772
|
+
|
|
773
|
+
type fetchQueryFetchPolicy =
|
|
774
|
+
| @as("network-only") NetworkOnly
|
|
775
|
+
| @as("store-or-network") StoreOrNetwork
|
|
776
|
+
|
|
777
|
+
type fetchQueryOptions = {
|
|
778
|
+
networkCacheConfig?: cacheConfig,
|
|
779
|
+
fetchPolicy?: fetchPolicy,
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
type loadQueryConfig = {
|
|
783
|
+
fetchKey: option<string>,
|
|
784
|
+
fetchPolicy: option<fetchPolicy>,
|
|
785
|
+
networkCacheConfig: option<cacheConfig>,
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
@module("react-relay")
|
|
789
|
+
external loadQuery: (Environment.t, queryNode<'a>, 'variables, loadQueryConfig) => 'queryResponse =
|
|
790
|
+
"loadQuery"
|
|
791
|
+
|
|
792
|
+
module type MakeLoadQueryConfig = {
|
|
793
|
+
type variables
|
|
794
|
+
type loadedQueryRef
|
|
795
|
+
type response
|
|
796
|
+
type node
|
|
797
|
+
let query: queryNode<node>
|
|
798
|
+
let convertVariables: variables => variables
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
module MakeLoadQuery = (C: MakeLoadQueryConfig) => {
|
|
802
|
+
let load: (
|
|
803
|
+
~environment: Environment.t,
|
|
804
|
+
~variables: C.variables,
|
|
805
|
+
~fetchPolicy: fetchPolicy=?,
|
|
806
|
+
~fetchKey: string=?,
|
|
807
|
+
~networkCacheConfig: cacheConfig=?,
|
|
808
|
+
) => C.loadedQueryRef = (
|
|
809
|
+
~environment,
|
|
810
|
+
~variables,
|
|
811
|
+
~fetchPolicy=?,
|
|
812
|
+
~fetchKey=?,
|
|
813
|
+
~networkCacheConfig=?,
|
|
814
|
+
) =>
|
|
815
|
+
loadQuery(
|
|
816
|
+
environment,
|
|
817
|
+
C.query,
|
|
818
|
+
variables->C.convertVariables,
|
|
819
|
+
{
|
|
820
|
+
fetchKey,
|
|
821
|
+
fetchPolicy,
|
|
822
|
+
networkCacheConfig,
|
|
823
|
+
},
|
|
824
|
+
)
|
|
825
|
+
|
|
826
|
+
type rawPreloadToken<'response> = {source: Js.Nullable.t<Observable.t<'response>>}
|
|
827
|
+
external tokenToRaw: C.loadedQueryRef => rawPreloadToken<C.response> = "%identity"
|
|
828
|
+
|
|
829
|
+
let queryRefToObservable = token => {
|
|
830
|
+
let raw = token->tokenToRaw
|
|
831
|
+
raw.source->Js.Nullable.toOption
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
let queryRefToPromise = token => {
|
|
835
|
+
Js.Promise.make((~resolve, ~reject as _) => {
|
|
836
|
+
switch token->queryRefToObservable {
|
|
837
|
+
| None => resolve(Error())
|
|
838
|
+
| Some(o) =>
|
|
839
|
+
open Observable
|
|
840
|
+
let _: subscription = o->subscribe(makeObserver(~complete=() => resolve(Ok())))
|
|
841
|
+
}
|
|
842
|
+
})
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
type mutationError = {message: string}
|
|
847
|
+
|
|
848
|
+
exception Mutation_failed(array<mutationError>)
|
|
849
|
+
|
|
850
|
+
@module("relay-runtime")
|
|
851
|
+
external commitLocalUpdate: (
|
|
852
|
+
~environment: Environment.t,
|
|
853
|
+
~updater: RecordSourceSelectorProxy.t => unit,
|
|
854
|
+
) => unit = "commitLocalUpdate"
|
|
855
|
+
|
|
856
|
+
@module("react-relay")
|
|
857
|
+
external useSubscribeToInvalidationState: (array<dataId>, unit => unit) => Disposable.t =
|
|
858
|
+
"useSubscribeToInvalidationState"
|