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/RelayEnvironment.js
DELETED
@@ -1,449 +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
|
-
/**
|
15
|
-
* @public
|
16
|
-
*
|
17
|
-
* `RelayEnvironment` is the public API for Relay core. Each instance provides
|
18
|
-
* an isolated environment with:
|
19
|
-
* - Methods for fetching and updating data.
|
20
|
-
* - An in-memory cache of fetched data.
|
21
|
-
* - A configurable network layer for resolving queries/mutations.
|
22
|
-
* - A configurable task scheduler to control when internal tasks are executed.
|
23
|
-
*
|
24
|
-
* No data or configuration is shared between instances. We recommend creating
|
25
|
-
* one `RelayEnvironment` instance per user: client apps may share a single
|
26
|
-
* instance, server apps may create one instance per HTTP request.
|
27
|
-
*/
|
28
|
-
var RelayEnvironment =
|
29
|
-
/*#__PURE__*/
|
30
|
-
function () {
|
31
|
-
var _proto = RelayEnvironment.prototype;
|
32
|
-
|
33
|
-
_proto.applyMutation = function applyMutation(_ref) {
|
34
|
-
var configs = _ref.configs,
|
35
|
-
operation = _ref.operation,
|
36
|
-
optimisticResponse = _ref.optimisticResponse,
|
37
|
-
variables = _ref.variables;
|
38
|
-
var mutationTransaction = new (require("./RelayGraphQLMutation"))(operation.node, require("./RelayVariables").getOperationVariables(operation, variables), null, this);
|
39
|
-
mutationTransaction.applyOptimistic(operation.node, optimisticResponse, configs);
|
40
|
-
var disposed = false;
|
41
|
-
return {
|
42
|
-
dispose: function dispose() {
|
43
|
-
if (!disposed) {
|
44
|
-
disposed = true;
|
45
|
-
mutationTransaction.rollback();
|
46
|
-
}
|
47
|
-
}
|
48
|
-
};
|
49
|
-
};
|
50
|
-
|
51
|
-
_proto.check = function check(selector) {
|
52
|
-
return false;
|
53
|
-
};
|
54
|
-
|
55
|
-
_proto.commitPayload = function commitPayload(operationDescriptor, payload) {
|
56
|
-
var selector = operationDescriptor.root;
|
57
|
-
|
58
|
-
var fragment = require("./RelayQuery").Fragment.create(selector.node, require("./RelayMetaRoute").get('$RelayEnvironment'), selector.variables);
|
59
|
-
|
60
|
-
var path = require("./RelayQueryPath").getRootRecordPath();
|
61
|
-
|
62
|
-
this._storeData.handleFragmentPayload(selector.dataID, fragment, path, payload, null);
|
63
|
-
};
|
64
|
-
/**
|
65
|
-
* An internal implementation of the "lookup" API that is shared by `lookup()`
|
66
|
-
* and `subscribe()`. Note that `subscribe()` cannot use `lookup()` directly,
|
67
|
-
* since the former may modify the result data before freezing it.
|
68
|
-
*/
|
69
|
-
|
70
|
-
|
71
|
-
_proto._lookup = function _lookup(selector) {
|
72
|
-
var fragment = require("./RelayQuery").Fragment.create(selector.node, require("./RelayMetaRoute").get('$RelayEnvironment'), selector.variables);
|
73
|
-
|
74
|
-
var _readRelayQueryData = require("./readRelayQueryData")(this._storeData, fragment, selector.dataID),
|
75
|
-
data = _readRelayQueryData.data,
|
76
|
-
dataIDs = _readRelayQueryData.dataIDs; // Ensure that the root ID is considered "seen" and will be watched for
|
77
|
-
// changes if the returned selector is passed to `subscribe()`.
|
78
|
-
|
79
|
-
|
80
|
-
dataIDs[selector.dataID] = true;
|
81
|
-
return (0, _objectSpread2["default"])({}, selector, {
|
82
|
-
data: data,
|
83
|
-
seenRecords: dataIDs,
|
84
|
-
isMissingData: false
|
85
|
-
});
|
86
|
-
};
|
87
|
-
|
88
|
-
_proto.lookup = function lookup(selector) {
|
89
|
-
var snapshot = this._lookup(selector);
|
90
|
-
|
91
|
-
if (process.env.NODE_ENV !== "production") {
|
92
|
-
deepFreezeSnapshot(snapshot);
|
93
|
-
}
|
94
|
-
|
95
|
-
return snapshot;
|
96
|
-
};
|
97
|
-
|
98
|
-
_proto.sendMutation = function sendMutation(_ref2) {
|
99
|
-
var configs = _ref2.configs,
|
100
|
-
onCompleted = _ref2.onCompleted,
|
101
|
-
onError = _ref2.onError,
|
102
|
-
operation = _ref2.operation,
|
103
|
-
optimisticOperation = _ref2.optimisticOperation,
|
104
|
-
optimisticResponse = _ref2.optimisticResponse,
|
105
|
-
variables = _ref2.variables,
|
106
|
-
uploadables = _ref2.uploadables;
|
107
|
-
var disposed = false;
|
108
|
-
var mutationTransaction = new (require("./RelayGraphQLMutation"))(operation.node, require("./RelayVariables").getOperationVariables(operation, variables), uploadables, this, {
|
109
|
-
onSuccess: function onSuccess(response) {
|
110
|
-
if (disposed) {
|
111
|
-
return;
|
112
|
-
}
|
113
|
-
|
114
|
-
onCompleted && onCompleted(response);
|
115
|
-
},
|
116
|
-
onFailure: function onFailure(transaction) {
|
117
|
-
if (disposed) {
|
118
|
-
return;
|
119
|
-
}
|
120
|
-
|
121
|
-
if (onError) {
|
122
|
-
var _error = transaction.getError();
|
123
|
-
|
124
|
-
if (!_error) {
|
125
|
-
_error = new Error("RelayEnvironment: Unknown error executing mutation ".concat(operation.node.name));
|
126
|
-
}
|
127
|
-
|
128
|
-
onError(_error);
|
129
|
-
}
|
130
|
-
}
|
131
|
-
});
|
132
|
-
|
133
|
-
if (optimisticResponse) {
|
134
|
-
mutationTransaction.applyOptimistic(optimisticOperation ? optimisticOperation.node : operation.node, optimisticResponse, configs);
|
135
|
-
}
|
136
|
-
|
137
|
-
mutationTransaction.commit(configs);
|
138
|
-
return {
|
139
|
-
dispose: function dispose() {
|
140
|
-
if (!disposed) {
|
141
|
-
disposed = true;
|
142
|
-
}
|
143
|
-
}
|
144
|
-
};
|
145
|
-
};
|
146
|
-
|
147
|
-
_proto.subscribe = function subscribe(snapshot, callback) {
|
148
|
-
var _this = this;
|
149
|
-
|
150
|
-
var subscription;
|
151
|
-
|
152
|
-
var changeEmitter = this._storeData.getChangeEmitter();
|
153
|
-
|
154
|
-
var update = function update() {
|
155
|
-
// Re-read data and see if anything changed
|
156
|
-
var nextSnapshot = _this._lookup(snapshot); // Note that `recycleNodesInto` may modify the "next" value
|
157
|
-
|
158
|
-
|
159
|
-
nextSnapshot.data = require("relay-runtime").recycleNodesInto(snapshot.data, nextSnapshot.data);
|
160
|
-
|
161
|
-
if (nextSnapshot.data === snapshot.data) {
|
162
|
-
// The record changes don't affect the results of the selector
|
163
|
-
return;
|
164
|
-
}
|
165
|
-
|
166
|
-
if (process.env.NODE_ENV !== "production") {
|
167
|
-
deepFreezeSnapshot(nextSnapshot);
|
168
|
-
}
|
169
|
-
|
170
|
-
if (subscription) {
|
171
|
-
subscription.remove();
|
172
|
-
}
|
173
|
-
|
174
|
-
subscription = changeEmitter.addListenerForIDs(Object.keys(nextSnapshot.seenRecords), update);
|
175
|
-
snapshot = nextSnapshot;
|
176
|
-
callback(snapshot);
|
177
|
-
};
|
178
|
-
|
179
|
-
subscription = changeEmitter.addListenerForIDs(Object.keys(snapshot.seenRecords), update);
|
180
|
-
return {
|
181
|
-
dispose: function dispose() {
|
182
|
-
if (subscription) {
|
183
|
-
subscription.remove();
|
184
|
-
subscription = null;
|
185
|
-
}
|
186
|
-
}
|
187
|
-
};
|
188
|
-
};
|
189
|
-
|
190
|
-
_proto.retain = function retain(selector) {
|
191
|
-
return {
|
192
|
-
dispose: function dispose() {}
|
193
|
-
};
|
194
|
-
};
|
195
|
-
|
196
|
-
_proto.sendQuery = function sendQuery(_ref3) {
|
197
|
-
var _this2 = this;
|
198
|
-
|
199
|
-
var cacheConfig = _ref3.cacheConfig,
|
200
|
-
onCompleted = _ref3.onCompleted,
|
201
|
-
onError = _ref3.onError,
|
202
|
-
onNext = _ref3.onNext,
|
203
|
-
operation = _ref3.operation;
|
204
|
-
var isDisposed = false;
|
205
|
-
|
206
|
-
var dispose = function dispose() {
|
207
|
-
isDisposed = true;
|
208
|
-
};
|
209
|
-
|
210
|
-
var query = require("./RelayQuery").OSSQuery.create(operation.node, require("./RelayMetaRoute").get('$RelayEnvironment'), operation.variables);
|
211
|
-
|
212
|
-
var request = new (require("./RelayQueryRequest"))(query);
|
213
|
-
request.getPromise().then(function (payload) {
|
214
|
-
if (isDisposed) {
|
215
|
-
return;
|
216
|
-
}
|
217
|
-
|
218
|
-
var forceIndex = cacheConfig && cacheConfig.force ? require("./generateForceIndex")() : null;
|
219
|
-
|
220
|
-
_this2._storeData.handleOSSQueryPayload(query, payload.response, forceIndex);
|
221
|
-
|
222
|
-
onNext && onNext(operation.root);
|
223
|
-
onCompleted && onCompleted();
|
224
|
-
}, function (error) {
|
225
|
-
if (isDisposed) {
|
226
|
-
return;
|
227
|
-
}
|
228
|
-
|
229
|
-
onError && onError(error);
|
230
|
-
});
|
231
|
-
|
232
|
-
this._storeData.getTaskQueue().enqueue(function () {
|
233
|
-
_this2._storeData.getNetworkLayer().sendQueries([request]);
|
234
|
-
});
|
235
|
-
|
236
|
-
return {
|
237
|
-
dispose: dispose
|
238
|
-
};
|
239
|
-
};
|
240
|
-
|
241
|
-
_proto.execute = function execute(_ref4) {
|
242
|
-
var _this3 = this;
|
243
|
-
|
244
|
-
var operation = _ref4.operation,
|
245
|
-
cacheConfig = _ref4.cacheConfig,
|
246
|
-
updater = _ref4.updater;
|
247
|
-
return require("relay-runtime").Observable.fromLegacy(function (observer) {
|
248
|
-
return _this3.sendQuery((0, _objectSpread2["default"])({
|
249
|
-
operation: operation,
|
250
|
-
cacheConfig: cacheConfig
|
251
|
-
}, observer));
|
252
|
-
});
|
253
|
-
};
|
254
|
-
|
255
|
-
function RelayEnvironment(storeData) {
|
256
|
-
this._storeData = storeData ? storeData : new (require("./RelayStoreData"))();
|
257
|
-
|
258
|
-
this._storeData.getChangeEmitter().injectBatchingStrategy(require("./relayUnstableBatchedUpdates"));
|
259
|
-
|
260
|
-
this.applyUpdate = this.applyUpdate.bind(this);
|
261
|
-
this.commitUpdate = this.commitUpdate.bind(this);
|
262
|
-
this.unstable_internal = require("./RelayClassicCore");
|
263
|
-
}
|
264
|
-
/**
|
265
|
-
* @internal
|
266
|
-
*/
|
267
|
-
|
268
|
-
|
269
|
-
_proto.getStoreData = function getStoreData() {
|
270
|
-
return this._storeData;
|
271
|
-
};
|
272
|
-
/**
|
273
|
-
* @internal
|
274
|
-
*/
|
275
|
-
|
276
|
-
|
277
|
-
_proto.injectDefaultNetworkLayer = function injectDefaultNetworkLayer(networkLayer) {
|
278
|
-
this._storeData.getNetworkLayer().injectDefaultImplementation(networkLayer);
|
279
|
-
};
|
280
|
-
|
281
|
-
_proto.injectNetworkLayer = function injectNetworkLayer(networkLayer) {
|
282
|
-
this._storeData.getNetworkLayer().injectImplementation(networkLayer);
|
283
|
-
};
|
284
|
-
/**
|
285
|
-
* @internal
|
286
|
-
*/
|
287
|
-
|
288
|
-
|
289
|
-
_proto.injectQueryTracker = function injectQueryTracker(queryTracker) {
|
290
|
-
this._storeData.injectQueryTracker(queryTracker);
|
291
|
-
};
|
292
|
-
|
293
|
-
_proto.addNetworkSubscriber = function addNetworkSubscriber(queryCallback, mutationCallback) {
|
294
|
-
return this._storeData.getNetworkLayer().addNetworkSubscriber(queryCallback, mutationCallback);
|
295
|
-
};
|
296
|
-
|
297
|
-
_proto.injectTaskScheduler = function injectTaskScheduler(scheduler) {
|
298
|
-
this._storeData.injectTaskScheduler(scheduler);
|
299
|
-
};
|
300
|
-
|
301
|
-
_proto.injectCacheManager = function injectCacheManager(cacheManager) {
|
302
|
-
this._storeData.injectCacheManager(cacheManager);
|
303
|
-
};
|
304
|
-
/**
|
305
|
-
* Primes the store by sending requests for any missing data that would be
|
306
|
-
* required to satisfy the supplied set of queries.
|
307
|
-
*/
|
308
|
-
|
309
|
-
|
310
|
-
_proto.primeCache = function primeCache(querySet, callback) {
|
311
|
-
return this._storeData.getQueryRunner().run(querySet, callback);
|
312
|
-
};
|
313
|
-
/**
|
314
|
-
* Forces the supplied set of queries to be fetched and written to the store.
|
315
|
-
* Any data that previously satisfied the queries will be overwritten.
|
316
|
-
*/
|
317
|
-
|
318
|
-
|
319
|
-
_proto.forceFetch = function forceFetch(querySet, callback) {
|
320
|
-
return this._storeData.getQueryRunner().forceFetch(querySet, callback);
|
321
|
-
};
|
322
|
-
/**
|
323
|
-
* Reads query data anchored at the supplied data ID.
|
324
|
-
*/
|
325
|
-
|
326
|
-
|
327
|
-
_proto.read = function read(node, dataID, options) {
|
328
|
-
return require("./readRelayQueryData")(this._storeData, node, dataID, options).data;
|
329
|
-
};
|
330
|
-
/**
|
331
|
-
* Reads query data anchored at the supplied data IDs.
|
332
|
-
*/
|
333
|
-
|
334
|
-
|
335
|
-
_proto.readAll = function readAll(node, dataIDs, options) {
|
336
|
-
var _this4 = this;
|
337
|
-
|
338
|
-
return dataIDs.map(function (dataID) {
|
339
|
-
return require("./readRelayQueryData")(_this4._storeData, node, dataID, options).data;
|
340
|
-
});
|
341
|
-
};
|
342
|
-
/**
|
343
|
-
* Reads query data, where each element in the result array corresponds to a
|
344
|
-
* root call argument. If the root call has no arguments, the result array
|
345
|
-
* will contain exactly one element.
|
346
|
-
*/
|
347
|
-
|
348
|
-
|
349
|
-
_proto.readQuery = function readQuery(root, options) {
|
350
|
-
var _this5 = this;
|
351
|
-
|
352
|
-
var queuedStore = this._storeData.getQueuedStore();
|
353
|
-
|
354
|
-
var storageKey = root.getStorageKey();
|
355
|
-
var results = [];
|
356
|
-
|
357
|
-
require("./forEachRootCallArg")(root, function (_ref5) {
|
358
|
-
var identifyingArgKey = _ref5.identifyingArgKey;
|
359
|
-
var data;
|
360
|
-
var dataID = queuedStore.getDataID(storageKey, identifyingArgKey);
|
361
|
-
|
362
|
-
if (dataID != null) {
|
363
|
-
data = _this5.read(root, dataID, options);
|
364
|
-
}
|
365
|
-
|
366
|
-
results.push(data);
|
367
|
-
});
|
368
|
-
|
369
|
-
return results;
|
370
|
-
};
|
371
|
-
/**
|
372
|
-
* @internal
|
373
|
-
*
|
374
|
-
* Returns a fragment "resolver" - a subscription to the results of a fragment
|
375
|
-
* and a means to access the latest results. This is a transitional API and
|
376
|
-
* not recommended for general use.
|
377
|
-
*/
|
378
|
-
|
379
|
-
|
380
|
-
_proto.getFragmentResolver = function getFragmentResolver(fragment, onNext) {
|
381
|
-
return new (require("./GraphQLStoreQueryResolver"))(this._storeData, fragment, onNext);
|
382
|
-
};
|
383
|
-
/**
|
384
|
-
* Adds an update to the store without committing it. The returned
|
385
|
-
* RelayMutationTransaction can be committed or rolled back at a later time.
|
386
|
-
*/
|
387
|
-
|
388
|
-
|
389
|
-
_proto.applyUpdate = function applyUpdate(mutation, callbacks) {
|
390
|
-
mutation.bindEnvironment(this);
|
391
|
-
return this._storeData.getMutationQueue().createTransaction(mutation, callbacks).applyOptimistic();
|
392
|
-
};
|
393
|
-
/**
|
394
|
-
* Adds an update to the store and commits it immediately. Returns
|
395
|
-
* the RelayMutationTransaction.
|
396
|
-
*/
|
397
|
-
|
398
|
-
|
399
|
-
_proto.commitUpdate = function commitUpdate(mutation, callbacks) {
|
400
|
-
var transaction = this.applyUpdate(mutation, callbacks); // The idea here is to defer the call to `commit()` to give the optimistic
|
401
|
-
// mutation time to flush out to the UI before starting the commit work.
|
402
|
-
|
403
|
-
var preCommitStatus = transaction.getStatus();
|
404
|
-
setTimeout(function () {
|
405
|
-
if (transaction.getStatus() !== preCommitStatus) {
|
406
|
-
return;
|
407
|
-
}
|
408
|
-
|
409
|
-
transaction.commit();
|
410
|
-
});
|
411
|
-
return transaction;
|
412
|
-
};
|
413
|
-
/**
|
414
|
-
* @deprecated
|
415
|
-
*
|
416
|
-
* Method renamed to commitUpdate
|
417
|
-
*/
|
418
|
-
|
419
|
-
|
420
|
-
_proto.update = function update(mutation, callbacks) {
|
421
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, '`Relay.Store.update` is deprecated. Please use' + ' `Relay.Store.commitUpdate` or `Relay.Store.applyUpdate` instead.') : void 0;
|
422
|
-
this.commitUpdate(mutation, callbacks);
|
423
|
-
};
|
424
|
-
|
425
|
-
return RelayEnvironment;
|
426
|
-
}();
|
427
|
-
/**
|
428
|
-
* RelayQuery mutates the `__cachedFragment__` property of concrete nodes for
|
429
|
-
* memoization purposes, so a snapshot cannot be completely frozen. Instead this
|
430
|
-
* function shallow-freezes the snapshot itself and deeply freezes all
|
431
|
-
* properties except the `node`.
|
432
|
-
*/
|
433
|
-
|
434
|
-
|
435
|
-
function deepFreezeSnapshot(snapshot) {
|
436
|
-
Object.freeze(snapshot);
|
437
|
-
|
438
|
-
if (snapshot.data != null) {
|
439
|
-
require("relay-runtime").deepFreeze(snapshot.data);
|
440
|
-
}
|
441
|
-
|
442
|
-
require("relay-runtime").deepFreeze(snapshot.seenRecords);
|
443
|
-
|
444
|
-
require("relay-runtime").deepFreeze(snapshot.variables);
|
445
|
-
|
446
|
-
return snapshot;
|
447
|
-
}
|
448
|
-
|
449
|
-
module.exports = RelayEnvironment;
|
package/lib/RelayFetchMode.js
DELETED
@@ -1,17 +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
|
-
* strict
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
var RelayFetchMode = Object.freeze({
|
13
|
-
CLIENT: 'CLIENT',
|
14
|
-
PRELOAD: 'PRELOAD',
|
15
|
-
REFETCH: 'REFETCH'
|
16
|
-
});
|
17
|
-
module.exports = RelayFetchMode;
|
@@ -1,161 +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
|
-
/**
|
13
|
-
* Fragment pointers encapsulate the fetched data for a fragment reference. They
|
14
|
-
* are opaque tokens that are used by Relay containers to read data that is then
|
15
|
-
* passed to the underlying React component.
|
16
|
-
*
|
17
|
-
* @internal
|
18
|
-
*/
|
19
|
-
var RelayFragmentPointer = {
|
20
|
-
addFragment: function addFragment(record, fragment) {
|
21
|
-
var fragmentMap = record.__fragments__;
|
22
|
-
|
23
|
-
if (fragmentMap == null) {
|
24
|
-
fragmentMap = record.__fragments__ = {};
|
25
|
-
}
|
26
|
-
|
27
|
-
!(typeof fragmentMap === 'object' && fragmentMap != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayFragmentPointer: Expected record to contain a fragment map, got ' + '`%s` for record `%s`.', fragmentMap, record.__dataID__) : require("fbjs/lib/invariant")(false) : void 0;
|
28
|
-
var fragmentID = fragment.getConcreteFragmentID();
|
29
|
-
var variableList = fragmentMap[fragmentID];
|
30
|
-
|
31
|
-
if (variableList == null) {
|
32
|
-
variableList = fragmentMap[fragmentID] = [];
|
33
|
-
}
|
34
|
-
|
35
|
-
!Array.isArray(variableList) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayFragmentPointer: Expected record to contain a fragment/variable ' + 'map, got `%s` for record `%s`.', variableList, record.__dataID__) : require("fbjs/lib/invariant")(false) : void 0;
|
36
|
-
variableList.push(fragment.getVariables());
|
37
|
-
},
|
38
|
-
|
39
|
-
/**
|
40
|
-
* Returns true if the concrete fragment is included in the fragment pointer
|
41
|
-
* results, regardless of the variables.
|
42
|
-
*/
|
43
|
-
hasConcreteFragment: function hasConcreteFragment(record, fragment) {
|
44
|
-
var fragmentMap = record.__fragments__;
|
45
|
-
|
46
|
-
if (typeof fragmentMap === 'object' && fragmentMap != null) {
|
47
|
-
var _fragmentID = fragment.getConcreteFragmentID();
|
48
|
-
|
49
|
-
return fragmentMap.hasOwnProperty(_fragmentID);
|
50
|
-
}
|
51
|
-
|
52
|
-
return false;
|
53
|
-
},
|
54
|
-
|
55
|
-
/**
|
56
|
-
* Returns true if the combination of concrete fragment + variables is
|
57
|
-
* included in the fragment pointer results.
|
58
|
-
*/
|
59
|
-
hasFragment: function hasFragment(record, fragment) {
|
60
|
-
var variableList = RelayFragmentPointer.getFragmentVariables(record, fragment);
|
61
|
-
|
62
|
-
if (variableList != null) {
|
63
|
-
return variableList.some(function (vars) {
|
64
|
-
return require("fbjs/lib/areEqual")(vars, fragment.getVariables());
|
65
|
-
});
|
66
|
-
}
|
67
|
-
|
68
|
-
return false;
|
69
|
-
},
|
70
|
-
getVariablesForID: function getVariablesForID(record, fragmentID) {
|
71
|
-
var fragmentMap = record.__fragments__;
|
72
|
-
|
73
|
-
if (typeof fragmentMap === 'object' && fragmentMap != null) {
|
74
|
-
var variables = fragmentMap[fragmentID];
|
75
|
-
|
76
|
-
if (variables) {
|
77
|
-
!(Array.isArray(variables) && variables.length === 1) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayFragmentPointer: Expected an array with at most one set of ' + 'variables per concrete fragment, got %s.', variables) : require("fbjs/lib/invariant")(false) : void 0;
|
78
|
-
return variables[0];
|
79
|
-
}
|
80
|
-
}
|
81
|
-
|
82
|
-
return null;
|
83
|
-
},
|
84
|
-
|
85
|
-
/**
|
86
|
-
* Returns the list of variables whose results are available for the given
|
87
|
-
* concrete fragment.
|
88
|
-
*/
|
89
|
-
getFragmentVariables: function getFragmentVariables(record, fragment) {
|
90
|
-
var fragmentMap = record.__fragments__;
|
91
|
-
|
92
|
-
if (typeof fragmentMap === 'object' && fragmentMap != null) {
|
93
|
-
var _fragmentID2 = fragment.getConcreteFragmentID();
|
94
|
-
|
95
|
-
return fragmentMap[_fragmentID2];
|
96
|
-
}
|
97
|
-
|
98
|
-
return null;
|
99
|
-
},
|
100
|
-
create: function create(dataID, fragment) {
|
101
|
-
var record = require("./RelayRecord").create(dataID);
|
102
|
-
|
103
|
-
RelayFragmentPointer.addFragment(record, fragment);
|
104
|
-
/* $FlowFixMe - Flow error detected during the deployment of v0.38.0. To see
|
105
|
-
* the error, remove this comment and run flow */
|
106
|
-
|
107
|
-
return record;
|
108
|
-
},
|
109
|
-
createForRoot: function createForRoot(store, query) {
|
110
|
-
var fragment = getRootFragment(query);
|
111
|
-
|
112
|
-
if (!fragment) {
|
113
|
-
return null;
|
114
|
-
}
|
115
|
-
|
116
|
-
var storageKey = query.getStorageKey();
|
117
|
-
var pointers = [];
|
118
|
-
|
119
|
-
require("./forEachRootCallArg")(query, function (_ref) {
|
120
|
-
var identifyingArgKey = _ref.identifyingArgKey;
|
121
|
-
var dataID = store.getDataID(storageKey, identifyingArgKey);
|
122
|
-
|
123
|
-
if (dataID == null) {
|
124
|
-
pointers.push(null);
|
125
|
-
} else {
|
126
|
-
pointers.push(RelayFragmentPointer.create(dataID, fragment));
|
127
|
-
}
|
128
|
-
}); // Distinguish between singular/plural queries.
|
129
|
-
|
130
|
-
|
131
|
-
var identifyingArg = query.getIdentifyingArg();
|
132
|
-
var identifyingArgValue = identifyingArg && identifyingArg.value || null;
|
133
|
-
|
134
|
-
if (Array.isArray(identifyingArgValue)) {
|
135
|
-
return pointers;
|
136
|
-
}
|
137
|
-
|
138
|
-
return pointers[0];
|
139
|
-
}
|
140
|
-
};
|
141
|
-
|
142
|
-
function getRootFragment(query) {
|
143
|
-
var batchCall = query.getBatchCall();
|
144
|
-
|
145
|
-
if (batchCall) {
|
146
|
-
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'Queries supplied at the root cannot have batch call variables. Query ' + '`%s` has a batch call variable, `%s`.', query.getName(), batchCall.refParamName) : require("fbjs/lib/invariant")(false) : void 0;
|
147
|
-
}
|
148
|
-
|
149
|
-
var fragment;
|
150
|
-
query.getChildren().forEach(function (child) {
|
151
|
-
if (child instanceof require("./RelayQuery").Fragment) {
|
152
|
-
!!fragment ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'Queries supplied at the root should contain exactly one fragment ' + "(e.g. `${Component.getFragment('...')}`). Query `%s` contains " + 'more than one fragment.', query.getName()) : require("fbjs/lib/invariant")(false) : void 0;
|
153
|
-
fragment = child;
|
154
|
-
} else if (child instanceof require("./RelayQuery").Field) {
|
155
|
-
!child.isGenerated() ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'Queries supplied at the root should contain exactly one fragment ' + 'and no fields. Query `%s` contains a field, `%s`. If you need to ' + 'fetch fields, declare them in a Relay container.', query.getName(), child.getSchemaName()) : require("fbjs/lib/invariant")(false) : void 0;
|
156
|
-
}
|
157
|
-
});
|
158
|
-
return fragment;
|
159
|
-
}
|
160
|
-
|
161
|
-
module.exports = RelayFragmentPointer;
|