react-relay 2.0.0-rc.2 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +2 -2
- package/lib/ReactRelayContext.js +6 -3
- package/lib/ReactRelayFragmentContainer.js +48 -46
- package/lib/ReactRelayFragmentMockRenderer.js +5 -1
- package/lib/ReactRelayPaginationContainer.js +102 -68
- package/lib/ReactRelayQueryFetcher.js +54 -28
- package/lib/ReactRelayQueryRenderer.js +28 -20
- package/lib/ReactRelayRefetchContainer.js +70 -58
- package/lib/ReactRelayTestMocker.js +56 -43
- package/lib/ReactRelayTypes.js +1 -1
- package/lib/RelayContext.js +8 -2
- package/lib/assertFragmentMap.js +9 -7
- package/lib/buildReactRelayContainer.js +32 -23
- package/lib/index.js +41 -0
- package/lib/isRelayEnvironment.js +1 -1
- package/lib/isRelayVariables.js +1 -1
- package/lib/readContext.js +7 -4
- package/package.json +4 -4
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/classic.js +0 -10
- package/compat.js +0 -10
- package/lib/ConcreteQuery.js +0 -10
- package/lib/GraphQLQueryRunner.js +0 -264
- package/lib/GraphQLRange.js +0 -1124
- package/lib/GraphQLSegment.js +0 -743
- package/lib/GraphQLStoreChangeEmitter.js +0 -141
- package/lib/GraphQLStoreQueryResolver.js +0 -288
- package/lib/GraphQLStoreRangeUtils.js +0 -126
- package/lib/QueryBuilder.js +0 -228
- package/lib/ReactRelayClassicExports.js +0 -29
- package/lib/ReactRelayCompatContainerBuilder.js +0 -175
- package/lib/ReactRelayCompatPublic.js +0 -28
- package/lib/ReactRelayContainerProfiler.js +0 -30
- package/lib/ReactRelayFragmentContainer-flowtest.js +0 -201
- package/lib/ReactRelayPaginationContainer-flowtest.js +0 -213
- package/lib/ReactRelayPublic.js +0 -29
- package/lib/ReactRelayRefetchContainer-flowtest.js +0 -191
- package/lib/RelayCacheProcessor.js +0 -196
- package/lib/RelayChangeTracker.js +0 -83
- package/lib/RelayClassicContainerUtils.js +0 -49
- package/lib/RelayClassicCore.js +0 -34
- package/lib/RelayClassicRecordState.js +0 -31
- package/lib/RelayCompatContainer.js +0 -25
- package/lib/RelayCompatEnvironment.js +0 -27
- package/lib/RelayCompatMutations.js +0 -133
- package/lib/RelayCompatPaginationContainer.js +0 -27
- package/lib/RelayCompatRefetchContainer.js +0 -27
- package/lib/RelayCompatTypes.js +0 -10
- package/lib/RelayContainer.js +0 -889
- package/lib/RelayContainerComparators.js +0 -75
- package/lib/RelayContainerProxy.js +0 -21
- package/lib/RelayDefaultNetworkLayer.js +0 -192
- package/lib/RelayEnvironment.js +0 -449
- package/lib/RelayEnvironmentTypes.js +0 -10
- package/lib/RelayFetchMode.js +0 -17
- package/lib/RelayFragmentPointer.js +0 -161
- package/lib/RelayFragmentReference.js +0 -249
- package/lib/RelayFragmentSpecResolver.js +0 -305
- package/lib/RelayGraphQLMutation.js +0 -288
- package/lib/RelayGraphQLTag.js +0 -42
- package/lib/RelayInternalTypes.js +0 -15
- package/lib/RelayInternals.js +0 -24
- package/lib/RelayMetaRoute.js +0 -35
- package/lib/RelayMockRenderer.js +0 -71
- package/lib/RelayModern-flowtest.js +0 -342
- package/lib/RelayModernFlowtest_badref.graphql.js +0 -10
- package/lib/RelayModernFlowtest_notref.graphql.js +0 -10
- package/lib/RelayModernFlowtest_user.graphql.js +0 -10
- package/lib/RelayModernFlowtest_users.graphql.js +0 -10
- package/lib/RelayMutation.js +0 -322
- package/lib/RelayMutationDebugPrinter.js +0 -47
- package/lib/RelayMutationQuery.js +0 -558
- package/lib/RelayMutationQueue.js +0 -530
- package/lib/RelayMutationRequest.js +0 -103
- package/lib/RelayMutationTracker.js +0 -113
- package/lib/RelayMutationTransaction.js +0 -92
- package/lib/RelayMutationTransactionStatus.js +0 -55
- package/lib/RelayNetworkDebug.js +0 -131
- package/lib/RelayNetworkLayer.js +0 -185
- package/lib/RelayNodeInterface.js +0 -104
- package/lib/RelayOperationDescriptor.js +0 -40
- package/lib/RelayOptimisticMutationUtils.js +0 -208
- package/lib/RelayPendingQueryTracker.js +0 -166
- package/lib/RelayPropTypes.js +0 -57
- package/lib/RelayPublic.js +0 -44
- package/lib/RelayQL.js +0 -128
- package/lib/RelayQuery.js +0 -1584
- package/lib/RelayQueryCaching.js +0 -33
- package/lib/RelayQueryConfig.js +0 -58
- package/lib/RelayQueryPath.js +0 -204
- package/lib/RelayQueryRequest.js +0 -103
- package/lib/RelayQueryTracker.js +0 -86
- package/lib/RelayQueryTransform.js +0 -91
- package/lib/RelayQueryVisitor.js +0 -93
- package/lib/RelayQueryWriter.js +0 -573
- package/lib/RelayReadyState.js +0 -83
- package/lib/RelayReadyStateRenderer.js +0 -145
- package/lib/RelayRecord.js +0 -75
- package/lib/RelayRecordStatusMap.js +0 -57
- package/lib/RelayRecordStore.js +0 -433
- package/lib/RelayRecordWriter.js +0 -601
- package/lib/RelayRefQueryDescriptor.js +0 -27
- package/lib/RelayRenderer.js +0 -268
- package/lib/RelayRootContainer.js +0 -125
- package/lib/RelayRoute.js +0 -92
- package/lib/RelayRouteFragment.js +0 -44
- package/lib/RelaySelector.js +0 -201
- package/lib/RelayShallowMock.js +0 -69
- package/lib/RelayStaticContainer.js +0 -38
- package/lib/RelayStore.js +0 -12
- package/lib/RelayStoreConstants.js +0 -20
- package/lib/RelayStoreData.js +0 -660
- package/lib/RelayTaskQueue.js +0 -189
- package/lib/RelayTypes.js +0 -13
- package/lib/RelayVariable.js +0 -32
- package/lib/RelayVariables.js +0 -92
- package/lib/buildRQL.js +0 -160
- package/lib/callsFromGraphQL.js +0 -74
- package/lib/callsToGraphQL.js +0 -34
- package/lib/checkRelayQueryData.js +0 -250
- package/lib/createRelayQuery.js +0 -17
- package/lib/dedent.js +0 -49
- package/lib/diffRelayQuery.js +0 -757
- package/lib/directivesToGraphQL.js +0 -39
- package/lib/filterRelayQuery.js +0 -29
- package/lib/findRelayQueryLeaves.js +0 -293
- package/lib/flattenRelayQuery.js +0 -121
- package/lib/flattenSplitRelayQueries.js +0 -44
- package/lib/forEachRootCallArg.js +0 -40
- package/lib/fromGraphQL.js +0 -48
- package/lib/generateClientEdgeID.js +0 -22
- package/lib/generateClientID.js +0 -27
- package/lib/generateConcreteFragmentID.js +0 -30
- package/lib/generateForceIndex.js +0 -24
- package/lib/generateRQLFieldAlias.js +0 -39
- package/lib/getRangeBehavior.js +0 -58
- package/lib/getRelayQueries.js +0 -83
- package/lib/intersectRelayQuery.js +0 -149
- package/lib/isClassicRelayContext.js +0 -20
- package/lib/isClassicRelayEnvironment.js +0 -20
- package/lib/isCompatibleRelayFragmentType.js +0 -27
- package/lib/isRelayContainer.js +0 -16
- package/lib/makeLegacyStringishComponentRef.js +0 -52
- package/lib/printRelayOSSQuery.js +0 -329
- package/lib/printRelayQuery.js +0 -26
- package/lib/rangeOperationToMetadataKey.js +0 -25
- package/lib/readRelayQueryData.js +0 -551
- package/lib/relayUnstableBatchedUpdates.js +0 -12
- package/lib/relayUnstableBatchedUpdates.native.js +0 -11
- package/lib/restoreRelayCacheData.js +0 -188
- package/lib/serializeRelayQueryCall.js +0 -42
- package/lib/splitDeferredRelayQueries.js +0 -298
- package/lib/stableStringify.js +0 -85
- package/lib/testEditDistance.js +0 -112
- package/lib/throwFailedPromise.js +0 -26
- package/lib/toGraphQL.js +0 -94
- package/lib/transformRelayQueryPayload.js +0 -145
- package/lib/validateMutationConfig.js +0 -117
- package/lib/validateRelayReadQuery.js +0 -112
- package/lib/writeRelayQueryPayload.js +0 -44
- package/lib/writeRelayUpdatePayload.js +0 -513
- package/react-relay-classic.js +0 -4
- package/react-relay-classic.min.js +0 -9
- package/react-relay-compat.js +0 -4
- package/react-relay-compat.min.js +0 -9
package/lib/RelayStoreData.js
DELETED
@@ -1,660 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
var _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
|
13
|
-
|
14
|
-
var idField = require("./RelayQuery").Field.build({
|
15
|
-
fieldName: require("./RelayNodeInterface").ID,
|
16
|
-
type: 'String'
|
17
|
-
});
|
18
|
-
|
19
|
-
var typeField = require("./RelayQuery").Field.build({
|
20
|
-
fieldName: require("./RelayNodeInterface").TYPENAME,
|
21
|
-
type: 'String'
|
22
|
-
});
|
23
|
-
/**
|
24
|
-
* @internal
|
25
|
-
*
|
26
|
-
* Wraps the data caches and associated metadata tracking objects used by
|
27
|
-
* GraphQLStore/RelayStore.
|
28
|
-
*/
|
29
|
-
|
30
|
-
|
31
|
-
var RelayStoreData =
|
32
|
-
/*#__PURE__*/
|
33
|
-
function () {
|
34
|
-
function RelayStoreData() {
|
35
|
-
var cachedRecords = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
36
|
-
var cachedRootCallMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
37
|
-
var queuedRecords = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
38
|
-
var records = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
39
|
-
var rootCallMap = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
40
|
-
var nodeRangeMap = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
41
|
-
var rangeData = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new (require("./GraphQLStoreRangeUtils"))();
|
42
|
-
this._cacheManager = null;
|
43
|
-
this._cachedRecords = cachedRecords;
|
44
|
-
this._cachedRootCallMap = cachedRootCallMap;
|
45
|
-
this._cachedStore = new (require("./RelayRecordStore"))({
|
46
|
-
cachedRecords: cachedRecords,
|
47
|
-
records: records
|
48
|
-
}, {
|
49
|
-
cachedRootCallMap: cachedRootCallMap,
|
50
|
-
rootCallMap: rootCallMap
|
51
|
-
}, nodeRangeMap);
|
52
|
-
this._changeEmitter = new (require("./GraphQLStoreChangeEmitter"))(rangeData);
|
53
|
-
this._mutationQueue = new (require("./RelayMutationQueue"))(this);
|
54
|
-
this._networkLayer = new (require("./RelayNetworkLayer"))();
|
55
|
-
this._nodeRangeMap = nodeRangeMap;
|
56
|
-
this._pendingQueryTracker = new (require("./RelayPendingQueryTracker"))(this);
|
57
|
-
this._queryRunner = new (require("./GraphQLQueryRunner"))(this);
|
58
|
-
this._queryTracker = new (require("./RelayQueryTracker"))();
|
59
|
-
this._queuedRecords = queuedRecords;
|
60
|
-
this._queuedStore = new (require("./RelayRecordStore"))({
|
61
|
-
cachedRecords: cachedRecords,
|
62
|
-
queuedRecords: queuedRecords,
|
63
|
-
records: records
|
64
|
-
}, {
|
65
|
-
cachedRootCallMap: cachedRootCallMap,
|
66
|
-
rootCallMap: rootCallMap
|
67
|
-
}, nodeRangeMap);
|
68
|
-
this._records = records;
|
69
|
-
this._recordStore = new (require("./RelayRecordStore"))({
|
70
|
-
records: records
|
71
|
-
}, {
|
72
|
-
rootCallMap: rootCallMap
|
73
|
-
}, nodeRangeMap);
|
74
|
-
this._rangeData = rangeData;
|
75
|
-
this._rootCallMap = rootCallMap;
|
76
|
-
this._taskQueue = new (require("./RelayTaskQueue"))();
|
77
|
-
}
|
78
|
-
/**
|
79
|
-
* @internal
|
80
|
-
*
|
81
|
-
* Sets/clears the query tracker.
|
82
|
-
*
|
83
|
-
* @warning Do not use this unless your application uses only
|
84
|
-
* `RelayGraphQLMutation` for mutations.
|
85
|
-
*/
|
86
|
-
|
87
|
-
|
88
|
-
var _proto = RelayStoreData.prototype;
|
89
|
-
|
90
|
-
_proto.injectQueryTracker = function injectQueryTracker(queryTracker) {
|
91
|
-
this._queryTracker = queryTracker;
|
92
|
-
};
|
93
|
-
/**
|
94
|
-
* Sets/clears the scheduling function used by the internal task queue to
|
95
|
-
* schedule units of work for execution.
|
96
|
-
*/
|
97
|
-
|
98
|
-
|
99
|
-
_proto.injectTaskScheduler = function injectTaskScheduler(scheduler) {
|
100
|
-
this._taskQueue.injectScheduler(scheduler);
|
101
|
-
};
|
102
|
-
/**
|
103
|
-
* Sets/clears the cache manager that is used to cache changes written to
|
104
|
-
* the store.
|
105
|
-
*/
|
106
|
-
|
107
|
-
|
108
|
-
_proto.injectCacheManager = function injectCacheManager(cacheManager) {
|
109
|
-
this._cacheManager = cacheManager;
|
110
|
-
};
|
111
|
-
|
112
|
-
_proto.clearCacheManager = function clearCacheManager() {
|
113
|
-
this._cacheManager = null;
|
114
|
-
};
|
115
|
-
|
116
|
-
_proto.hasCacheManager = function hasCacheManager() {
|
117
|
-
return !!this._cacheManager;
|
118
|
-
};
|
119
|
-
|
120
|
-
_proto.getCacheManager = function getCacheManager() {
|
121
|
-
return this._cacheManager;
|
122
|
-
};
|
123
|
-
/**
|
124
|
-
* Returns whether a given record is affected by an optimistic update.
|
125
|
-
*/
|
126
|
-
|
127
|
-
|
128
|
-
_proto.hasOptimisticUpdate = function hasOptimisticUpdate(dataID) {
|
129
|
-
dataID = this.getRangeData().getCanonicalClientID(dataID);
|
130
|
-
return this.getQueuedStore().hasOptimisticUpdate(dataID);
|
131
|
-
};
|
132
|
-
/**
|
133
|
-
* Returns a list of client mutation IDs for queued mutations whose optimistic
|
134
|
-
* updates are affecting the record corresponding the given dataID. Returns
|
135
|
-
* null if the record isn't affected by any optimistic updates.
|
136
|
-
*/
|
137
|
-
|
138
|
-
|
139
|
-
_proto.getClientMutationIDs = function getClientMutationIDs(dataID) {
|
140
|
-
dataID = this.getRangeData().getCanonicalClientID(dataID);
|
141
|
-
return this.getQueuedStore().getClientMutationIDs(dataID);
|
142
|
-
};
|
143
|
-
/**
|
144
|
-
* Restores data for queries incrementally from cache.
|
145
|
-
* It calls onSuccess when all the data has been loaded into memory.
|
146
|
-
* It calls onFailure when some data is unabled to be satisfied from cache.
|
147
|
-
*/
|
148
|
-
|
149
|
-
|
150
|
-
_proto.restoreQueriesFromCache = function restoreQueriesFromCache(queries, callbacks) {
|
151
|
-
var _this = this;
|
152
|
-
|
153
|
-
var cacheManager = this._cacheManager;
|
154
|
-
!cacheManager ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayStoreData: `restoreQueriesFromCache` should only be called ' + 'when cache manager is available.') : require("fbjs/lib/invariant")(false) : void 0;
|
155
|
-
var changeTracker = new (require("./RelayChangeTracker"))();
|
156
|
-
|
157
|
-
var profile = require("relay-runtime").RelayProfiler.profile('RelayStoreData.readFromDiskCache');
|
158
|
-
|
159
|
-
return require("./restoreRelayCacheData").restoreQueriesDataFromCache(queries, this._queuedStore, this._cachedRecords, this._cachedRootCallMap, cacheManager, changeTracker, {
|
160
|
-
onSuccess: function onSuccess() {
|
161
|
-
_this._handleChangedAndNewDataIDs(changeTracker.getChangeSet());
|
162
|
-
|
163
|
-
profile.stop();
|
164
|
-
callbacks.onSuccess && callbacks.onSuccess();
|
165
|
-
},
|
166
|
-
onFailure: function onFailure() {
|
167
|
-
_this._handleChangedAndNewDataIDs(changeTracker.getChangeSet());
|
168
|
-
|
169
|
-
profile.stop();
|
170
|
-
callbacks.onFailure && callbacks.onFailure();
|
171
|
-
}
|
172
|
-
});
|
173
|
-
};
|
174
|
-
/**
|
175
|
-
* Restores data for a fragment incrementally from cache.
|
176
|
-
* It calls onSuccess when all the data has been loaded into memory.
|
177
|
-
* It calls onFailure when some data is unabled to be satisfied from cache.
|
178
|
-
*/
|
179
|
-
|
180
|
-
|
181
|
-
_proto.restoreFragmentFromCache = function restoreFragmentFromCache(dataID, fragment, path, callbacks) {
|
182
|
-
var _this2 = this;
|
183
|
-
|
184
|
-
var cacheManager = this._cacheManager;
|
185
|
-
!cacheManager ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayStoreData: `restoreFragmentFromCache` should only be called when ' + 'cache manager is available.') : require("fbjs/lib/invariant")(false) : void 0;
|
186
|
-
var changeTracker = new (require("./RelayChangeTracker"))();
|
187
|
-
|
188
|
-
var profile = require("relay-runtime").RelayProfiler.profile('RelayStoreData.readFragmentFromDiskCache');
|
189
|
-
|
190
|
-
return require("./restoreRelayCacheData").restoreFragmentDataFromCache(dataID, fragment, path, this._queuedStore, this._cachedRecords, this._cachedRootCallMap, cacheManager, changeTracker, {
|
191
|
-
onSuccess: function onSuccess() {
|
192
|
-
_this2._handleChangedAndNewDataIDs(changeTracker.getChangeSet());
|
193
|
-
|
194
|
-
profile.stop();
|
195
|
-
callbacks.onSuccess && callbacks.onSuccess();
|
196
|
-
},
|
197
|
-
onFailure: function onFailure() {
|
198
|
-
_this2._handleChangedAndNewDataIDs(changeTracker.getChangeSet());
|
199
|
-
|
200
|
-
profile.stop();
|
201
|
-
callbacks.onFailure && callbacks.onFailure();
|
202
|
-
}
|
203
|
-
});
|
204
|
-
};
|
205
|
-
/**
|
206
|
-
* Write the results of an OSS query, which can have multiple root fields,
|
207
|
-
* updating both the root call map (for consistency with classic queries)
|
208
|
-
* and the root record (for consistency with modern queries/fragments).
|
209
|
-
*/
|
210
|
-
|
211
|
-
|
212
|
-
_proto.handleOSSQueryPayload = function handleOSSQueryPayload(query, payload, forceIndex) {
|
213
|
-
var _this3 = this;
|
214
|
-
|
215
|
-
var profiler = require("relay-runtime").RelayProfiler.profile('RelayStoreData.handleQueryPayload');
|
216
|
-
|
217
|
-
var changeTracker = new (require("./RelayChangeTracker"))();
|
218
|
-
var recordWriter = this.getRecordWriter();
|
219
|
-
var writer = new (require("./RelayQueryWriter"))(this._queuedStore, recordWriter, this._queryTracker, changeTracker, {
|
220
|
-
forceIndex: forceIndex,
|
221
|
-
updateTrackedQueries: true
|
222
|
-
});
|
223
|
-
getRootsWithPayloads(query, payload).forEach(function (_ref) {
|
224
|
-
var field = _ref.field,
|
225
|
-
root = _ref.root,
|
226
|
-
rootPayload = _ref.rootPayload;
|
227
|
-
|
228
|
-
// Write the results of the field-specific query
|
229
|
-
require("./writeRelayQueryPayload")(writer, root, rootPayload); // Ensure the root record exists
|
230
|
-
|
231
|
-
|
232
|
-
var path = require("./RelayQueryPath").getRootRecordPath();
|
233
|
-
|
234
|
-
recordWriter.putRecord(require("./RelayStoreConstants").ROOT_ID, query.getType(), path);
|
235
|
-
|
236
|
-
if (_this3._queuedStore.getRecordState(require("./RelayStoreConstants").ROOT_ID) !== require("./RelayClassicRecordState").EXISTENT) {
|
237
|
-
changeTracker.createID(require("./RelayStoreConstants").ROOT_ID);
|
238
|
-
} else {
|
239
|
-
changeTracker.updateID(require("./RelayStoreConstants").ROOT_ID);
|
240
|
-
} // Collect linked record ids for this root field
|
241
|
-
|
242
|
-
|
243
|
-
var dataIDs = [];
|
244
|
-
|
245
|
-
require("./RelayNodeInterface").getResultsFromPayload(root, rootPayload).forEach(function (_ref2) {
|
246
|
-
var result = _ref2.result,
|
247
|
-
rootCallInfo = _ref2.rootCallInfo;
|
248
|
-
var storageKey = rootCallInfo.storageKey,
|
249
|
-
identifyingArgKey = rootCallInfo.identifyingArgKey;
|
250
|
-
var dataID = recordWriter.getDataID(storageKey, identifyingArgKey);
|
251
|
-
|
252
|
-
if (dataID != null) {
|
253
|
-
dataIDs.push(dataID);
|
254
|
-
}
|
255
|
-
}); // Write the field to the root record
|
256
|
-
|
257
|
-
|
258
|
-
var storageKey = field.getStorageKey();
|
259
|
-
|
260
|
-
if (field.isPlural()) {
|
261
|
-
recordWriter.putLinkedRecordIDs(require("./RelayStoreConstants").ROOT_ID, storageKey, dataIDs);
|
262
|
-
} else {
|
263
|
-
var dataID = dataIDs[0];
|
264
|
-
|
265
|
-
if (dataID != null) {
|
266
|
-
recordWriter.putLinkedRecordID(require("./RelayStoreConstants").ROOT_ID, storageKey, dataID);
|
267
|
-
} else {
|
268
|
-
recordWriter.putField(require("./RelayStoreConstants").ROOT_ID, storageKey, null);
|
269
|
-
}
|
270
|
-
}
|
271
|
-
});
|
272
|
-
|
273
|
-
this._handleChangedAndNewDataIDs(changeTracker.getChangeSet());
|
274
|
-
|
275
|
-
profiler.stop();
|
276
|
-
};
|
277
|
-
/**
|
278
|
-
* Write the results of a query into the base record store.
|
279
|
-
*/
|
280
|
-
|
281
|
-
|
282
|
-
_proto.handleQueryPayload = function handleQueryPayload(query, payload, forceIndex) {
|
283
|
-
var profiler = require("relay-runtime").RelayProfiler.profile('RelayStoreData.handleQueryPayload');
|
284
|
-
|
285
|
-
var changeTracker = new (require("./RelayChangeTracker"))();
|
286
|
-
var writer = new (require("./RelayQueryWriter"))(this._queuedStore, this.getRecordWriter(), this._queryTracker, changeTracker, {
|
287
|
-
forceIndex: forceIndex,
|
288
|
-
updateTrackedQueries: true
|
289
|
-
});
|
290
|
-
|
291
|
-
require("./writeRelayQueryPayload")(writer, query, payload);
|
292
|
-
|
293
|
-
this._handleChangedAndNewDataIDs(changeTracker.getChangeSet());
|
294
|
-
|
295
|
-
profiler.stop();
|
296
|
-
};
|
297
|
-
/**
|
298
|
-
* Write the result of a fragment into the base record store.
|
299
|
-
*/
|
300
|
-
|
301
|
-
|
302
|
-
_proto.handleFragmentPayload = function handleFragmentPayload(dataID, fragment, path, payload, forceIndex) {
|
303
|
-
var profiler = require("relay-runtime").RelayProfiler.profile('RelayStoreData.handleFragmentPayload');
|
304
|
-
|
305
|
-
var changeTracker = new (require("./RelayChangeTracker"))();
|
306
|
-
var writer = new (require("./RelayQueryWriter"))(this._queuedStore, this.getRecordWriter(), this._queryTracker, changeTracker, {
|
307
|
-
forceIndex: forceIndex,
|
308
|
-
updateTrackedQueries: true
|
309
|
-
});
|
310
|
-
writer.createRecordIfMissing(fragment, dataID, path, payload);
|
311
|
-
writer.writePayload(fragment, dataID, payload, path);
|
312
|
-
|
313
|
-
this._handleChangedAndNewDataIDs(changeTracker.getChangeSet());
|
314
|
-
|
315
|
-
profiler.stop();
|
316
|
-
};
|
317
|
-
/**
|
318
|
-
* Write the results of an update into the base record store.
|
319
|
-
*/
|
320
|
-
|
321
|
-
|
322
|
-
_proto.handleUpdatePayload = function handleUpdatePayload(operation, payload, _ref3) {
|
323
|
-
var configs = _ref3.configs,
|
324
|
-
isOptimisticUpdate = _ref3.isOptimisticUpdate;
|
325
|
-
|
326
|
-
var profiler = require("relay-runtime").RelayProfiler.profile('RelayStoreData.handleUpdatePayload');
|
327
|
-
|
328
|
-
var changeTracker = new (require("./RelayChangeTracker"))();
|
329
|
-
var recordWriter;
|
330
|
-
|
331
|
-
if (isOptimisticUpdate) {
|
332
|
-
var _ConnectionInterface$ = require("relay-runtime").ConnectionInterface.get(),
|
333
|
-
CLIENT_MUTATION_ID = _ConnectionInterface$.CLIENT_MUTATION_ID;
|
334
|
-
|
335
|
-
var clientMutationID = payload[CLIENT_MUTATION_ID];
|
336
|
-
!(typeof clientMutationID === 'string') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayStoreData.handleUpdatePayload(): Expected optimistic payload ' + 'to have a valid `%s`.', CLIENT_MUTATION_ID) : require("fbjs/lib/invariant")(false) : void 0;
|
337
|
-
recordWriter = this.getRecordWriterForOptimisticMutation(clientMutationID);
|
338
|
-
} else {
|
339
|
-
recordWriter = this._getRecordWriterForMutation();
|
340
|
-
}
|
341
|
-
|
342
|
-
var writer = new (require("./RelayQueryWriter"))(this._queuedStore, recordWriter, this._queryTracker, changeTracker, {
|
343
|
-
forceIndex: require("./generateForceIndex")(),
|
344
|
-
isOptimisticUpdate: isOptimisticUpdate,
|
345
|
-
updateTrackedQueries: false
|
346
|
-
});
|
347
|
-
|
348
|
-
require("./writeRelayUpdatePayload")(writer, operation, payload, {
|
349
|
-
configs: configs,
|
350
|
-
isOptimisticUpdate: isOptimisticUpdate
|
351
|
-
});
|
352
|
-
|
353
|
-
this._handleChangedAndNewDataIDs(changeTracker.getChangeSet());
|
354
|
-
|
355
|
-
profiler.stop();
|
356
|
-
};
|
357
|
-
/**
|
358
|
-
* Given a query fragment and a data ID, returns a root query that applies
|
359
|
-
* the fragment to the object specified by the data ID.
|
360
|
-
*/
|
361
|
-
|
362
|
-
|
363
|
-
_proto.buildFragmentQueryForDataID = function buildFragmentQueryForDataID(fragment, dataID) {
|
364
|
-
if (require("./RelayRecord").isClientID(dataID)) {
|
365
|
-
var path = this._queuedStore.getPathToRecord(this._rangeData.getCanonicalClientID(dataID));
|
366
|
-
|
367
|
-
!path ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayStoreData.buildFragmentQueryForDataID(): Cannot refetch ' + 'record `%s` without a path.', dataID) : require("fbjs/lib/invariant")(false) : void 0;
|
368
|
-
return require("./RelayQueryPath").getQuery(this._cachedStore, path, fragment);
|
369
|
-
} // Fragment fields cannot be spread directly into the root because they
|
370
|
-
// may not exist on the `Node` type.
|
371
|
-
|
372
|
-
|
373
|
-
return require("./RelayQuery").Root.build(fragment.getDebugName() || 'UnknownQuery', require("./RelayNodeInterface").NODE, dataID, [idField, typeField, fragment], {
|
374
|
-
identifyingArgName: require("./RelayNodeInterface").ID,
|
375
|
-
identifyingArgType: require("./RelayNodeInterface").ID_TYPE,
|
376
|
-
isAbstract: true,
|
377
|
-
isDeferred: false,
|
378
|
-
isPlural: false
|
379
|
-
}, require("./RelayNodeInterface").NODE_TYPE);
|
380
|
-
};
|
381
|
-
|
382
|
-
_proto.getNodeData = function getNodeData() {
|
383
|
-
return this._records;
|
384
|
-
};
|
385
|
-
|
386
|
-
_proto.getQueuedData = function getQueuedData() {
|
387
|
-
return this._queuedRecords;
|
388
|
-
};
|
389
|
-
|
390
|
-
_proto.clearQueuedData = function clearQueuedData() {
|
391
|
-
var _this4 = this;
|
392
|
-
|
393
|
-
require("fbjs/lib/forEachObject")(this._queuedRecords, function (_, key) {
|
394
|
-
delete _this4._queuedRecords[key];
|
395
|
-
|
396
|
-
_this4._changeEmitter.broadcastChangeForID(key);
|
397
|
-
});
|
398
|
-
};
|
399
|
-
|
400
|
-
_proto.getCachedData = function getCachedData() {
|
401
|
-
return this._cachedRecords;
|
402
|
-
};
|
403
|
-
|
404
|
-
_proto.getMutationQueue = function getMutationQueue() {
|
405
|
-
return this._mutationQueue;
|
406
|
-
};
|
407
|
-
|
408
|
-
_proto.getNetworkLayer = function getNetworkLayer() {
|
409
|
-
return this._networkLayer;
|
410
|
-
};
|
411
|
-
/**
|
412
|
-
* Get the record store with only the cached and base data (no queued data).
|
413
|
-
*/
|
414
|
-
|
415
|
-
|
416
|
-
_proto.getCachedStore = function getCachedStore() {
|
417
|
-
return this._cachedStore;
|
418
|
-
};
|
419
|
-
/**
|
420
|
-
* Get the record store with full data (cached, base, queued).
|
421
|
-
*/
|
422
|
-
|
423
|
-
|
424
|
-
_proto.getQueuedStore = function getQueuedStore() {
|
425
|
-
return this._queuedStore;
|
426
|
-
};
|
427
|
-
/**
|
428
|
-
* Get the record store with only the base data (no queued/cached data).
|
429
|
-
*/
|
430
|
-
|
431
|
-
|
432
|
-
_proto.getRecordStore = function getRecordStore() {
|
433
|
-
return this._recordStore;
|
434
|
-
};
|
435
|
-
/**
|
436
|
-
* Get the record writer for the base data.
|
437
|
-
*/
|
438
|
-
|
439
|
-
|
440
|
-
_proto.getRecordWriter = function getRecordWriter() {
|
441
|
-
return new (require("./RelayRecordWriter"))(this._records, this._rootCallMap, false, // isOptimistic
|
442
|
-
this._nodeRangeMap, this._cacheManager ? this._cacheManager.getQueryWriter() : null);
|
443
|
-
};
|
444
|
-
|
445
|
-
_proto.getQueryTracker = function getQueryTracker() {
|
446
|
-
return this._queryTracker;
|
447
|
-
};
|
448
|
-
|
449
|
-
_proto.getQueryRunner = function getQueryRunner() {
|
450
|
-
return this._queryRunner;
|
451
|
-
};
|
452
|
-
|
453
|
-
_proto.getChangeEmitter = function getChangeEmitter() {
|
454
|
-
return this._changeEmitter;
|
455
|
-
};
|
456
|
-
|
457
|
-
_proto.getRangeData = function getRangeData() {
|
458
|
-
return this._rangeData;
|
459
|
-
};
|
460
|
-
|
461
|
-
_proto.getPendingQueryTracker = function getPendingQueryTracker() {
|
462
|
-
return this._pendingQueryTracker;
|
463
|
-
};
|
464
|
-
|
465
|
-
_proto.getTaskQueue = function getTaskQueue() {
|
466
|
-
return this._taskQueue;
|
467
|
-
};
|
468
|
-
/**
|
469
|
-
* @deprecated
|
470
|
-
*
|
471
|
-
* Used temporarily by GraphQLStore, but all updates to this object are now
|
472
|
-
* handled through a `RelayRecordStore` instance.
|
473
|
-
*/
|
474
|
-
|
475
|
-
|
476
|
-
_proto.getRootCallData = function getRootCallData() {
|
477
|
-
return this._rootCallMap;
|
478
|
-
};
|
479
|
-
|
480
|
-
_proto._isStoreDataEmpty = function _isStoreDataEmpty() {
|
481
|
-
return Object.keys(this._records).length === 0 && Object.keys(this._queuedRecords).length === 0 && Object.keys(this._cachedRecords).length === 0;
|
482
|
-
};
|
483
|
-
/**
|
484
|
-
* Given a ChangeSet, broadcasts changes for updated DataIDs
|
485
|
-
* and registers new DataIDs with the garbage collector.
|
486
|
-
*/
|
487
|
-
|
488
|
-
|
489
|
-
_proto._handleChangedAndNewDataIDs = function _handleChangedAndNewDataIDs(changeSet) {
|
490
|
-
var _this5 = this;
|
491
|
-
|
492
|
-
var updatedDataIDs = Object.keys(changeSet.updated);
|
493
|
-
var createdDataIDs = Object.keys(changeSet.created);
|
494
|
-
updatedDataIDs.forEach(function (id) {
|
495
|
-
return _this5._changeEmitter.broadcastChangeForID(id);
|
496
|
-
}); // Containers may be subscribed to "new" records in the case where they
|
497
|
-
// were previously garbage collected or where the link was incrementally
|
498
|
-
// loaded from cache prior to the linked record.
|
499
|
-
|
500
|
-
createdDataIDs.forEach(function (id) {
|
501
|
-
_this5._changeEmitter.broadcastChangeForID(id);
|
502
|
-
});
|
503
|
-
};
|
504
|
-
|
505
|
-
_proto._getRecordWriterForMutation = function _getRecordWriterForMutation() {
|
506
|
-
return new (require("./RelayRecordWriter"))(this._records, this._rootCallMap, false, // isOptimistic
|
507
|
-
this._nodeRangeMap, this._cacheManager ? this._cacheManager.getMutationWriter() : null);
|
508
|
-
};
|
509
|
-
|
510
|
-
_proto.getRecordWriterForOptimisticMutation = function getRecordWriterForOptimisticMutation(clientMutationID) {
|
511
|
-
return new (require("./RelayRecordWriter"))(this._queuedRecords, this._rootCallMap, true, // isOptimistic
|
512
|
-
this._nodeRangeMap, null, // don't cache optimistic data
|
513
|
-
clientMutationID);
|
514
|
-
};
|
515
|
-
|
516
|
-
_proto.toJSON = function toJSON() {
|
517
|
-
/**
|
518
|
-
* A util function which remove the querypath from the record. Used to stringify the RecordMap.
|
519
|
-
*/
|
520
|
-
var getRecordsWithoutPaths = function getRecordsWithoutPaths(recordMap) {
|
521
|
-
if (!recordMap) {
|
522
|
-
return null;
|
523
|
-
}
|
524
|
-
|
525
|
-
return require("fbjs/lib/mapObject")(recordMap, function (record) {
|
526
|
-
var nextRecord = (0, _objectSpread2["default"])({}, record);
|
527
|
-
delete nextRecord[require("./RelayRecord").MetadataKey.PATH];
|
528
|
-
return nextRecord;
|
529
|
-
});
|
530
|
-
};
|
531
|
-
|
532
|
-
return {
|
533
|
-
cachedRecords: getRecordsWithoutPaths(this._cachedRecords),
|
534
|
-
cachedRootCallMap: this._cachedRootCallMap,
|
535
|
-
queuedRecords: getRecordsWithoutPaths(this._queuedRecords),
|
536
|
-
records: getRecordsWithoutPaths(this._records),
|
537
|
-
rootCallMap: this._rootCallMap,
|
538
|
-
nodeRangeMap: this._nodeRangeMap
|
539
|
-
};
|
540
|
-
};
|
541
|
-
/* $FlowFixMe: This comment suppresses an error caught by Flow 0.59 which was
|
542
|
-
* not caught before. Most likely, this error is because an exported function
|
543
|
-
* parameter is missing an annotation. Without an annotation, these parameters
|
544
|
-
* are uncovered by Flow. */
|
545
|
-
|
546
|
-
|
547
|
-
RelayStoreData.fromJSON = function fromJSON(obj) {
|
548
|
-
!obj ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayStoreData: JSON object is empty') : require("fbjs/lib/invariant")(false) : void 0;
|
549
|
-
var cachedRecords = obj.cachedRecords,
|
550
|
-
cachedRootCallMap = obj.cachedRootCallMap,
|
551
|
-
queuedRecords = obj.queuedRecords,
|
552
|
-
records = obj.records,
|
553
|
-
rootCallMap = obj.rootCallMap,
|
554
|
-
nodeRangeMap = obj.nodeRangeMap;
|
555
|
-
deserializeRecordRanges(cachedRecords);
|
556
|
-
deserializeRecordRanges(queuedRecords);
|
557
|
-
deserializeRecordRanges(records);
|
558
|
-
return new RelayStoreData(cachedRecords, cachedRootCallMap, queuedRecords, records, rootCallMap, nodeRangeMap);
|
559
|
-
};
|
560
|
-
|
561
|
-
return RelayStoreData;
|
562
|
-
}();
|
563
|
-
/**
|
564
|
-
* A helper function which checks for serialized GraphQLRange
|
565
|
-
* instances and deserializes them in toJSON()
|
566
|
-
*/
|
567
|
-
|
568
|
-
|
569
|
-
function deserializeRecordRanges(records) {
|
570
|
-
for (var _key in records) {
|
571
|
-
var record = records[_key];
|
572
|
-
var range = record.__range__;
|
573
|
-
|
574
|
-
if (range) {
|
575
|
-
record.__range__ = require("./GraphQLRange").fromJSON(range);
|
576
|
-
}
|
577
|
-
}
|
578
|
-
}
|
579
|
-
/**
|
580
|
-
* Given an OSS query and response, returns an array of information
|
581
|
-
* corresponding to each root field with items as follows:
|
582
|
-
* - `field`: the root field from the input query
|
583
|
-
* - `root`: the synthesized RelayQueryRoot corresponding to that field
|
584
|
-
* - `rootPayload`: the payload for that `root`
|
585
|
-
*/
|
586
|
-
|
587
|
-
|
588
|
-
function getRootsWithPayloads(query, response) {
|
589
|
-
var results = [];
|
590
|
-
query.getChildren().forEach(function (child) {
|
591
|
-
var field = child;
|
592
|
-
|
593
|
-
if (!(field instanceof require("./RelayQuery").Field) || !field.canHaveSubselections()) {
|
594
|
-
// Only care about linked fields
|
595
|
-
return;
|
596
|
-
} // Get the concrete field from the RelayQueryField
|
597
|
-
|
598
|
-
|
599
|
-
var concreteField = require("nullthrows")(require("./QueryBuilder").getField(field.getConcreteQueryNode())); // Build the identifying argument for the query
|
600
|
-
|
601
|
-
|
602
|
-
var identifyingArgName;
|
603
|
-
var identifyingArgType;
|
604
|
-
var identifyingArg = concreteField.calls && concreteField.calls[0];
|
605
|
-
|
606
|
-
if (identifyingArg) {
|
607
|
-
identifyingArgName = identifyingArg.name;
|
608
|
-
identifyingArgType = identifyingArg.metadata && identifyingArg.metadata.type;
|
609
|
-
} // Build the concrete query
|
610
|
-
|
611
|
-
|
612
|
-
var concreteQuery = {
|
613
|
-
calls: concreteField.calls,
|
614
|
-
children: concreteField.children,
|
615
|
-
directives: [],
|
616
|
-
// @include/@skip directives are processed within getChildren()
|
617
|
-
fieldName: concreteField.fieldName,
|
618
|
-
isDeferred: false,
|
619
|
-
kind: 'Query',
|
620
|
-
metadata: {
|
621
|
-
identifyingArgName: identifyingArgName,
|
622
|
-
identifyingArgType: identifyingArgType,
|
623
|
-
isAbstract: concreteField.metadata && concreteField.metadata.isAbstract,
|
624
|
-
isPlural: concreteField.metadata && concreteField.metadata.isPlural
|
625
|
-
},
|
626
|
-
name: query.getName(),
|
627
|
-
// Note that classic queries are typed as the type of the root field, not
|
628
|
-
// the `Query` type
|
629
|
-
type: field.getType()
|
630
|
-
}; // Construct a root query
|
631
|
-
|
632
|
-
var root = require("./RelayQuery").Root.create(concreteQuery, require("./RelayMetaRoute").get('$RelayEnvironment'), query.getVariables()); // Construct the payload that would have been returned had `root` been
|
633
|
-
// used to fetch data.
|
634
|
-
|
635
|
-
|
636
|
-
var serializationKey = field.getSerializationKey();
|
637
|
-
var rootPayload = {};
|
638
|
-
|
639
|
-
if (!response.hasOwnProperty(serializationKey)) {
|
640
|
-
// Data is missing for this field. This can occur when the field is empty
|
641
|
-
// due to a failing conditional (@include/@skip) in its subtree.
|
642
|
-
return;
|
643
|
-
}
|
644
|
-
|
645
|
-
rootPayload[root.getFieldName()] = response[serializationKey];
|
646
|
-
results.push({
|
647
|
-
field: field,
|
648
|
-
root: root,
|
649
|
-
rootPayload: rootPayload
|
650
|
-
});
|
651
|
-
});
|
652
|
-
return results;
|
653
|
-
}
|
654
|
-
|
655
|
-
require("relay-runtime").RelayProfiler.instrumentMethods(RelayStoreData.prototype, {
|
656
|
-
handleQueryPayload: 'RelayStoreData.prototype.handleQueryPayload',
|
657
|
-
handleUpdatePayload: 'RelayStoreData.prototype.handleUpdatePayload'
|
658
|
-
});
|
659
|
-
|
660
|
-
module.exports = RelayStoreData;
|