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,897 @@
|
|
|
1
|
+
/**Abstract type for arguments, used when selecting fields on `RecordProxy` and friends when interacting with the store imperatively.*/
|
|
2
|
+
type arguments
|
|
3
|
+
|
|
4
|
+
/**Abstract type for uploadables.
|
|
5
|
+
|
|
6
|
+
### Constructing an `uploadables`
|
|
7
|
+
Use `makeUploadable`: `makeUploadable({ "someFile": theFileYouWantToUpload })` to construct an `uploadables`, and then pass it to your mutation via the `uploadables` prop.
|
|
8
|
+
|
|
9
|
+
Please note that you'll need to handle _sending_ the uploadables to your server yourself in the network layer. [Here's an example](https://github.com/facebook/relay/issues/1844#issuecomment-316893590) in regular JS that you can adapt to ReScript as you need/want.*/
|
|
10
|
+
type uploadables
|
|
11
|
+
|
|
12
|
+
/**If you see this, it means that all fields have been masked in this selection, which is why it contains no data. Relay uses [_data masking_](https://relay.dev/docs/en/thinking-in-relay.html#data-masking) to hide data you haven't explicitly asked for, even if it exists on the object.*/
|
|
13
|
+
type allFieldsMasked = {.}
|
|
14
|
+
|
|
15
|
+
/**Abstract helper type to signify something that could not be generated in a type-safe way.*/
|
|
16
|
+
type any
|
|
17
|
+
|
|
18
|
+
/**A query node, used internally by Relay. These are runtime artifacts produced by the Relay compiler.*/
|
|
19
|
+
type queryNode<'node>
|
|
20
|
+
|
|
21
|
+
/**A fragment node, used internally by Relay. These are runtime artifacts produced by the Relay compiler.*/
|
|
22
|
+
type fragmentNode<'node>
|
|
23
|
+
|
|
24
|
+
/**A mutation node, used internally by Relay. These are runtime artifacts produced by the Relay compiler.*/
|
|
25
|
+
type mutationNode<'node>
|
|
26
|
+
|
|
27
|
+
/**A subscription node, used internally by Relay. These are runtime artifacts produced by the Relay compiler.*/
|
|
28
|
+
type subscriptionNode<'node>
|
|
29
|
+
|
|
30
|
+
/**This type shows all of the fragments that has been spread on this particular object.*/
|
|
31
|
+
type fragmentRefs<'fragments>
|
|
32
|
+
|
|
33
|
+
/**This type shows the Relay resolver fragment that has been spread on this particular object.*/
|
|
34
|
+
type resolverFragmentRefs<'fragments>
|
|
35
|
+
|
|
36
|
+
/**This type shows all of the updatable fragments that has been spread on this particular object.*/
|
|
37
|
+
type updatableFragmentRefs<'fragments>
|
|
38
|
+
|
|
39
|
+
/**The type of the id Relay uses to identify records in its store.*/
|
|
40
|
+
type dataId
|
|
41
|
+
|
|
42
|
+
type dataIdObject = {id: dataId}
|
|
43
|
+
|
|
44
|
+
module SuspenseSentinel: {
|
|
45
|
+
type t
|
|
46
|
+
|
|
47
|
+
@module("relay-runtime") external suspend: t => 'any = "suspenseSentinel"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type liveStateCallback = unit => unit
|
|
51
|
+
type liveStateUnsubscribeCallback = unit => unit
|
|
52
|
+
|
|
53
|
+
type liveState<'value> = {
|
|
54
|
+
read: SuspenseSentinel.t => 'value,
|
|
55
|
+
subscribe: liveStateCallback => liveStateUnsubscribeCallback,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@module("relay-runtime/experimental")
|
|
59
|
+
external resolverDataInjector: ('a, 'b, 'c, 'd) => 'return = "resolverDataInjector"
|
|
60
|
+
|
|
61
|
+
/**Turns a `dataId` into a `string`.*/
|
|
62
|
+
external dataIdToString: dataId => string = "%identity"
|
|
63
|
+
|
|
64
|
+
/**Turns a `string` into a `dataId`.*/
|
|
65
|
+
external makeDataId: string => dataId = "%identity"
|
|
66
|
+
|
|
67
|
+
/**Construct an `arguments` object for use with certain Relay store APIs.
|
|
68
|
+
|
|
69
|
+
### Usage
|
|
70
|
+
Use it like this: `makeArguments({ "someArgument": someValue, "anotherArgument": anotherValue })`. Notice the "" surrounding the property names - these are important and tells ReScript that we want this to be a JS object.*/
|
|
71
|
+
external makeArguments: {..} => arguments = "%identity"
|
|
72
|
+
|
|
73
|
+
/**Construct an `uploadables` object from a `Js.Dict` with your desired file format, that you can use for uploads via Relay.*/
|
|
74
|
+
external makeUploadables: Js.Dict.t<'file> => uploadables = "%identity"
|
|
75
|
+
|
|
76
|
+
/**Unwraps `uploadables` into a Js.Dict.t with your expected file type, so you can use that dict to attach the provided files to your request.*/
|
|
77
|
+
external unwrapUploadables: uploadables => Js.Dict.t<'file> = "%identity"
|
|
78
|
+
|
|
79
|
+
/**This generates a `dataId` for use on the _client_ side. However, this is farily low level, and what you're probably really looking for is `generateUniqueClientID` that'll let you generate a new, unique `dataId` that you can use for client side only records (like when doing optimistic updates).*/
|
|
80
|
+
@module("relay-runtime")
|
|
81
|
+
external generateClientID: (~dataId: dataId, ~storageKey: string, ~index: int=?) => dataId =
|
|
82
|
+
"generateClientID"
|
|
83
|
+
|
|
84
|
+
/**This generates a unique `dataId` that's safe to use on the _client_ side. Useful when doing optimistic updates and you need to create IDs that the optimistic update can use.*/
|
|
85
|
+
@module("relay-runtime")
|
|
86
|
+
external generateUniqueClientID: unit => dataId = "generateUniqueClientID"
|
|
87
|
+
|
|
88
|
+
/**Checks whether the provided `dataId` is guaranteed to be a client side only id.*/
|
|
89
|
+
@module("relay-runtime")
|
|
90
|
+
external isClientID: dataId => bool = "isClientID"
|
|
91
|
+
|
|
92
|
+
/**Relay feature flags. Mutate this record as soon as your application boots to enable/disable features.*/
|
|
93
|
+
type featureFlags = {
|
|
94
|
+
@as("DELAY_CLEANUP_OF_PENDING_PRELOAD_QUERIES")
|
|
95
|
+
mutable delayCleanupOfPendingPreloadQueries: bool,
|
|
96
|
+
@as("ENABLE_CLIENT_EDGES")
|
|
97
|
+
mutable enableClientEdges: bool,
|
|
98
|
+
@as("ENABLE_VARIABLE_CONNECTION_KEY")
|
|
99
|
+
mutable enableVariableConnectionKey: bool,
|
|
100
|
+
@as("ENABLE_PARTIAL_RENDERING_DEFAULT")
|
|
101
|
+
mutable enablePartialRenderingDefault: bool,
|
|
102
|
+
@as("ENABLE_REACT_FLIGHT_COMPONENT_FIELD")
|
|
103
|
+
mutable enableReactFlightComponentField: bool,
|
|
104
|
+
@as("ENABLE_RELAY_RESOLVERS")
|
|
105
|
+
mutable enableRelayResolvers: bool,
|
|
106
|
+
@as("ENABLE_GETFRAGMENTIDENTIFIER_OPTIMIZATION")
|
|
107
|
+
mutable enableGetFragmentIdentifierOptimization: bool,
|
|
108
|
+
@as("ENABLE_FRIENDLY_QUERY_NAME_GQL_URL")
|
|
109
|
+
mutable enableFriendlyQueryNameGqlUrl: bool,
|
|
110
|
+
@as("ENABLE_LOAD_QUERY_REQUEST_DEDUPING")
|
|
111
|
+
mutable enableLoadQueryRequestDeduping: bool,
|
|
112
|
+
@as("ENABLE_DO_NOT_WRAP_LIVE_QUERY")
|
|
113
|
+
mutable enableDoNotWrapLiveQuery: bool,
|
|
114
|
+
@as("ENABLE_NOTIFY_SUBSCRIPTION")
|
|
115
|
+
mutable enableNotifySubscription: bool,
|
|
116
|
+
@as("ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT")
|
|
117
|
+
mutable enableContainersSubscribeOnCommit: bool,
|
|
118
|
+
@as("ENABLE_QUERY_RENDERER_OFFSCREEN_SUPPORT")
|
|
119
|
+
mutable enableQueryRendererOffscreenSupport: bool,
|
|
120
|
+
@as("MAX_DATA_ID_LENGTH")
|
|
121
|
+
mutable maxDataIdLength: option<int>,
|
|
122
|
+
@as("REFACTOR_SUSPENSE_RESOURCE")
|
|
123
|
+
mutable refactorSuspenseResource: bool,
|
|
124
|
+
@as("STRING_INTERN_LEVEL")
|
|
125
|
+
mutable stringInternLevel: int,
|
|
126
|
+
@as("USE_REACT_CACHE")
|
|
127
|
+
mutable useReactCache: bool,
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**Relay feature flags. Mutate this record as soon as your application boots to enable/disable features.*/
|
|
131
|
+
@module("relay-runtime")
|
|
132
|
+
external relayFeatureFlags: featureFlags = "RelayFeatureFlags"
|
|
133
|
+
|
|
134
|
+
/**Representing all records in the store serialized to JSON in a way that you can use to re-hydrate the store.
|
|
135
|
+
|
|
136
|
+
See `RecordSource.toJSON` for how to produce it.*/
|
|
137
|
+
type recordSourceRecords = Js.Json.t
|
|
138
|
+
|
|
139
|
+
/**The `dataId` for the Relay store's root. Useful when for example referencing the `parentID` of a connection that's on the store root.*/
|
|
140
|
+
@module("relay-runtime")
|
|
141
|
+
external storeRootId: dataId = "ROOT_ID"
|
|
142
|
+
|
|
143
|
+
/**The `type` for the Relay store's root `RecordProxy`.*/
|
|
144
|
+
@module("relay-runtime")
|
|
145
|
+
external storeRootType: string = "ROOT_TYPE"
|
|
146
|
+
|
|
147
|
+
/**Internal, do not use.*/
|
|
148
|
+
@module("./utils")
|
|
149
|
+
external convertObj: ('a, Js.Dict.t<Js.Dict.t<Js.Dict.t<string>>>, 'b, 'c) => 'd = "traverser"
|
|
150
|
+
|
|
151
|
+
/**Read the following section on working with the Relay store: https://relay.dev/docs/en/relay-store*/
|
|
152
|
+
module RecordProxy: {
|
|
153
|
+
/**Read the following section on working with the Relay store: https://relay.dev/docs/en/relay-store*/
|
|
154
|
+
type t
|
|
155
|
+
|
|
156
|
+
/**Copies all fields from one `RecordProxy` to another.*/
|
|
157
|
+
@send
|
|
158
|
+
external copyFieldsFrom: (t, ~sourceRecord: t) => unit = "copyFieldsFrom"
|
|
159
|
+
|
|
160
|
+
/**Gets the `dataId` for a particular record.*/
|
|
161
|
+
@send
|
|
162
|
+
external getDataId: t => dataId = "getDataID"
|
|
163
|
+
|
|
164
|
+
/**Gets a single linked record. A linked record is another object in the store, and not a scalar field like an int or float.*/
|
|
165
|
+
@send
|
|
166
|
+
@return(nullable)
|
|
167
|
+
external getLinkedRecord: (t, ~name: string, ~arguments: arguments=?) => option<t> =
|
|
168
|
+
"getLinkedRecord"
|
|
169
|
+
|
|
170
|
+
/**Gets an array of linked records, for when a field is a list (meaning a link to multiple records).*/
|
|
171
|
+
let getLinkedRecords: (t, ~name: string, ~arguments: arguments=?) => option<array<option<t>>>
|
|
172
|
+
|
|
173
|
+
/**This returns an existing linked record, or creates one at the configured place if one does not already exist.*/
|
|
174
|
+
@send
|
|
175
|
+
external getOrCreateLinkedRecord: (
|
|
176
|
+
t,
|
|
177
|
+
~name: string,
|
|
178
|
+
~typeName: string,
|
|
179
|
+
~arguments: arguments=?,
|
|
180
|
+
) => t = "getOrCreateLinkedRecord"
|
|
181
|
+
|
|
182
|
+
/**Returns the `__typename` of this particular record.*/
|
|
183
|
+
@send
|
|
184
|
+
external getType: t => string = "getType"
|
|
185
|
+
|
|
186
|
+
/**Returns a field value, expecting it to be a string.*/
|
|
187
|
+
@send
|
|
188
|
+
@return(nullable)
|
|
189
|
+
external getValueString: (t, ~name: string, ~arguments: arguments=?) => option<string> =
|
|
190
|
+
"getValue"
|
|
191
|
+
|
|
192
|
+
/**Returns a field value, expecting it to be an array of strings.*/
|
|
193
|
+
@send
|
|
194
|
+
@return(nullable)
|
|
195
|
+
external getValueStringArray: (
|
|
196
|
+
t,
|
|
197
|
+
~name: string,
|
|
198
|
+
~arguments: arguments=?,
|
|
199
|
+
) => option<array<option<string>>> = "getValue"
|
|
200
|
+
|
|
201
|
+
/**Returns a field value, expecting it to be an int.*/
|
|
202
|
+
@send
|
|
203
|
+
@return(nullable)
|
|
204
|
+
external getValueInt: (t, ~name: string, ~arguments: arguments=?) => option<int> = "getValue"
|
|
205
|
+
|
|
206
|
+
/**Returns a field value, expecting it to be an array of ints.*/
|
|
207
|
+
@send
|
|
208
|
+
@return(nullable)
|
|
209
|
+
external getValueIntArray: (
|
|
210
|
+
t,
|
|
211
|
+
~name: string,
|
|
212
|
+
~arguments: arguments=?,
|
|
213
|
+
) => option<array<option<int>>> = "getValue"
|
|
214
|
+
|
|
215
|
+
/**Returns a field value, expecting it to be a float.*/
|
|
216
|
+
@send
|
|
217
|
+
@return(nullable)
|
|
218
|
+
external getValueFloat: (t, ~name: string, ~arguments: arguments=?) => option<float> = "getValue"
|
|
219
|
+
|
|
220
|
+
/**Returns a field value, expecting it to be an array of floats.*/
|
|
221
|
+
@send
|
|
222
|
+
@return(nullable)
|
|
223
|
+
external getValueFloatArray: (
|
|
224
|
+
t,
|
|
225
|
+
~name: string,
|
|
226
|
+
~arguments: arguments=?,
|
|
227
|
+
) => option<array<option<float>>> = "getValue"
|
|
228
|
+
|
|
229
|
+
/**Returns a field value, expecting it to be a boolean.*/
|
|
230
|
+
@send
|
|
231
|
+
@return(nullable)
|
|
232
|
+
external getValueBool: (t, ~name: string, ~arguments: arguments=?) => option<bool> = "getValue"
|
|
233
|
+
|
|
234
|
+
/**Returns a field value, expecting it to be an array of booleans.*/
|
|
235
|
+
@send
|
|
236
|
+
@return(nullable)
|
|
237
|
+
external getValueBoolArray: (
|
|
238
|
+
t,
|
|
239
|
+
~name: string,
|
|
240
|
+
~arguments: arguments=?,
|
|
241
|
+
) => option<array<option<bool>>> = "getValue"
|
|
242
|
+
|
|
243
|
+
/**Sets a `RecordProxy.t` as the linked record for a particular field.*/
|
|
244
|
+
@send
|
|
245
|
+
external setLinkedRecord: (t, ~record: t, ~name: string, ~arguments: arguments=?) => t =
|
|
246
|
+
"setLinkedRecord"
|
|
247
|
+
|
|
248
|
+
/**Sets an array of `RecordProxy.t` as the linked records for a particular field.*/
|
|
249
|
+
@send
|
|
250
|
+
external setLinkedRecords: (
|
|
251
|
+
t,
|
|
252
|
+
~records: array<option<t>>,
|
|
253
|
+
~name: string,
|
|
254
|
+
~arguments: arguments=?,
|
|
255
|
+
) => t = "setLinkedRecords"
|
|
256
|
+
|
|
257
|
+
/**Sets a string as field value.*/
|
|
258
|
+
@send
|
|
259
|
+
external setValueString: (t, ~value: string, ~name: string, ~arguments: arguments=?) => t =
|
|
260
|
+
"setValue"
|
|
261
|
+
|
|
262
|
+
/**Sets an array of strings as field value.*/
|
|
263
|
+
@send
|
|
264
|
+
external setValueStringArray: (
|
|
265
|
+
t,
|
|
266
|
+
~value: array<string>,
|
|
267
|
+
~name: string,
|
|
268
|
+
~arguments: arguments=?,
|
|
269
|
+
) => t = "setValue"
|
|
270
|
+
|
|
271
|
+
/**Sets an int as field value.*/
|
|
272
|
+
@send
|
|
273
|
+
external setValueInt: (t, ~value: int, ~name: string, ~arguments: arguments=?) => t = "setValue"
|
|
274
|
+
|
|
275
|
+
/**Sets an array of ints as field value.*/
|
|
276
|
+
@send
|
|
277
|
+
external setValueIntArray: (t, ~value: array<int>, ~name: string, ~arguments: arguments=?) => t =
|
|
278
|
+
"setValue"
|
|
279
|
+
|
|
280
|
+
/**Sets a float as field value.*/
|
|
281
|
+
@send
|
|
282
|
+
external setValueFloat: (t, ~value: float, ~name: string, ~arguments: arguments=?) => t =
|
|
283
|
+
"setValue"
|
|
284
|
+
|
|
285
|
+
/**Sets an array of floats as field value.*/
|
|
286
|
+
@send
|
|
287
|
+
external setValueFloatArray: (
|
|
288
|
+
t,
|
|
289
|
+
~value: array<float>,
|
|
290
|
+
~name: string,
|
|
291
|
+
~arguments: arguments=?,
|
|
292
|
+
) => t = "setValue"
|
|
293
|
+
|
|
294
|
+
/**Sets a boolean as field value.*/
|
|
295
|
+
@send
|
|
296
|
+
external setValueBool: (t, ~value: bool, ~name: string, ~arguments: arguments=?) => t = "setValue"
|
|
297
|
+
|
|
298
|
+
/**Sets an array of booleans as field value.*/
|
|
299
|
+
@send
|
|
300
|
+
external setValueBoolArray: (
|
|
301
|
+
t,
|
|
302
|
+
~value: array<bool>,
|
|
303
|
+
~name: string,
|
|
304
|
+
~arguments: arguments=?,
|
|
305
|
+
) => t = "setValue"
|
|
306
|
+
|
|
307
|
+
/**Sets the field value to `undefined` (meaning Relay will treat it as missing data).*/
|
|
308
|
+
@send
|
|
309
|
+
external setValueToUndefined: (
|
|
310
|
+
t,
|
|
311
|
+
@as(json`undefined`) _,
|
|
312
|
+
~name: string,
|
|
313
|
+
~arguments: arguments=?,
|
|
314
|
+
) => t = "setValue"
|
|
315
|
+
|
|
316
|
+
/**Sets the field value to `null`.*/
|
|
317
|
+
@send
|
|
318
|
+
external setValueToNull: (t, @as(json`null`) _, ~name: string, ~arguments: arguments=?) => t =
|
|
319
|
+
"setValue"
|
|
320
|
+
|
|
321
|
+
/**Sets this linked record to `undefined` (meaning Relay will treat it as missing data).*/
|
|
322
|
+
@send
|
|
323
|
+
external setLinkedRecordToUndefined: (
|
|
324
|
+
t,
|
|
325
|
+
@as(json`undefined`) _,
|
|
326
|
+
~name: string,
|
|
327
|
+
~arguments: arguments=?,
|
|
328
|
+
) => t = "setValue"
|
|
329
|
+
|
|
330
|
+
/**Sets this linked record to `null`.*/
|
|
331
|
+
@send
|
|
332
|
+
external setLinkedRecordToNull: (
|
|
333
|
+
t,
|
|
334
|
+
@as(json`null`) _,
|
|
335
|
+
~name: string,
|
|
336
|
+
~arguments: arguments=?,
|
|
337
|
+
) => t = "setValue"
|
|
338
|
+
|
|
339
|
+
/**Sets the field holding these linked records to `undefined` (meaning Relay will treat it as missing data).*/
|
|
340
|
+
@send
|
|
341
|
+
external setLinkedRecordsToUndefined: (
|
|
342
|
+
t,
|
|
343
|
+
@as(json`undefined`) _,
|
|
344
|
+
~name: string,
|
|
345
|
+
~arguments: arguments=?,
|
|
346
|
+
) => t = "setValue"
|
|
347
|
+
|
|
348
|
+
/**Sets the field holding these linked records to `null`.*/
|
|
349
|
+
@send
|
|
350
|
+
external setLinkedRecordsToNull: (
|
|
351
|
+
t,
|
|
352
|
+
@as(json`null`) _,
|
|
353
|
+
~name: string,
|
|
354
|
+
~arguments: arguments=?,
|
|
355
|
+
) => t = "setValue"
|
|
356
|
+
|
|
357
|
+
/**Invalidates this record.
|
|
358
|
+
|
|
359
|
+
Invalidating a record means that the _next_ time Relay evaluates this record, it'll be treated as missing.
|
|
360
|
+
|
|
361
|
+
_Beware_ that this doesn't mean that queries using this record will refetch immediately. Rather, it'll happen the next time the query _renders_. Have a look at `useSubscribeToInvalidationState`, that'll allow you to subscribe to whenever records are invalidated, if you're looking for a way to refetch immediately as something invalidates.*/
|
|
362
|
+
@send
|
|
363
|
+
external invalidateRecord: t => unit = "invalidateRecord"
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**RecordSourceSelectorProxy and RecordSourceProxy are the two modules representing the store, with various capabilities.*/
|
|
367
|
+
module RecordSourceSelectorProxy: {
|
|
368
|
+
/**Type type representing a `RecordSourceSelectorProxy`.*/
|
|
369
|
+
type t
|
|
370
|
+
|
|
371
|
+
@send
|
|
372
|
+
external batchLiveStateUpdates: (t, unit => unit) => unit = "batchLiveStateUpdates"
|
|
373
|
+
|
|
374
|
+
/**Creates a new `RecordProxy`.*/
|
|
375
|
+
@send
|
|
376
|
+
external create: (t, ~dataId: dataId, ~typeName: string) => RecordProxy.t = "create"
|
|
377
|
+
|
|
378
|
+
/**Deletes the `RecordProxy` with the provided `dataId`.*/
|
|
379
|
+
@send
|
|
380
|
+
external delete: (t, ~dataId: dataId) => unit = "delete"
|
|
381
|
+
|
|
382
|
+
/**Returns the `RecordProxy` with the provided `dataId`, if it exists.*/
|
|
383
|
+
@send
|
|
384
|
+
@return(nullable)
|
|
385
|
+
external get: (t, ~dataId: dataId) => option<RecordProxy.t> = "get"
|
|
386
|
+
|
|
387
|
+
/**Returns the _root_ `RecordProxy`, meaning the `RecordProxy` holding your top level fields.*/
|
|
388
|
+
@send
|
|
389
|
+
external getRoot: t => RecordProxy.t = "getRoot"
|
|
390
|
+
|
|
391
|
+
/**Returns the `RecordProxy` for the `fieldName` at root. You should prefer using `RecordSourceSelectorProxy.getRoot()` and traverse from there if you need access to root fields rather than use this.*/
|
|
392
|
+
@send
|
|
393
|
+
@return(nullable)
|
|
394
|
+
external getRootField: (t, ~fieldName: string) => option<RecordProxy.t> = "getRootField"
|
|
395
|
+
|
|
396
|
+
/**Plural version of `RecordSourceSelectorProxy.getRootField`.*/
|
|
397
|
+
let getPluralRootField: (t, ~fieldName: string) => option<array<option<RecordProxy.t>>>
|
|
398
|
+
|
|
399
|
+
/**Invalidates the entire store. This means that _at the next render_, the entire store will be treated as empty, meaning Relay will refetch everything it needs to show the view it's to show.*/
|
|
400
|
+
@send
|
|
401
|
+
external invalidateStore: t => unit = "invalidateStore"
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**ReadOnlyRecordSourceProxy is the store, but in read-only mode.*/
|
|
405
|
+
module ReadOnlyRecordSourceProxy: {
|
|
406
|
+
/**Type type representing a `ReadOnlyRecordSourceProxy`.*/
|
|
407
|
+
type t
|
|
408
|
+
|
|
409
|
+
/**Returns the `RecordProxy` with the provided `dataId`, if it exists.*/
|
|
410
|
+
@send
|
|
411
|
+
@return(nullable)
|
|
412
|
+
external get: (t, ~dataId: dataId) => option<RecordProxy.t> = "get"
|
|
413
|
+
|
|
414
|
+
/**Returns the _root_ `RecordProxy`, meaning the `RecordProxy` holding your top level fields.*/
|
|
415
|
+
@send
|
|
416
|
+
external getRoot: t => RecordProxy.t = "getRoot"
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**A missing field handler, which is a way of teaching Relay more about the relations in your schema, so it can fulfill more things from the cache. Read more [in this section of the Relay docs](https://relay.dev/docs/guided-tour/reusing-cached-data/filling-in-missing-data/).
|
|
420
|
+
|
|
421
|
+
Feed a list of missing field handlers into `Environment.make` if you want to use them.*/
|
|
422
|
+
module MissingFieldHandler: {
|
|
423
|
+
@@warning("-30")
|
|
424
|
+
|
|
425
|
+
/**A missing field handler, which is a way of teaching Relay more about the relations in your schema, so it can fulfill more things from the cache. Read more [in this section of the Relay docs](https://relay.dev/docs/guided-tour/reusing-cached-data/filling-in-missing-data/).*/
|
|
426
|
+
type t
|
|
427
|
+
|
|
428
|
+
type normalizationArgumentWrapped = {kind: [#ListValue | #Literal | #ObjectValue | #Variable]}
|
|
429
|
+
|
|
430
|
+
type rec normalizationListValueArgument = {
|
|
431
|
+
name: string,
|
|
432
|
+
items: array<Js.Nullable.t<normalizationArgumentWrapped>>,
|
|
433
|
+
}
|
|
434
|
+
and normalizationLiteralArgument = {
|
|
435
|
+
name: string,
|
|
436
|
+
@as("type") type_: Js.Nullable.t<string>,
|
|
437
|
+
value: Js.Json.t,
|
|
438
|
+
}
|
|
439
|
+
and normalizationObjectValueArgument = {
|
|
440
|
+
name: string,
|
|
441
|
+
fields: Js.Nullable.t<array<normalizationArgumentWrapped>>,
|
|
442
|
+
}
|
|
443
|
+
and normalizationVariableArgument = {
|
|
444
|
+
name: string,
|
|
445
|
+
@as("type") type_: Js.Nullable.t<string>,
|
|
446
|
+
variableName: string,
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
type normalizationArgument =
|
|
450
|
+
| ListValue(normalizationListValueArgument)
|
|
451
|
+
| Literal(normalizationLiteralArgument)
|
|
452
|
+
| ObjectValue(normalizationObjectValueArgument)
|
|
453
|
+
| Variable(normalizationVariableArgument)
|
|
454
|
+
|
|
455
|
+
let unwrapNormalizationArgument: normalizationArgumentWrapped => normalizationArgument
|
|
456
|
+
|
|
457
|
+
type normalizationScalarField = {
|
|
458
|
+
alias: Js.Nullable.t<string>,
|
|
459
|
+
name: string,
|
|
460
|
+
args: Js.Nullable.t<array<normalizationArgumentWrapped>>,
|
|
461
|
+
storageKey: Js.Nullable.t<string>,
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**Make a `MissingFieldHandler.t` for scalar fields. Give this a handler function that returns `Js.null` (to indicate that data exists but is null), `Js.undefined` (to indicate data is still missing), or a scalar value (to indicate that the value exists even though it's not in the cache, and is the value you send back).*/
|
|
465
|
+
let makeScalarMissingFieldHandler: (
|
|
466
|
+
(
|
|
467
|
+
normalizationScalarField,
|
|
468
|
+
Js.Nullable.t<'record>,
|
|
469
|
+
'args,
|
|
470
|
+
ReadOnlyRecordSourceProxy.t,
|
|
471
|
+
) => 'scalarValue
|
|
472
|
+
) => t
|
|
473
|
+
|
|
474
|
+
type normalizationLinkedField = {
|
|
475
|
+
alias: Js.Nullable.t<string>,
|
|
476
|
+
name: string,
|
|
477
|
+
storageKey: Js.Nullable.t<string>,
|
|
478
|
+
args: Js.Nullable.t<array<normalizationArgument>>,
|
|
479
|
+
concreteType: Js.Nullable.t<string>,
|
|
480
|
+
plural: bool,
|
|
481
|
+
selections: array<Js.Json.t>,
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**Make a `MissingFieldHandler.t` for linked fields (other objects/records). Give this a handler function that returns `Js.null` (to indicate that the link exists but the linked record is null), `Js.undefined` (to indicate data is still missing), or a `dataId` of the record that is linked at this field.*/
|
|
485
|
+
let makeLinkedMissingFieldHandler: (
|
|
486
|
+
(
|
|
487
|
+
normalizationLinkedField,
|
|
488
|
+
Js.Nullable.t<RecordProxy.t>,
|
|
489
|
+
'args,
|
|
490
|
+
ReadOnlyRecordSourceProxy.t,
|
|
491
|
+
) => Js.Nullable.t<dataId>
|
|
492
|
+
) => t
|
|
493
|
+
|
|
494
|
+
/**Make a `MissingFieldHandler.t` for lists of linked fields (other objects/records). Give this a handler function that returns `Js.null` (to indicate that the link exists but the linked record is null), `Js.undefined` (to indicate data is still missing), or an array of `Js.Nullable.t<dataId>` where the `dataId`'s are the linked records/objects.*/
|
|
495
|
+
let makePluralLinkedMissingFieldHandler: (
|
|
496
|
+
(
|
|
497
|
+
normalizationLinkedField,
|
|
498
|
+
Js.Nullable.t<RecordProxy.t>,
|
|
499
|
+
'args,
|
|
500
|
+
ReadOnlyRecordSourceProxy.t,
|
|
501
|
+
) => Js.Nullable.t<array<Js.Nullable.t<dataId>>>
|
|
502
|
+
) => t
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**Read the Relay docs section on [ConnectionHandler](https://relay.dev/docs/en/relay-store#connectionhandler)*/
|
|
506
|
+
module ConnectionHandler: {
|
|
507
|
+
/**For a `RecordProxy`, returns the `RecordProxy` that is at the connection config provided.*/
|
|
508
|
+
@module("relay-runtime")
|
|
509
|
+
@scope("ConnectionHandler")
|
|
510
|
+
@return(nullable)
|
|
511
|
+
external getConnection: (
|
|
512
|
+
~record: RecordProxy.t,
|
|
513
|
+
~key: string,
|
|
514
|
+
~filters: arguments=?,
|
|
515
|
+
) => option<RecordProxy.t> = "getConnection"
|
|
516
|
+
|
|
517
|
+
/**Creates an edge for a particular connection.*/
|
|
518
|
+
@module("relay-runtime")
|
|
519
|
+
@scope("ConnectionHandler")
|
|
520
|
+
external createEdge: (
|
|
521
|
+
~store: RecordSourceSelectorProxy.t,
|
|
522
|
+
~connection: RecordProxy.t,
|
|
523
|
+
~node: RecordProxy.t,
|
|
524
|
+
~edgeType: string,
|
|
525
|
+
) => RecordProxy.t = "createEdge"
|
|
526
|
+
|
|
527
|
+
/**Inserts an edge into a connection _before_ the provided cursor. If no cursor is provided, it inserts the edge at the start of the connection list.*/
|
|
528
|
+
@module("relay-runtime")
|
|
529
|
+
@scope("ConnectionHandler")
|
|
530
|
+
external insertEdgeBefore: (
|
|
531
|
+
~connection: RecordProxy.t,
|
|
532
|
+
~newEdge: RecordProxy.t,
|
|
533
|
+
~cursor: string=?,
|
|
534
|
+
) => unit = "insertEdgeBefore"
|
|
535
|
+
|
|
536
|
+
/**Inserts an edge into a connection _after_ the provided cursor. If no cursor is provided, it inserts the edge at the end of the connection list.*/
|
|
537
|
+
@module("relay-runtime")
|
|
538
|
+
@scope("ConnectionHandler")
|
|
539
|
+
external insertEdgeAfter: (
|
|
540
|
+
~connection: RecordProxy.t,
|
|
541
|
+
~newEdge: RecordProxy.t,
|
|
542
|
+
~cursor: string=?,
|
|
543
|
+
) => unit = "insertEdgeAfter"
|
|
544
|
+
|
|
545
|
+
/**Deletes any edge from the connection where the node of the edge has the provided `dataId`. Please not that this _will not_ remove the actual node from the store. Use `RecordSourceSelectorProxy.delete` for that.*/
|
|
546
|
+
@module("relay-runtime")
|
|
547
|
+
@scope("ConnectionHandler")
|
|
548
|
+
external deleteNode: (~connection: RecordProxy.t, ~nodeId: dataId) => unit = "deleteNode"
|
|
549
|
+
|
|
550
|
+
/**Constructs a `dataId` targeting a specific connection at a specific parent. Note that the generated module for every fragment with a `@connection` will have a `<moduleName>.Utils.connectionKey` representing the connection key of that particular `@connection`, that you should use with this.*/
|
|
551
|
+
@module("relay-runtime")
|
|
552
|
+
@scope("ConnectionHandler")
|
|
553
|
+
external getConnectionID: (dataId, string, 'filters) => dataId = "getConnectionID"
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**The cache config provided to the network layer. Relay won't do anything in particular with these, it's up to you to use them if you want inside of your `NetworkLayer`.*/
|
|
557
|
+
type cacheConfig = {
|
|
558
|
+
force: option<bool>,
|
|
559
|
+
poll: option<int>,
|
|
560
|
+
liveConfigId: option<string>,
|
|
561
|
+
transactionId: option<string>,
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**A Relay observable, used throughout Relay for delivering data, in particular when dealing with multiple payloads like with subscriptions or multipart responses like `@stream` or `@defer`.*/
|
|
565
|
+
module Observable: {
|
|
566
|
+
/**The type representing the observable.*/
|
|
567
|
+
type t<'response>
|
|
568
|
+
|
|
569
|
+
/**This sink can be used to give the observable new data.*/
|
|
570
|
+
type sink<'response> = {
|
|
571
|
+
next: 'response => unit,
|
|
572
|
+
error: Js.Exn.t => unit,
|
|
573
|
+
complete: unit => unit,
|
|
574
|
+
closed: bool,
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**A subscription for an observable, allowing you to unsubscribe if wanted.*/
|
|
578
|
+
type subscription = {
|
|
579
|
+
unsubscribe: unit => unit,
|
|
580
|
+
closed: bool,
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**An observer of the observable.*/
|
|
584
|
+
type observer<'response>
|
|
585
|
+
|
|
586
|
+
/**Create an observer.*/
|
|
587
|
+
@obj
|
|
588
|
+
external makeObserver: (
|
|
589
|
+
~start: subscription => unit=?,
|
|
590
|
+
~next: 'response => unit=?,
|
|
591
|
+
~error: Js.Exn.t => unit=?,
|
|
592
|
+
~complete: unit => unit=?,
|
|
593
|
+
~unsubscribe: subscription => unit=?,
|
|
594
|
+
) => observer<'response> = ""
|
|
595
|
+
|
|
596
|
+
/**Create a new observable, getting fed an `Observable.sink` for interacting with the observable, and optionally returning a `Observable.subscription` if you have things you want to unsubscribe from as the observable closes.*/
|
|
597
|
+
@module("relay-runtime")
|
|
598
|
+
@scope("Observable")
|
|
599
|
+
external make: (sink<'t> => option<subscription>) => t<'t> = "create"
|
|
600
|
+
|
|
601
|
+
/**Subscribe to the `Observable.t` using an observer.*/
|
|
602
|
+
@send
|
|
603
|
+
external subscribe: (t<'t>, observer<'t>) => subscription = "subscribe"
|
|
604
|
+
|
|
605
|
+
/**Turns an `Observable` into a promise. _Beware_ that reading the response in the resulting promise is currently _not safe_ due to some internals of how ReScript Relay works. This will be resolved in the future.*/
|
|
606
|
+
@send
|
|
607
|
+
external toPromise: t<'t> => Js.Promise.t<'t> = "toPromise"
|
|
608
|
+
|
|
609
|
+
/**Ignore this subscription.*/ external ignoreSubscription: subscription => unit = "%ignore"
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/**Represents the network layer.*/
|
|
613
|
+
module Network: {
|
|
614
|
+
type codesplitsMetadata = (string, unit => unit)
|
|
615
|
+
|
|
616
|
+
type operationMetadata = {codesplits?: array<codesplitsMetadata>}
|
|
617
|
+
|
|
618
|
+
/**The type representing an instantiated `NetworkLayer`.*/
|
|
619
|
+
type t
|
|
620
|
+
|
|
621
|
+
/**The operation fed to the `NetworkLayer` when Relay wants to make a request. Please note that if you're using persisted queries, `id` will exist but `text` won't, and vice versa when not using persisted queries.*/
|
|
622
|
+
type operation = {
|
|
623
|
+
id: string,
|
|
624
|
+
text: string,
|
|
625
|
+
name: string,
|
|
626
|
+
operationKind: string,
|
|
627
|
+
metadata: Js.Nullable.t<operationMetadata>,
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/**The shape of the function Relay expects for creating a subscription.*/
|
|
631
|
+
type subscribeFn = (operation, Js.Json.t, cacheConfig) => Observable.t<Js.Json.t>
|
|
632
|
+
|
|
633
|
+
/**The shape of the function responsible for fetching data if you want to return a promise rather than an `Observable`.*/
|
|
634
|
+
type fetchFunctionPromise = (
|
|
635
|
+
operation,
|
|
636
|
+
Js.Json.t,
|
|
637
|
+
cacheConfig,
|
|
638
|
+
Js.Nullable.t<uploadables>,
|
|
639
|
+
) => Js.Promise.t<Js.Json.t>
|
|
640
|
+
|
|
641
|
+
/**The shape of the function responsible for fetching data if you want to return an `Observable`.*/
|
|
642
|
+
type fetchFunctionObservable = (
|
|
643
|
+
operation,
|
|
644
|
+
Js.Json.t,
|
|
645
|
+
cacheConfig,
|
|
646
|
+
Js.Nullable.t<uploadables>,
|
|
647
|
+
) => Observable.t<Js.Json.t>
|
|
648
|
+
|
|
649
|
+
/**Create a new `NetworkLayer` using a fetch function that returns a promise.*/
|
|
650
|
+
@module("relay-runtime")
|
|
651
|
+
@scope("Network")
|
|
652
|
+
external makePromiseBased: (
|
|
653
|
+
~fetchFunction: fetchFunctionPromise,
|
|
654
|
+
~subscriptionFunction: subscribeFn=?,
|
|
655
|
+
) => t = "create"
|
|
656
|
+
|
|
657
|
+
/**Create a new `NetworkLayer` using a fetch function that returns an `Observable`.*/
|
|
658
|
+
@module("relay-runtime")
|
|
659
|
+
@scope("Network")
|
|
660
|
+
external makeObservableBased: (
|
|
661
|
+
~observableFunction: fetchFunctionObservable,
|
|
662
|
+
~subscriptionFunction: subscribeFn=?,
|
|
663
|
+
) => t = "create"
|
|
664
|
+
|
|
665
|
+
let preloadResources: (~operation: operation, ~variables: Js.Json.t, ~response: Js.Json.t) => unit
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**RecordSource is the source of records used by the store. Can be initiated with or without prior records; eg. hydrating the store with prior data.*/
|
|
669
|
+
module RecordSource: {
|
|
670
|
+
/**The type representing an instantiated `RecordSource`.*/
|
|
671
|
+
type t
|
|
672
|
+
|
|
673
|
+
/**Create a new `RecordSource`. Here's where you pass an existing `recordSourceRecords` if you have existing records you want to hydrate the store with, when doing SSR or similar.*/
|
|
674
|
+
@module("relay-runtime")
|
|
675
|
+
@new
|
|
676
|
+
external make: (~records: recordSourceRecords=?) => t = "RecordSource"
|
|
677
|
+
|
|
678
|
+
/**Serializes the `RecordSource` into `recordSourceRecords` that you can use to rehydrate another store. Typically used for SSR.*/
|
|
679
|
+
@send
|
|
680
|
+
external toJSON: t => recordSourceRecords = "toJSON"
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**The actual store module, with configuration for the store.*/
|
|
684
|
+
module Store: {
|
|
685
|
+
/**The type representing an instantiated `Store`.*/
|
|
686
|
+
type t
|
|
687
|
+
|
|
688
|
+
/**Creates a new `Store`.*/
|
|
689
|
+
let make: (
|
|
690
|
+
~source: RecordSource.t,
|
|
691
|
+
~gcReleaseBufferSize: /* `gcReleaseBufferSize` controls how many queries are allowed to be cached by default. Increase this to increase the size of the cache. */
|
|
692
|
+
int=?,
|
|
693
|
+
~queryCacheExpirationTime: int=?,
|
|
694
|
+
) => /* `queryCacheExpirationTime` sets a TTL (time to live) for all queries. If that time passes, the data is considered stale and is evicted from the store. Default is no TTL. */
|
|
695
|
+
t
|
|
696
|
+
|
|
697
|
+
/**Creates a new `LiveStore`.*/
|
|
698
|
+
let makeLiveStore: (
|
|
699
|
+
~source: RecordSource.t,
|
|
700
|
+
~gcReleaseBufferSize: /* `gcReleaseBufferSize` controls how many queries are allowed to be cached by default. Increase this to increase the size of the cache. */
|
|
701
|
+
int=?,
|
|
702
|
+
~queryCacheExpirationTime: int=?,
|
|
703
|
+
) => /* `queryCacheExpirationTime` sets a TTL (time to live) for all queries. If that time passes, the data is considered stale and is evicted from the store. Default is no TTL. */
|
|
704
|
+
t
|
|
705
|
+
|
|
706
|
+
let _makeLiveStoreCjs: (
|
|
707
|
+
~source: RecordSource.t,
|
|
708
|
+
~gcReleaseBufferSize: int=?,
|
|
709
|
+
~queryCacheExpirationTime: int=?,
|
|
710
|
+
) => t
|
|
711
|
+
|
|
712
|
+
/**Gets the `RecordSource` for this `Store`.*/
|
|
713
|
+
@send
|
|
714
|
+
external getSource: t => RecordSource.t = "getSource"
|
|
715
|
+
|
|
716
|
+
/**Publishes _new_ records to this store. This is useful in particular with frameworks like Next.js where routes could preload data needed and then serialize that (using `RecordSource.toJSON`) and send it over the wire, but you already have a store instantiated client side. This will then allow you to publish those records into your existing store.*/
|
|
717
|
+
@send
|
|
718
|
+
external publish: (t, RecordSource.t) => unit = "publish"
|
|
719
|
+
|
|
720
|
+
/**Informes the store to stop its normal garbage collection processes. This prevents data being lost between calling relay's `fetchQuery` any serialization process (eg: toJSON)*/
|
|
721
|
+
@send
|
|
722
|
+
external holdGC: t => unit = "holdGC"
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/**Internal, do not use.*/
|
|
726
|
+
type operationDescriptor
|
|
727
|
+
|
|
728
|
+
/**A disposable is something you can use to dispose of something when you don't use/need it anymore.*/
|
|
729
|
+
module Disposable: {
|
|
730
|
+
/**The type representing a `Disposable`.*/
|
|
731
|
+
type t
|
|
732
|
+
|
|
733
|
+
/**Dispose the `Disposable`.*/
|
|
734
|
+
@send
|
|
735
|
+
external dispose: t => unit = "dispose"
|
|
736
|
+
|
|
737
|
+
/**Ignore this disposable.*/ external ignore: t => unit = "%ignore"
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**A required field logger, which gets called when a field annotated with the @required directive was missing from the response*/
|
|
741
|
+
module RelayFieldLogger: {
|
|
742
|
+
@tag("kind")
|
|
743
|
+
type arg =
|
|
744
|
+
| @as("missing_field.log") MissingFieldLog({owner: string, fieldPath: string})
|
|
745
|
+
| @as("missing_field.throw") MissingFieldThrow({owner: string, fieldPath: string})
|
|
746
|
+
| @as("relay_resolver.error")
|
|
747
|
+
RelayResolverError({
|
|
748
|
+
owner: string,
|
|
749
|
+
fieldPath: string,
|
|
750
|
+
error: Js.Exn.t,
|
|
751
|
+
})
|
|
752
|
+
|
|
753
|
+
/**A required field logger, which gets called when a field annotated with the @required directive was missing from the response*/
|
|
754
|
+
type t = arg => unit
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/**Module representing the environment, which you'll need to use and pass to various functions. Takes a few configuration options like store and network layer.*/
|
|
758
|
+
module Environment: {
|
|
759
|
+
/**The type representing an instantiated `Environment`.*/
|
|
760
|
+
type t
|
|
761
|
+
|
|
762
|
+
/**Create a new `Environment`.*/
|
|
763
|
+
let make: (
|
|
764
|
+
~network: Network.t,
|
|
765
|
+
~store: Store.t,
|
|
766
|
+
~getDataID: (
|
|
767
|
+
~nodeObj: {.."__typename": string, "id": string} as 'a,
|
|
768
|
+
~typeName: string,
|
|
769
|
+
) => string=?,
|
|
770
|
+
~treatMissingFieldsAsNull: bool=?,
|
|
771
|
+
~missingFieldHandlers: array<MissingFieldHandler.t>=?,
|
|
772
|
+
~relayFieldLogger: RelayFieldLogger.t=?,
|
|
773
|
+
~isServer: bool=?,
|
|
774
|
+
) => t
|
|
775
|
+
|
|
776
|
+
/**Get the `Store` for this `Environment`.*/
|
|
777
|
+
@send
|
|
778
|
+
external getStore: t => Store.t = "getStore"
|
|
779
|
+
|
|
780
|
+
/**Given an `operationDescriptor`, commits the corresponding payload.*/
|
|
781
|
+
@send
|
|
782
|
+
external commitPayload: (t, operationDescriptor, 'payload) => unit = "commitPayload"
|
|
783
|
+
|
|
784
|
+
/**Given an `operationDescriptor`, retains the corresponding operation so any data referenced by it isn't garbage collected.
|
|
785
|
+
You should use the generated `Query.retain` function on your queries instead of using this directly.*/
|
|
786
|
+
@send
|
|
787
|
+
external retain: (t, operationDescriptor) => Disposable.t = "retain"
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/**fetchPolicy controls how you want Relay to resolve your data.*/
|
|
791
|
+
type fetchPolicy =
|
|
792
|
+
| /** will only reuse locally cached data, and will never send a network request to fetch the query. In this case, the responsibility of fetching the query falls to the caller, but this policy could also be used to read and operate on data that is entirely local. */
|
|
793
|
+
@as("store-only")
|
|
794
|
+
StoreOnly
|
|
795
|
+
| /** (default) will reuse locally cached data, and will only send a network request if any data for the query is missing or stale. If the query is fully cached, a network request will not be made.*/
|
|
796
|
+
@as("store-or-network")
|
|
797
|
+
StoreOrNetwork
|
|
798
|
+
| /** will reuse locally cached data and will always send a network request, regardless of whether any data was missing or stale in the store. */
|
|
799
|
+
@as("store-and-network")
|
|
800
|
+
StoreAndNetwork
|
|
801
|
+
| /** will not reuse locally cached data, and will always send a network request to fetch the query, ignoring any data that might be locally cached and whether it's missing or stale. */
|
|
802
|
+
@as("network-only")
|
|
803
|
+
NetworkOnly
|
|
804
|
+
|
|
805
|
+
/**The fetch policies allowed for fetching a query outside of React's render (as in `Query.fetch`).*/
|
|
806
|
+
type fetchQueryFetchPolicy =
|
|
807
|
+
| /** will not reuse locally cached data, and will always send a network request to fetch the query, ignoring any data that might be locally cached and whether it's missing or stale. */
|
|
808
|
+
@as("network-only")
|
|
809
|
+
NetworkOnly
|
|
810
|
+
| /** (default) will reuse locally cached data, and will only send a network request if any data for the query is missing or stale. If the query is fully cached, a network request will not be made.*/
|
|
811
|
+
@as("store-or-network")
|
|
812
|
+
StoreOrNetwork
|
|
813
|
+
|
|
814
|
+
/**An error from a mutation.*/
|
|
815
|
+
type mutationError = {message: string}
|
|
816
|
+
|
|
817
|
+
/**Context provider for the Relay environment.*/
|
|
818
|
+
module Context: {
|
|
819
|
+
/**Type representing the context.*/
|
|
820
|
+
type t
|
|
821
|
+
|
|
822
|
+
/**The expected shape of the context.*/
|
|
823
|
+
type contextShape = {"environment": Environment.t}
|
|
824
|
+
|
|
825
|
+
/**The actual React context coming from Relay.*/
|
|
826
|
+
@module("react-relay")
|
|
827
|
+
external context: React.Context.t<option<contextShape>> = "ReactRelayContext"
|
|
828
|
+
|
|
829
|
+
/**The context provider you wrap your app in and pass your `Environment` for Relay to work.*/
|
|
830
|
+
module Provider: {
|
|
831
|
+
/**The React component you wrap your app in and pass your `Environment` for Relay to work.*/
|
|
832
|
+
type props<'environment, 'children> = {
|
|
833
|
+
environment: 'environment,
|
|
834
|
+
children: 'children,
|
|
835
|
+
}
|
|
836
|
+
let make: props<Environment.t, React.element> => React.element
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/**An exception saying that the environment could not be found in the context. Means you forgot to wrap your app in `<RescriptRelay.Context.Provider environment=RelayEnv.environment>`*/
|
|
841
|
+
exception EnvironmentNotFoundInContext
|
|
842
|
+
|
|
843
|
+
/**Hook for getting the current environment from context.*/
|
|
844
|
+
let useEnvironmentFromContext: unit => Environment.t
|
|
845
|
+
|
|
846
|
+
/**An exception detailing that a mutation failed.*/ exception Mutation_failed(array<mutationError>)
|
|
847
|
+
|
|
848
|
+
/**A way of committing a local update to the store.*/
|
|
849
|
+
@module("relay-runtime")
|
|
850
|
+
external commitLocalUpdate: (
|
|
851
|
+
~environment: Environment.t,
|
|
852
|
+
~updater: RecordSourceSelectorProxy.t => unit,
|
|
853
|
+
) => unit = "commitLocalUpdate"
|
|
854
|
+
|
|
855
|
+
/**Allows you to subscribe to when a record, connection, or even the store itself is invalidated, and then react to that.*/
|
|
856
|
+
@module("react-relay")
|
|
857
|
+
external useSubscribeToInvalidationState: (array<dataId>, unit => unit) => Disposable.t =
|
|
858
|
+
"useSubscribeToInvalidationState"
|
|
859
|
+
|
|
860
|
+
/**Options valid when fetching a query outside of React's render method (like when using `Query.fetch`).*/
|
|
861
|
+
type fetchQueryOptions = {
|
|
862
|
+
networkCacheConfig?: cacheConfig,
|
|
863
|
+
fetchPolicy?: fetchPolicy,
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
type loadQueryConfig = {
|
|
867
|
+
fetchKey: option<string>,
|
|
868
|
+
fetchPolicy: option<fetchPolicy>,
|
|
869
|
+
networkCacheConfig: option<cacheConfig>,
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
@module("react-relay")
|
|
873
|
+
external loadQuery: (Environment.t, queryNode<'a>, 'variables, loadQueryConfig) => 'queryResponse =
|
|
874
|
+
"loadQuery"
|
|
875
|
+
|
|
876
|
+
module type MakeLoadQueryConfig = {
|
|
877
|
+
type variables
|
|
878
|
+
type loadedQueryRef
|
|
879
|
+
type response
|
|
880
|
+
type node
|
|
881
|
+
let query: queryNode<node>
|
|
882
|
+
let convertVariables: variables => variables
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
module MakeLoadQuery: (C: MakeLoadQueryConfig) =>
|
|
886
|
+
{
|
|
887
|
+
let load: (
|
|
888
|
+
~environment: Environment.t,
|
|
889
|
+
~variables: C.variables,
|
|
890
|
+
~fetchPolicy: fetchPolicy=?,
|
|
891
|
+
~fetchKey: string=?,
|
|
892
|
+
~networkCacheConfig: cacheConfig=?,
|
|
893
|
+
) => C.loadedQueryRef
|
|
894
|
+
|
|
895
|
+
let queryRefToObservable: C.loadedQueryRef => option<Observable.t<C.response>>
|
|
896
|
+
let queryRefToPromise: C.loadedQueryRef => Js.Promise.t<Belt.Result.t<unit, unit>>
|
|
897
|
+
}
|