relay-runtime 0.0.0-main-976e6ee5 → 0.0.0-main-ec91ebca
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/experimental.js +1 -1
- package/index.js +1 -1
- package/index.js.flow +2 -0
- package/lib/index.js +1 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +1 -1
- package/lib/multi-actor-environment/MultiActorEnvironment.js +4 -3
- package/lib/mutations/RelayRecordSourceProxy.js +4 -3
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +4 -3
- package/lib/mutations/createUpdatableProxy.js +99 -12
- package/lib/mutations/readUpdatableFragment_EXPERIMENTAL.js +2 -2
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +2 -2
- package/lib/store/DataChecker.js +7 -28
- package/lib/store/RelayModernEnvironment.js +3 -3
- package/lib/store/RelayPublishQueue.js +7 -6
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +3 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +3 -2
- package/mutations/RelayRecordSourceProxy.js.flow +11 -1
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +11 -1
- package/mutations/createUpdatableProxy.js.flow +128 -8
- package/mutations/readUpdatableFragment_EXPERIMENTAL.js.flow +3 -0
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +7 -1
- package/mutations/validateMutation.js.flow +1 -1
- package/network/RelayObservable.js.flow +1 -1
- package/package.json +1 -1
- package/relay-runtime-experimental.js +2 -2
- package/relay-runtime-experimental.min.js +2 -2
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/DataChecker.js.flow +17 -30
- package/store/RelayExperimentalGraphResponseHandler.js.flow +2 -1
- package/store/RelayModernEnvironment.js.flow +2 -1
- package/store/RelayModernFragmentSpecResolver.js.flow +2 -2
- package/store/RelayModernSelector.js.flow +2 -2
- package/store/RelayPublishQueue.js.flow +11 -0
- package/store/RelayStoreTypes.js.flow +6 -5
- package/store/RelayStoreUtils.js.flow +1 -1
- package/store/StoreInspector.js.flow +4 -1
- package/store/experimental-live-resolvers/LiveResolverCache.js.flow +2 -2
package/experimental.js
CHANGED
package/index.js
CHANGED
package/index.js.flow
CHANGED
|
@@ -147,6 +147,7 @@ export type {
|
|
|
147
147
|
ReactFlightServerErrorHandler,
|
|
148
148
|
ReaderSelector,
|
|
149
149
|
ReadOnlyRecordProxy,
|
|
150
|
+
ReadOnlyRecordSourceProxy,
|
|
150
151
|
RecordProxy,
|
|
151
152
|
RecordSourceProxy,
|
|
152
153
|
RecordSourceSelectorProxy,
|
|
@@ -271,6 +272,7 @@ module.exports = {
|
|
|
271
272
|
createReaderSelector: RelayModernSelector.createReaderSelector,
|
|
272
273
|
createRequestDescriptor:
|
|
273
274
|
RelayModernOperationDescriptor.createRequestDescriptor,
|
|
275
|
+
getArgumentValues: RelayStoreUtils.getArgumentValues,
|
|
274
276
|
getDataIDsFromFragment: RelayModernSelector.getDataIDsFromFragment,
|
|
275
277
|
getDataIDsFromObject: RelayModernSelector.getDataIDsFromObject,
|
|
276
278
|
getNode: GraphQLTag.getNode,
|
package/lib/index.js
CHANGED
|
@@ -156,6 +156,7 @@ module.exports = {
|
|
|
156
156
|
createOperationDescriptor: RelayModernOperationDescriptor.createOperationDescriptor,
|
|
157
157
|
createReaderSelector: RelayModernSelector.createReaderSelector,
|
|
158
158
|
createRequestDescriptor: RelayModernOperationDescriptor.createRequestDescriptor,
|
|
159
|
+
getArgumentValues: RelayStoreUtils.getArgumentValues,
|
|
159
160
|
getDataIDsFromFragment: RelayModernSelector.getDataIDsFromFragment,
|
|
160
161
|
getDataIDsFromObject: RelayModernSelector.getDataIDsFromObject,
|
|
161
162
|
getNode: GraphQLTag.getNode,
|
|
@@ -32,7 +32,7 @@ var ActorSpecificEnvironment = /*#__PURE__*/function () {
|
|
|
32
32
|
this._operationTracker = new RelayOperationTracker();
|
|
33
33
|
this._store = config.store;
|
|
34
34
|
this._network = wrapNetworkWithLogObserver(this, config.network);
|
|
35
|
-
this._publishQueue = new RelayPublishQueue(config.store, config.handlerProvider, defaultGetDataID);
|
|
35
|
+
this._publishQueue = new RelayPublishQueue(config.store, config.handlerProvider, defaultGetDataID, config.missingFieldHandlers);
|
|
36
36
|
this._defaultRenderPolicy = config.defaultRenderPolicy; // TODO:T92305692 Remove `options` in favor of directly using `actorIdentifier` on the environment
|
|
37
37
|
|
|
38
38
|
this.options = {
|
|
@@ -34,7 +34,7 @@ var ActorSpecificEnvironment = require('./ActorSpecificEnvironment');
|
|
|
34
34
|
|
|
35
35
|
var MultiActorEnvironment = /*#__PURE__*/function () {
|
|
36
36
|
function MultiActorEnvironment(config) {
|
|
37
|
-
var _config$getDataID, _config$logFn, _config$requiredField, _config$treatMissingF, _config$isServer, _config$defaultRender;
|
|
37
|
+
var _config$getDataID, _config$logFn, _config$requiredField, _config$treatMissingF, _config$isServer, _config$missingFieldH, _config$defaultRender;
|
|
38
38
|
|
|
39
39
|
this._actorEnvironments = new Map();
|
|
40
40
|
this._operationLoader = config.operationLoader;
|
|
@@ -48,7 +48,7 @@ var MultiActorEnvironment = /*#__PURE__*/function () {
|
|
|
48
48
|
this._shouldProcessClientComponents = config.shouldProcessClientComponents;
|
|
49
49
|
this._treatMissingFieldsAsNull = (_config$treatMissingF = config.treatMissingFieldsAsNull) !== null && _config$treatMissingF !== void 0 ? _config$treatMissingF : false;
|
|
50
50
|
this._isServer = (_config$isServer = config.isServer) !== null && _config$isServer !== void 0 ? _config$isServer : false;
|
|
51
|
-
this._missingFieldHandlers = config.missingFieldHandlers;
|
|
51
|
+
this._missingFieldHandlers = (_config$missingFieldH = config.missingFieldHandlers) !== null && _config$missingFieldH !== void 0 ? _config$missingFieldH : [];
|
|
52
52
|
this._createStoreForActor = config.createStoreForActor;
|
|
53
53
|
this._reactFlightPayloadDeserializer = config.reactFlightPayloadDeserializer;
|
|
54
54
|
this._reactFlightServerErrorHandler = config.reactFlightServerErrorHandler;
|
|
@@ -77,7 +77,8 @@ var MultiActorEnvironment = /*#__PURE__*/function () {
|
|
|
77
77
|
store: this._createStoreForActor != null ? this._createStoreForActor(actorIdentifier) : new RelayModernStore(RelayRecordSource.create()),
|
|
78
78
|
network: this._createNetworkForActor(actorIdentifier),
|
|
79
79
|
handlerProvider: this._handlerProvider,
|
|
80
|
-
defaultRenderPolicy: this._defaultRenderPolicy
|
|
80
|
+
defaultRenderPolicy: this._defaultRenderPolicy,
|
|
81
|
+
missingFieldHandlers: this._missingFieldHandlers
|
|
81
82
|
});
|
|
82
83
|
|
|
83
84
|
this._actorEnvironments.set(actorIdentifier, newEnvironment);
|
|
@@ -37,13 +37,14 @@ var invariant = require('invariant');
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
var RelayRecordSourceProxy = /*#__PURE__*/function () {
|
|
40
|
-
function RelayRecordSourceProxy(mutator, getDataID, handlerProvider) {
|
|
40
|
+
function RelayRecordSourceProxy(mutator, getDataID, handlerProvider, missingFieldHandlers) {
|
|
41
41
|
this.__mutator = mutator;
|
|
42
42
|
this._handlerProvider = handlerProvider || null;
|
|
43
43
|
this._proxies = {};
|
|
44
44
|
this._getDataID = getDataID;
|
|
45
45
|
this._invalidatedStore = false;
|
|
46
46
|
this._idsMarkedForInvalidation = new Set();
|
|
47
|
+
this._missingFieldHandlers = missingFieldHandlers;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
var _proto = RelayRecordSourceProxy.prototype;
|
|
@@ -139,11 +140,11 @@ var RelayRecordSourceProxy = /*#__PURE__*/function () {
|
|
|
139
140
|
};
|
|
140
141
|
|
|
141
142
|
_proto.readUpdatableQuery_EXPERIMENTAL = function readUpdatableQuery_EXPERIMENTAL(query, variables) {
|
|
142
|
-
return _readUpdatableQuery_EXPERIMENTAL(query, variables, this);
|
|
143
|
+
return _readUpdatableQuery_EXPERIMENTAL(query, variables, this, this._missingFieldHandlers);
|
|
143
144
|
};
|
|
144
145
|
|
|
145
146
|
_proto.readUpdatableFragment_EXPERIMENTAL = function readUpdatableFragment_EXPERIMENTAL(fragment, fragmentReference) {
|
|
146
|
-
return _readUpdatableFragment_EXPERIMENTAL(fragment, fragmentReference, this);
|
|
147
|
+
return _readUpdatableFragment_EXPERIMENTAL(fragment, fragmentReference, this, this._missingFieldHandlers);
|
|
147
148
|
};
|
|
148
149
|
|
|
149
150
|
return RelayRecordSourceProxy;
|
|
@@ -32,10 +32,11 @@ var invariant = require('invariant');
|
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
var RelayRecordSourceSelectorProxy = /*#__PURE__*/function () {
|
|
35
|
-
function RelayRecordSourceSelectorProxy(mutator, recordSource, readSelector) {
|
|
35
|
+
function RelayRecordSourceSelectorProxy(mutator, recordSource, readSelector, missingFieldHandlers) {
|
|
36
36
|
this.__mutator = mutator;
|
|
37
37
|
this.__recordSource = recordSource;
|
|
38
38
|
this._readSelector = readSelector;
|
|
39
|
+
this._missingFieldHandlers = missingFieldHandlers;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
var _proto = RelayRecordSourceSelectorProxy.prototype;
|
|
@@ -99,11 +100,11 @@ var RelayRecordSourceSelectorProxy = /*#__PURE__*/function () {
|
|
|
99
100
|
};
|
|
100
101
|
|
|
101
102
|
_proto.readUpdatableQuery_EXPERIMENTAL = function readUpdatableQuery_EXPERIMENTAL(query, variables) {
|
|
102
|
-
return _readUpdatableQuery_EXPERIMENTAL(query, variables, this);
|
|
103
|
+
return _readUpdatableQuery_EXPERIMENTAL(query, variables, this, this._missingFieldHandlers);
|
|
103
104
|
};
|
|
104
105
|
|
|
105
106
|
_proto.readUpdatableFragment_EXPERIMENTAL = function readUpdatableFragment_EXPERIMENTAL(fragment, fragmentReference) {
|
|
106
|
-
return _readUpdatableFragment_EXPERIMENTAL(fragment, fragmentReference, this);
|
|
107
|
+
return _readUpdatableFragment_EXPERIMENTAL(fragment, fragmentReference, this, this._missingFieldHandlers);
|
|
107
108
|
};
|
|
108
109
|
|
|
109
110
|
return RelayRecordSourceSelectorProxy;
|
|
@@ -40,9 +40,9 @@ var _require2 = require('../util/RelayConcreteNode'),
|
|
|
40
40
|
|
|
41
41
|
var nonUpdatableKeys = ['id', '__id', '__typename', 'js'];
|
|
42
42
|
|
|
43
|
-
function createUpdatableProxy(updatableProxyRootRecord, variables, selections, recordSourceProxy) {
|
|
43
|
+
function createUpdatableProxy(updatableProxyRootRecord, variables, selections, recordSourceProxy, missingFieldHandlers) {
|
|
44
44
|
var mutableUpdatableProxy = {};
|
|
45
|
-
updateProxyFromSelections(mutableUpdatableProxy, updatableProxyRootRecord, variables, selections, recordSourceProxy);
|
|
45
|
+
updateProxyFromSelections(mutableUpdatableProxy, updatableProxyRootRecord, variables, selections, recordSourceProxy, missingFieldHandlers);
|
|
46
46
|
|
|
47
47
|
if (process.env.NODE_ENV !== "production") {
|
|
48
48
|
Object.freeze(mutableUpdatableProxy);
|
|
@@ -54,7 +54,7 @@ function createUpdatableProxy(updatableProxyRootRecord, variables, selections, r
|
|
|
54
54
|
return mutableUpdatableProxy;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function updateProxyFromSelections(mutableUpdatableProxy, updatableProxyRootRecord, variables, selections, recordSourceProxy) {
|
|
57
|
+
function updateProxyFromSelections(mutableUpdatableProxy, updatableProxyRootRecord, variables, selections, recordSourceProxy, missingFieldHandlers) {
|
|
58
58
|
var _selection$alias3;
|
|
59
59
|
|
|
60
60
|
var _iterator = (0, _createForOfIteratorHelper2["default"])(selections),
|
|
@@ -69,12 +69,12 @@ function updateProxyFromSelections(mutableUpdatableProxy, updatableProxyRootReco
|
|
|
69
69
|
if (selection.plural) {
|
|
70
70
|
Object.defineProperty(mutableUpdatableProxy, (_selection$alias = selection.alias) !== null && _selection$alias !== void 0 ? _selection$alias : selection.name, {
|
|
71
71
|
// $FlowFixMe[incompatible-call] these getters and setters have different types on purpose
|
|
72
|
-
get: createGetterForPluralLinkedField(selection, variables, updatableProxyRootRecord, recordSourceProxy),
|
|
72
|
+
get: createGetterForPluralLinkedField(selection, variables, updatableProxyRootRecord, recordSourceProxy, missingFieldHandlers),
|
|
73
73
|
set: createSetterForPluralLinkedField(selection, variables, updatableProxyRootRecord, recordSourceProxy)
|
|
74
74
|
});
|
|
75
75
|
} else {
|
|
76
76
|
Object.defineProperty(mutableUpdatableProxy, (_selection$alias2 = selection.alias) !== null && _selection$alias2 !== void 0 ? _selection$alias2 : selection.name, {
|
|
77
|
-
get: createGetterForSingularLinkedField(selection, variables, updatableProxyRootRecord, recordSourceProxy),
|
|
77
|
+
get: createGetterForSingularLinkedField(selection, variables, updatableProxyRootRecord, recordSourceProxy, missingFieldHandlers),
|
|
78
78
|
set: createSetterForSingularLinkedField(selection, variables, updatableProxyRootRecord, recordSourceProxy)
|
|
79
79
|
});
|
|
80
80
|
}
|
|
@@ -90,8 +90,14 @@ function updateProxyFromSelections(mutableUpdatableProxy, updatableProxyRootReco
|
|
|
90
90
|
var newVariables = getArgumentValues((_selection$args = selection.args) !== null && _selection$args !== void 0 ? _selection$args : [], variables); // Flow incorrect assumes that the return value for the get method must match
|
|
91
91
|
// the set parameter.
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
var value = updatableProxyRootRecord.getValue(selection.name, newVariables // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
94
94
|
);
|
|
95
|
+
|
|
96
|
+
if (value == null) {
|
|
97
|
+
value = getScalarUsingMissingFieldHandlers(selection, newVariables, updatableProxyRootRecord, recordSourceProxy, missingFieldHandlers);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return value;
|
|
95
101
|
},
|
|
96
102
|
set: nonUpdatableKeys.includes(selection.name) ? undefined : // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
97
103
|
function (newValue) {
|
|
@@ -106,13 +112,13 @@ function updateProxyFromSelections(mutableUpdatableProxy, updatableProxyRootReco
|
|
|
106
112
|
|
|
107
113
|
case INLINE_FRAGMENT:
|
|
108
114
|
if (updatableProxyRootRecord.getType() === selection.type) {
|
|
109
|
-
updateProxyFromSelections(mutableUpdatableProxy, updatableProxyRootRecord, variables, selection.selections, recordSourceProxy);
|
|
115
|
+
updateProxyFromSelections(mutableUpdatableProxy, updatableProxyRootRecord, variables, selection.selections, recordSourceProxy, missingFieldHandlers);
|
|
110
116
|
}
|
|
111
117
|
|
|
112
118
|
break;
|
|
113
119
|
|
|
114
120
|
case CLIENT_EXTENSION:
|
|
115
|
-
updateProxyFromSelections(mutableUpdatableProxy, updatableProxyRootRecord, variables, selection.selections, recordSourceProxy);
|
|
121
|
+
updateProxyFromSelections(mutableUpdatableProxy, updatableProxyRootRecord, variables, selection.selections, recordSourceProxy, missingFieldHandlers);
|
|
116
122
|
break;
|
|
117
123
|
|
|
118
124
|
case FRAGMENT_SPREAD:
|
|
@@ -215,18 +221,22 @@ function createSetterForSingularLinkedField(selection, variables, updatableProxy
|
|
|
215
221
|
};
|
|
216
222
|
}
|
|
217
223
|
|
|
218
|
-
function createGetterForPluralLinkedField(selection, variables, updatableProxyRootRecord, recordSourceProxy) {
|
|
224
|
+
function createGetterForPluralLinkedField(selection, variables, updatableProxyRootRecord, recordSourceProxy, missingFieldHandlers) {
|
|
219
225
|
return function () {
|
|
220
226
|
var _selection$args5;
|
|
221
227
|
|
|
222
228
|
var newVariables = getArgumentValues((_selection$args5 = selection.args) !== null && _selection$args5 !== void 0 ? _selection$args5 : [], variables);
|
|
223
229
|
var linkedRecords = updatableProxyRootRecord.getLinkedRecords(selection.name, newVariables);
|
|
224
230
|
|
|
231
|
+
if (linkedRecords === undefined) {
|
|
232
|
+
linkedRecords = getPluralLinkedRecordUsingMissingFieldHandlers(selection, newVariables, updatableProxyRootRecord, recordSourceProxy, missingFieldHandlers);
|
|
233
|
+
}
|
|
234
|
+
|
|
225
235
|
if (linkedRecords != null) {
|
|
226
236
|
return linkedRecords.map(function (linkedRecord) {
|
|
227
237
|
if (linkedRecord != null) {
|
|
228
238
|
var updatableProxy = {};
|
|
229
|
-
updateProxyFromSelections(updatableProxy, linkedRecord, variables, selection.selections, recordSourceProxy);
|
|
239
|
+
updateProxyFromSelections(updatableProxy, linkedRecord, variables, selection.selections, recordSourceProxy, missingFieldHandlers);
|
|
230
240
|
|
|
231
241
|
if (process.env.NODE_ENV !== "production") {
|
|
232
242
|
Object.freeze(updatableProxy);
|
|
@@ -247,16 +257,20 @@ function createGetterForPluralLinkedField(selection, variables, updatableProxyRo
|
|
|
247
257
|
};
|
|
248
258
|
}
|
|
249
259
|
|
|
250
|
-
function createGetterForSingularLinkedField(selection, variables, updatableProxyRootRecord, recordSourceProxy) {
|
|
260
|
+
function createGetterForSingularLinkedField(selection, variables, updatableProxyRootRecord, recordSourceProxy, missingFieldHandlers) {
|
|
251
261
|
return function () {
|
|
252
262
|
var _selection$args6;
|
|
253
263
|
|
|
254
264
|
var newVariables = getArgumentValues((_selection$args6 = selection.args) !== null && _selection$args6 !== void 0 ? _selection$args6 : [], variables);
|
|
255
265
|
var linkedRecord = updatableProxyRootRecord.getLinkedRecord(selection.name, newVariables);
|
|
256
266
|
|
|
267
|
+
if (linkedRecord === undefined) {
|
|
268
|
+
linkedRecord = getLinkedRecordUsingMissingFieldHandlers(selection, newVariables, updatableProxyRootRecord, recordSourceProxy, missingFieldHandlers);
|
|
269
|
+
}
|
|
270
|
+
|
|
257
271
|
if (linkedRecord != null) {
|
|
258
272
|
var updatableProxy = {};
|
|
259
|
-
updateProxyFromSelections(updatableProxy, linkedRecord, variables, selection.selections, recordSourceProxy);
|
|
273
|
+
updateProxyFromSelections(updatableProxy, linkedRecord, variables, selection.selections, recordSourceProxy, missingFieldHandlers);
|
|
260
274
|
|
|
261
275
|
if (process.env.NODE_ENV !== "production") {
|
|
262
276
|
Object.freeze(updatableProxy);
|
|
@@ -272,6 +286,79 @@ function createGetterForSingularLinkedField(selection, variables, updatableProxy
|
|
|
272
286
|
};
|
|
273
287
|
}
|
|
274
288
|
|
|
289
|
+
function getLinkedRecordUsingMissingFieldHandlers(selection, newVariables, updatableProxyRootRecord, recordSourceProxy, missingFieldHandlers) {
|
|
290
|
+
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(missingFieldHandlers),
|
|
291
|
+
_step2;
|
|
292
|
+
|
|
293
|
+
try {
|
|
294
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
295
|
+
var handler = _step2.value;
|
|
296
|
+
|
|
297
|
+
if (handler.kind === 'linked') {
|
|
298
|
+
var newId = handler.handle(selection, updatableProxyRootRecord, newVariables, recordSourceProxy);
|
|
299
|
+
|
|
300
|
+
if (newId != null) {
|
|
301
|
+
return recordSourceProxy.get(newId);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
} catch (err) {
|
|
306
|
+
_iterator2.e(err);
|
|
307
|
+
} finally {
|
|
308
|
+
_iterator2.f();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function getPluralLinkedRecordUsingMissingFieldHandlers(selection, newVariables, updatableProxyRootRecord, recordSourceProxy, missingFieldHandlers) {
|
|
313
|
+
var _iterator3 = (0, _createForOfIteratorHelper2["default"])(missingFieldHandlers),
|
|
314
|
+
_step3;
|
|
315
|
+
|
|
316
|
+
try {
|
|
317
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
318
|
+
var handler = _step3.value;
|
|
319
|
+
|
|
320
|
+
if (handler.kind === 'pluralLinked') {
|
|
321
|
+
var newIds = handler.handle(selection, updatableProxyRootRecord, newVariables, recordSourceProxy);
|
|
322
|
+
|
|
323
|
+
if (newIds != null) {
|
|
324
|
+
return newIds.map(function (newId) {
|
|
325
|
+
if (newId != null) {
|
|
326
|
+
return recordSourceProxy.get(newId);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
} catch (err) {
|
|
333
|
+
_iterator3.e(err);
|
|
334
|
+
} finally {
|
|
335
|
+
_iterator3.f();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function getScalarUsingMissingFieldHandlers(selection, newVariables, updatableProxyRootRecord, recordSourceProxy, missingFieldHandlers) {
|
|
340
|
+
var _iterator4 = (0, _createForOfIteratorHelper2["default"])(missingFieldHandlers),
|
|
341
|
+
_step4;
|
|
342
|
+
|
|
343
|
+
try {
|
|
344
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
345
|
+
var handler = _step4.value;
|
|
346
|
+
|
|
347
|
+
if (handler.kind === 'scalar') {
|
|
348
|
+
var value = handler.handle(selection, updatableProxyRootRecord, newVariables, recordSourceProxy);
|
|
349
|
+
|
|
350
|
+
if (value !== undefined) {
|
|
351
|
+
return value;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
} catch (err) {
|
|
356
|
+
_iterator4.e(err);
|
|
357
|
+
} finally {
|
|
358
|
+
_iterator4.f();
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
275
362
|
module.exports = {
|
|
276
363
|
createUpdatableProxy: createUpdatableProxy
|
|
277
364
|
};
|
|
@@ -25,7 +25,7 @@ var _require4 = require('./createUpdatableProxy'),
|
|
|
25
25
|
var invariant = require('invariant'); // Note: plural fragment references are currently not supported
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
function readUpdatableFragment_EXPERIMENTAL(fragment, fragmentReference, proxy) {
|
|
28
|
+
function readUpdatableFragment_EXPERIMENTAL(fragment, fragmentReference, proxy, missingFieldHandlers) {
|
|
29
29
|
var updatableFragment = getFragment(fragment);
|
|
30
30
|
var fragmentVariables = getVariablesFromFragment(updatableFragment, fragmentReference); // $FlowFixMe[prop-missing] it's there, we just don't include it in the type
|
|
31
31
|
|
|
@@ -33,7 +33,7 @@ function readUpdatableFragment_EXPERIMENTAL(fragment, fragmentReference, proxy)
|
|
|
33
33
|
var fragmentRoot = proxy.get(id);
|
|
34
34
|
!(fragmentRoot != null) ? process.env.NODE_ENV !== "production" ? invariant(false, "No record with ".concat(id, " was found. This likely indicates a problem with Relay.")) : invariant(false) : void 0;
|
|
35
35
|
return {
|
|
36
|
-
updatableData: createUpdatableProxy(fragmentRoot, fragmentVariables, updatableFragment.selections, proxy)
|
|
36
|
+
updatableData: createUpdatableProxy(fragmentRoot, fragmentVariables, updatableFragment.selections, proxy, missingFieldHandlers)
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -16,10 +16,10 @@ var _require = require('../query/GraphQLTag'),
|
|
|
16
16
|
var _require2 = require('./createUpdatableProxy'),
|
|
17
17
|
createUpdatableProxy = _require2.createUpdatableProxy;
|
|
18
18
|
|
|
19
|
-
function readUpdatableQuery_EXPERIMENTAL(query, variables, proxy) {
|
|
19
|
+
function readUpdatableQuery_EXPERIMENTAL(query, variables, proxy, missingFieldHandlers) {
|
|
20
20
|
var updatableQuery = getUpdatableQuery(query);
|
|
21
21
|
return {
|
|
22
|
-
updatableData: createUpdatableProxy(proxy.getRoot(), variables, updatableQuery.fragment.selections, proxy)
|
|
22
|
+
updatableData: createUpdatableProxy(proxy.getRoot(), variables, updatableQuery.fragment.selections, proxy, missingFieldHandlers)
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
|
package/lib/store/DataChecker.js
CHANGED
|
@@ -124,7 +124,7 @@ var DataChecker = /*#__PURE__*/function () {
|
|
|
124
124
|
var target = this._getTargetForActor(actorIdentifier);
|
|
125
125
|
|
|
126
126
|
var mutator = new RelayRecordSourceMutator(this._getSourceForActor(actorIdentifier), target);
|
|
127
|
-
var recordSourceProxy = new RelayRecordSourceProxy(mutator, this._getDataID);
|
|
127
|
+
var recordSourceProxy = new RelayRecordSourceProxy(mutator, this._getDataID, undefined, this._handlers);
|
|
128
128
|
tuple = [mutator, recordSourceProxy];
|
|
129
129
|
|
|
130
130
|
this._mutatorRecordSourceProxyCache.set(actorIdentifier, tuple);
|
|
@@ -156,29 +156,12 @@ var DataChecker = /*#__PURE__*/function () {
|
|
|
156
156
|
this._recordWasMissing = true;
|
|
157
157
|
};
|
|
158
158
|
|
|
159
|
-
_proto._getDataForHandlers = function _getDataForHandlers(field, dataID) {
|
|
160
|
-
return {
|
|
161
|
-
/* $FlowFixMe[class-object-subtyping] added when improving typing for
|
|
162
|
-
* this parameters */
|
|
163
|
-
args: field.args ? getArgumentValues(field.args, this._variables) : {},
|
|
164
|
-
// Getting a snapshot of the record state is potentially expensive since
|
|
165
|
-
// we will need to merge the sink and source records. Since we do not create
|
|
166
|
-
// any new records in this process, it is probably reasonable to provide
|
|
167
|
-
// handlers with a copy of the source record.
|
|
168
|
-
// The only thing that the provided record will not contain is fields
|
|
169
|
-
// added by previous handlers.
|
|
170
|
-
record: this._source.get(dataID)
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
|
|
174
159
|
_proto._handleMissingScalarField = function _handleMissingScalarField(field, dataID) {
|
|
175
160
|
if (field.name === 'id' && field.alias == null && isClientID(dataID)) {
|
|
176
161
|
return undefined;
|
|
177
162
|
}
|
|
178
163
|
|
|
179
|
-
var
|
|
180
|
-
args = _this$_getDataForHand.args,
|
|
181
|
-
record = _this$_getDataForHand.record;
|
|
164
|
+
var args = field.args != undefined ? getArgumentValues(field.args, this._variables) : {};
|
|
182
165
|
|
|
183
166
|
var _iterator = (0, _createForOfIteratorHelper2["default"])(this._handlers),
|
|
184
167
|
_step;
|
|
@@ -188,7 +171,7 @@ var DataChecker = /*#__PURE__*/function () {
|
|
|
188
171
|
var handler = _step.value;
|
|
189
172
|
|
|
190
173
|
if (handler.kind === 'scalar') {
|
|
191
|
-
var newValue = handler.handle(field,
|
|
174
|
+
var newValue = handler.handle(field, this._recordSourceProxy.get(dataID), args, this._recordSourceProxy);
|
|
192
175
|
|
|
193
176
|
if (newValue !== undefined) {
|
|
194
177
|
return newValue;
|
|
@@ -205,9 +188,7 @@ var DataChecker = /*#__PURE__*/function () {
|
|
|
205
188
|
};
|
|
206
189
|
|
|
207
190
|
_proto._handleMissingLinkField = function _handleMissingLinkField(field, dataID) {
|
|
208
|
-
var
|
|
209
|
-
args = _this$_getDataForHand2.args,
|
|
210
|
-
record = _this$_getDataForHand2.record;
|
|
191
|
+
var args = field.args != undefined ? getArgumentValues(field.args, this._variables) : {};
|
|
211
192
|
|
|
212
193
|
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(this._handlers),
|
|
213
194
|
_step2;
|
|
@@ -217,7 +198,7 @@ var DataChecker = /*#__PURE__*/function () {
|
|
|
217
198
|
var handler = _step2.value;
|
|
218
199
|
|
|
219
200
|
if (handler.kind === 'linked') {
|
|
220
|
-
var newValue = handler.handle(field,
|
|
201
|
+
var newValue = handler.handle(field, this._recordSourceProxy.get(dataID), args, this._recordSourceProxy);
|
|
221
202
|
|
|
222
203
|
if (newValue !== undefined && (newValue === null || this._mutator.getStatus(newValue) === EXISTENT)) {
|
|
223
204
|
return newValue;
|
|
@@ -236,9 +217,7 @@ var DataChecker = /*#__PURE__*/function () {
|
|
|
236
217
|
_proto._handleMissingPluralLinkField = function _handleMissingPluralLinkField(field, dataID) {
|
|
237
218
|
var _this = this;
|
|
238
219
|
|
|
239
|
-
var
|
|
240
|
-
args = _this$_getDataForHand3.args,
|
|
241
|
-
record = _this$_getDataForHand3.record;
|
|
220
|
+
var args = field.args != undefined ? getArgumentValues(field.args, this._variables) : {};
|
|
242
221
|
|
|
243
222
|
var _iterator3 = (0, _createForOfIteratorHelper2["default"])(this._handlers),
|
|
244
223
|
_step3;
|
|
@@ -248,7 +227,7 @@ var DataChecker = /*#__PURE__*/function () {
|
|
|
248
227
|
var handler = _step3.value;
|
|
249
228
|
|
|
250
229
|
if (handler.kind === 'pluralLinked') {
|
|
251
|
-
var newValue = handler.handle(field,
|
|
230
|
+
var newValue = handler.handle(field, this._recordSourceProxy.get(dataID), args, this._recordSourceProxy);
|
|
252
231
|
|
|
253
232
|
if (newValue != null) {
|
|
254
233
|
var allItemsKnown = newValue.every(function (linkedID) {
|
|
@@ -46,7 +46,7 @@ var RelayModernEnvironment = /*#__PURE__*/function () {
|
|
|
46
46
|
function RelayModernEnvironment(config) {
|
|
47
47
|
var _this = this;
|
|
48
48
|
|
|
49
|
-
var _config$log, _config$requiredField, _config$UNSTABLE_defa, _config$getDataID, _config$
|
|
49
|
+
var _config$log, _config$requiredField, _config$UNSTABLE_defa, _config$getDataID, _config$missingFieldH, _config$handlerProvid, _config$scheduler, _config$isServer, _config$operationTrac;
|
|
50
50
|
|
|
51
51
|
this.configName = config.configName;
|
|
52
52
|
this._treatMissingFieldsAsNull = config.treatMissingFieldsAsNull === true;
|
|
@@ -71,7 +71,8 @@ var RelayModernEnvironment = /*#__PURE__*/function () {
|
|
|
71
71
|
this._operationExecutions = new Map();
|
|
72
72
|
this._network = wrapNetworkWithLogObserver(this, config.network);
|
|
73
73
|
this._getDataID = (_config$getDataID = config.getDataID) !== null && _config$getDataID !== void 0 ? _config$getDataID : defaultGetDataID;
|
|
74
|
-
this.
|
|
74
|
+
this._missingFieldHandlers = (_config$missingFieldH = config.missingFieldHandlers) !== null && _config$missingFieldH !== void 0 ? _config$missingFieldH : [];
|
|
75
|
+
this._publishQueue = new RelayPublishQueue(config.store, (_config$handlerProvid = config.handlerProvider) !== null && _config$handlerProvid !== void 0 ? _config$handlerProvid : RelayDefaultHandlerProvider, this._getDataID, this._missingFieldHandlers);
|
|
75
76
|
this._scheduler = (_config$scheduler = config.scheduler) !== null && _config$scheduler !== void 0 ? _config$scheduler : null;
|
|
76
77
|
this._store = config.store;
|
|
77
78
|
this.options = config.options;
|
|
@@ -90,7 +91,6 @@ var RelayModernEnvironment = /*#__PURE__*/function () {
|
|
|
90
91
|
};
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
this._missingFieldHandlers = (_config$missingFieldH = config.missingFieldHandlers) !== null && _config$missingFieldH !== void 0 ? _config$missingFieldH : [];
|
|
94
94
|
this._operationTracker = (_config$operationTrac = config.operationTracker) !== null && _config$operationTrac !== void 0 ? _config$operationTrac : new RelayOperationTracker();
|
|
95
95
|
this._reactFlightPayloadDeserializer = reactFlightPayloadDeserializer;
|
|
96
96
|
this._reactFlightServerErrorHandler = reactFlightServerErrorHandler;
|
|
@@ -57,7 +57,7 @@ var RelayPublishQueue = /*#__PURE__*/function () {
|
|
|
57
57
|
// we want to parametrize by "any" since the type is effectively
|
|
58
58
|
// "the union of all T's that PublishQueue's methods were called with".
|
|
59
59
|
// Garbage collection hold, should rerun gc on dispose
|
|
60
|
-
function RelayPublishQueue(store, handlerProvider, getDataID) {
|
|
60
|
+
function RelayPublishQueue(store, handlerProvider, getDataID, missingFieldHandlers) {
|
|
61
61
|
this._hasStoreSnapshot = false;
|
|
62
62
|
this._handlerProvider = handlerProvider || null;
|
|
63
63
|
this._pendingBackupRebase = false;
|
|
@@ -67,6 +67,7 @@ var RelayPublishQueue = /*#__PURE__*/function () {
|
|
|
67
67
|
this._appliedOptimisticUpdates = new Set();
|
|
68
68
|
this._gcHold = null;
|
|
69
69
|
this._getDataID = getDataID;
|
|
70
|
+
this._missingFieldHandlers = missingFieldHandlers;
|
|
70
71
|
}
|
|
71
72
|
/**
|
|
72
73
|
* Schedule applying an optimistic updates on the next `run()`.
|
|
@@ -232,7 +233,7 @@ var RelayPublishQueue = /*#__PURE__*/function () {
|
|
|
232
233
|
var source = payload.source,
|
|
233
234
|
fieldPayloads = payload.fieldPayloads;
|
|
234
235
|
var mutator = new RelayRecordSourceMutator(this._store.getSource(), source);
|
|
235
|
-
var recordSourceProxy = new RelayRecordSourceProxy(mutator, this._getDataID);
|
|
236
|
+
var recordSourceProxy = new RelayRecordSourceProxy(mutator, this._getDataID, this._handlerProvider, this._missingFieldHandlers);
|
|
236
237
|
|
|
237
238
|
if (fieldPayloads && fieldPayloads.length) {
|
|
238
239
|
fieldPayloads.forEach(function (fieldPayload) {
|
|
@@ -246,7 +247,7 @@ var RelayPublishQueue = /*#__PURE__*/function () {
|
|
|
246
247
|
if (updater) {
|
|
247
248
|
var selector = operation.fragment;
|
|
248
249
|
!(selector != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected a selector to be provided with updater function.') : invariant(false) : void 0;
|
|
249
|
-
var recordSourceSelectorProxy = new RelayRecordSourceSelectorProxy(mutator, recordSourceProxy, selector);
|
|
250
|
+
var recordSourceSelectorProxy = new RelayRecordSourceSelectorProxy(mutator, recordSourceProxy, selector, this._missingFieldHandlers);
|
|
250
251
|
var selectorData = lookupSelector(source, selector);
|
|
251
252
|
updater(recordSourceSelectorProxy, selectorData);
|
|
252
253
|
}
|
|
@@ -285,7 +286,7 @@ var RelayPublishQueue = /*#__PURE__*/function () {
|
|
|
285
286
|
var updater = data.updater;
|
|
286
287
|
var sink = RelayRecordSource.create();
|
|
287
288
|
var mutator = new RelayRecordSourceMutator(_this2._store.getSource(), sink);
|
|
288
|
-
var recordSourceProxy = new RelayRecordSourceProxy(mutator, _this2._getDataID);
|
|
289
|
+
var recordSourceProxy = new RelayRecordSourceProxy(mutator, _this2._getDataID, _this2._handlerProvider, _this2._missingFieldHandlers);
|
|
289
290
|
applyWithGuard(updater, null, [recordSourceProxy], null, 'RelayPublishQueue:commitData');
|
|
290
291
|
invalidatedStore = invalidatedStore || recordSourceProxy.isStoreMarkedForInvalidation();
|
|
291
292
|
var idsMarkedForInvalidation = recordSourceProxy.getIDsMarkedForInvalidation();
|
|
@@ -310,7 +311,7 @@ var RelayPublishQueue = /*#__PURE__*/function () {
|
|
|
310
311
|
|
|
311
312
|
var sink = RelayRecordSource.create();
|
|
312
313
|
var mutator = new RelayRecordSourceMutator(this._store.getSource(), sink);
|
|
313
|
-
var recordSourceProxy = new RelayRecordSourceProxy(mutator, this._getDataID, this._handlerProvider); // $FlowFixMe[unclear-type] see explanation above.
|
|
314
|
+
var recordSourceProxy = new RelayRecordSourceProxy(mutator, this._getDataID, this._handlerProvider, this._missingFieldHandlers); // $FlowFixMe[unclear-type] see explanation above.
|
|
314
315
|
|
|
315
316
|
var processUpdate = function processUpdate(optimisticUpdate) {
|
|
316
317
|
if (optimisticUpdate.storeUpdater) {
|
|
@@ -334,7 +335,7 @@ var RelayPublishQueue = /*#__PURE__*/function () {
|
|
|
334
335
|
selectorData = lookupSelector(source, operation.fragment);
|
|
335
336
|
}
|
|
336
337
|
|
|
337
|
-
var recordSourceSelectorProxy = new RelayRecordSourceSelectorProxy(mutator, recordSourceProxy, operation.fragment);
|
|
338
|
+
var recordSourceSelectorProxy = new RelayRecordSourceSelectorProxy(mutator, recordSourceProxy, operation.fragment, _this3._missingFieldHandlers);
|
|
338
339
|
applyWithGuard(updater, null, [recordSourceSelectorProxy, selectorData], null, 'RelayPublishQueue:applyUpdates');
|
|
339
340
|
}
|
|
340
341
|
}
|
|
@@ -17,6 +17,7 @@ import type {INetwork} from '../network/RelayNetworkTypes';
|
|
|
17
17
|
import type RelayObservable from '../network/RelayObservable';
|
|
18
18
|
import type {
|
|
19
19
|
ExecuteMutationConfig,
|
|
20
|
+
MissingFieldHandler,
|
|
20
21
|
LogFunction,
|
|
21
22
|
MutationParameters,
|
|
22
23
|
OperationAvailability,
|
|
@@ -54,6 +55,7 @@ export type ActorSpecificEnvironmentConfig = $ReadOnly<{
|
|
|
54
55
|
network: INetwork,
|
|
55
56
|
requiredFieldLogger: RequiredFieldLogger,
|
|
56
57
|
store: Store,
|
|
58
|
+
missingFieldHandlers: $ReadOnlyArray<MissingFieldHandler>,
|
|
57
59
|
}>;
|
|
58
60
|
|
|
59
61
|
class ActorSpecificEnvironment implements IActorEnvironment {
|
|
@@ -83,6 +85,7 @@ class ActorSpecificEnvironment implements IActorEnvironment {
|
|
|
83
85
|
config.store,
|
|
84
86
|
config.handlerProvider,
|
|
85
87
|
defaultGetDataID,
|
|
88
|
+
config.missingFieldHandlers,
|
|
86
89
|
);
|
|
87
90
|
this._defaultRenderPolicy = config.defaultRenderPolicy;
|
|
88
91
|
// TODO:T92305692 Remove `options` in favor of directly using `actorIdentifier` on the environment
|
|
@@ -83,7 +83,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
83
83
|
+_handlerProvider: HandlerProvider;
|
|
84
84
|
+_isServer: boolean;
|
|
85
85
|
+_logFn: LogFunction;
|
|
86
|
-
+_missingFieldHandlers:
|
|
86
|
+
+_missingFieldHandlers: $ReadOnlyArray<MissingFieldHandler>;
|
|
87
87
|
+_operationExecutions: Map<string, ActiveState>;
|
|
88
88
|
+_operationLoader: ?OperationLoader;
|
|
89
89
|
+_reactFlightPayloadDeserializer: ?ReactFlightPayloadDeserializer;
|
|
@@ -109,7 +109,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
109
109
|
this._shouldProcessClientComponents = config.shouldProcessClientComponents;
|
|
110
110
|
this._treatMissingFieldsAsNull = config.treatMissingFieldsAsNull ?? false;
|
|
111
111
|
this._isServer = config.isServer ?? false;
|
|
112
|
-
this._missingFieldHandlers = config.missingFieldHandlers;
|
|
112
|
+
this._missingFieldHandlers = config.missingFieldHandlers ?? [];
|
|
113
113
|
this._createStoreForActor = config.createStoreForActor;
|
|
114
114
|
this._reactFlightPayloadDeserializer =
|
|
115
115
|
config.reactFlightPayloadDeserializer;
|
|
@@ -141,6 +141,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
141
141
|
network: this._createNetworkForActor(actorIdentifier),
|
|
142
142
|
handlerProvider: this._handlerProvider,
|
|
143
143
|
defaultRenderPolicy: this._defaultRenderPolicy,
|
|
144
|
+
missingFieldHandlers: this._missingFieldHandlers,
|
|
144
145
|
});
|
|
145
146
|
this._actorEnvironments.set(actorIdentifier, newEnvironment);
|
|
146
147
|
return newEnvironment;
|
|
@@ -22,6 +22,7 @@ import type {
|
|
|
22
22
|
RecordSource,
|
|
23
23
|
RecordSourceProxy,
|
|
24
24
|
UpdatableData,
|
|
25
|
+
MissingFieldHandler,
|
|
25
26
|
} from '../store/RelayStoreTypes';
|
|
26
27
|
import type {
|
|
27
28
|
DataID,
|
|
@@ -55,11 +56,13 @@ class RelayRecordSourceProxy implements RecordSourceProxy {
|
|
|
55
56
|
_getDataID: GetDataID;
|
|
56
57
|
_invalidatedStore: boolean;
|
|
57
58
|
_idsMarkedForInvalidation: DataIDSet;
|
|
59
|
+
_missingFieldHandlers: $ReadOnlyArray<MissingFieldHandler>;
|
|
58
60
|
|
|
59
61
|
constructor(
|
|
60
62
|
mutator: RelayRecordSourceMutator,
|
|
61
63
|
getDataID: GetDataID,
|
|
62
64
|
handlerProvider?: ?HandlerProvider,
|
|
65
|
+
missingFieldHandlers: $ReadOnlyArray<MissingFieldHandler>,
|
|
63
66
|
) {
|
|
64
67
|
this.__mutator = mutator;
|
|
65
68
|
this._handlerProvider = handlerProvider || null;
|
|
@@ -67,6 +70,7 @@ class RelayRecordSourceProxy implements RecordSourceProxy {
|
|
|
67
70
|
this._getDataID = getDataID;
|
|
68
71
|
this._invalidatedStore = false;
|
|
69
72
|
this._idsMarkedForInvalidation = new Set();
|
|
73
|
+
this._missingFieldHandlers = missingFieldHandlers;
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
publishSource(
|
|
@@ -176,7 +180,12 @@ class RelayRecordSourceProxy implements RecordSourceProxy {
|
|
|
176
180
|
query: UpdatableQuery<TVariables, TData>,
|
|
177
181
|
variables: TVariables,
|
|
178
182
|
): UpdatableData<TData> {
|
|
179
|
-
return readUpdatableQuery_EXPERIMENTAL(
|
|
183
|
+
return readUpdatableQuery_EXPERIMENTAL(
|
|
184
|
+
query,
|
|
185
|
+
variables,
|
|
186
|
+
this,
|
|
187
|
+
this._missingFieldHandlers,
|
|
188
|
+
);
|
|
180
189
|
}
|
|
181
190
|
|
|
182
191
|
readUpdatableFragment_EXPERIMENTAL<TFragmentType: FragmentType, TData>(
|
|
@@ -187,6 +196,7 @@ class RelayRecordSourceProxy implements RecordSourceProxy {
|
|
|
187
196
|
fragment,
|
|
188
197
|
fragmentReference,
|
|
189
198
|
this,
|
|
199
|
+
this._missingFieldHandlers,
|
|
190
200
|
);
|
|
191
201
|
}
|
|
192
202
|
}
|