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/RelayQueryWriter.js
DELETED
@@ -1,573 +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 _inheritsLoose2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/inheritsLoose"));
|
15
|
-
|
16
|
-
/**
|
17
|
-
* @internal
|
18
|
-
*
|
19
|
-
* Helper for writing the result of one or more queries/operations into the
|
20
|
-
* store, updating tracked queries, and recording changed record IDs.
|
21
|
-
*/
|
22
|
-
var RelayQueryWriter =
|
23
|
-
/*#__PURE__*/
|
24
|
-
function (_RelayQueryVisitor) {
|
25
|
-
(0, _inheritsLoose2["default"])(RelayQueryWriter, _RelayQueryVisitor);
|
26
|
-
|
27
|
-
function RelayQueryWriter(store, writer, queryTracker, changeTracker, options) {
|
28
|
-
var _this;
|
29
|
-
|
30
|
-
_this = _RelayQueryVisitor.call(this) || this;
|
31
|
-
_this._changeTracker = changeTracker;
|
32
|
-
_this._forceIndex = options && options.forceIndex ? options.forceIndex : 0;
|
33
|
-
_this._isOptimisticUpdate = !!(options && options.isOptimisticUpdate);
|
34
|
-
_this._store = store;
|
35
|
-
_this._queryTracker = queryTracker;
|
36
|
-
_this._updateTrackedQueries = !!(options && options.updateTrackedQueries);
|
37
|
-
_this._writer = writer;
|
38
|
-
return _this;
|
39
|
-
}
|
40
|
-
|
41
|
-
var _proto = RelayQueryWriter.prototype;
|
42
|
-
|
43
|
-
_proto.getRecordStore = function getRecordStore() {
|
44
|
-
return this._store;
|
45
|
-
};
|
46
|
-
|
47
|
-
_proto.getRecordWriter = function getRecordWriter() {
|
48
|
-
return this._writer;
|
49
|
-
};
|
50
|
-
|
51
|
-
_proto.getRecordTypeName = function getRecordTypeName(node, recordID, payload) {
|
52
|
-
if (this._isOptimisticUpdate) {
|
53
|
-
// Optimistic queries are inferred. Reuse existing type if available.
|
54
|
-
return this._store.getType(recordID);
|
55
|
-
}
|
56
|
-
|
57
|
-
var typeName = payload[require("./RelayNodeInterface").TYPENAME];
|
58
|
-
|
59
|
-
if (typeName == null) {
|
60
|
-
if (!node.isAbstract()) {
|
61
|
-
typeName = node.getType();
|
62
|
-
} else {
|
63
|
-
typeName = this._store.getType(recordID);
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
67
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(typeName && typeName !== require("./RelayNodeInterface").ANY_TYPE, 'RelayQueryWriter: Could not find a type name for record `%s`.', recordID) : void 0;
|
68
|
-
return typeName || null;
|
69
|
-
};
|
70
|
-
/**
|
71
|
-
* Traverses a query and payload in parallel, writing the results into the
|
72
|
-
* store.
|
73
|
-
*/
|
74
|
-
|
75
|
-
|
76
|
-
_proto.writePayload = function writePayload(node, recordID, responseData, path) {
|
77
|
-
var _this2 = this;
|
78
|
-
|
79
|
-
var state = {
|
80
|
-
nodeID: null,
|
81
|
-
path: path,
|
82
|
-
recordID: recordID,
|
83
|
-
responseData: responseData
|
84
|
-
};
|
85
|
-
|
86
|
-
if (node instanceof require("./RelayQuery").Field && node.canHaveSubselections()) {
|
87
|
-
// for non-scalar fields, the recordID is the parent
|
88
|
-
node.getChildren().forEach(function (child) {
|
89
|
-
_this2.visit(child, state);
|
90
|
-
});
|
91
|
-
return;
|
92
|
-
}
|
93
|
-
|
94
|
-
this.visit(node, state);
|
95
|
-
};
|
96
|
-
/**
|
97
|
-
* Records are "created" whenever an entry did not previously exist for the
|
98
|
-
* `recordID`, including cases when a `recordID` is created with a null value.
|
99
|
-
*/
|
100
|
-
|
101
|
-
|
102
|
-
_proto.recordCreate = function recordCreate(recordID) {
|
103
|
-
this._changeTracker.createID(recordID);
|
104
|
-
};
|
105
|
-
/**
|
106
|
-
* Records are "updated" if any field changes (including being set to null).
|
107
|
-
* Updates are not recorded for newly created records.
|
108
|
-
*/
|
109
|
-
|
110
|
-
|
111
|
-
_proto.recordUpdate = function recordUpdate(recordID) {
|
112
|
-
this._changeTracker.updateID(recordID);
|
113
|
-
};
|
114
|
-
/**
|
115
|
-
* Determine if the record was created by this write operation.
|
116
|
-
*/
|
117
|
-
|
118
|
-
|
119
|
-
_proto.isNewRecord = function isNewRecord(recordID) {
|
120
|
-
return this._changeTracker.isNewRecord(recordID);
|
121
|
-
};
|
122
|
-
/**
|
123
|
-
* Helper to create a record and the corresponding notification.
|
124
|
-
*/
|
125
|
-
|
126
|
-
|
127
|
-
_proto.createRecordIfMissing = function createRecordIfMissing(node, recordID, path, payload) {
|
128
|
-
var recordState = this._store.getRecordState(recordID);
|
129
|
-
|
130
|
-
var typeName = payload && this.getRecordTypeName(node, recordID, payload);
|
131
|
-
|
132
|
-
this._writer.putRecord(recordID, typeName, path);
|
133
|
-
|
134
|
-
if (recordState !== require("./RelayClassicRecordState").EXISTENT) {
|
135
|
-
this.recordCreate(recordID);
|
136
|
-
}
|
137
|
-
|
138
|
-
if (this._queryTracker && (this.isNewRecord(recordID) || this._updateTrackedQueries) && (!require("./RelayRecord").isClientID(recordID) || require("./RelayQueryPath").isRootPath(path))) {
|
139
|
-
this._queryTracker.trackNodeForID(node, recordID);
|
140
|
-
}
|
141
|
-
};
|
142
|
-
|
143
|
-
_proto.visitRoot = function visitRoot(root, state) {
|
144
|
-
var path = state.path,
|
145
|
-
recordID = state.recordID,
|
146
|
-
responseData = state.responseData;
|
147
|
-
|
148
|
-
var recordState = this._store.getRecordState(recordID); // GraphQL should never return undefined for a field
|
149
|
-
|
150
|
-
|
151
|
-
if (responseData == null) {
|
152
|
-
!(responseData !== undefined) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryWriter: Unexpectedly encountered `undefined` in payload. ' + 'Cannot set root record `%s` to undefined.', recordID) : require("fbjs/lib/invariant")(false) : void 0;
|
153
|
-
|
154
|
-
this._writer.deleteRecord(recordID);
|
155
|
-
|
156
|
-
if (recordState === require("./RelayClassicRecordState").EXISTENT) {
|
157
|
-
this.recordUpdate(recordID);
|
158
|
-
}
|
159
|
-
|
160
|
-
return;
|
161
|
-
}
|
162
|
-
|
163
|
-
!(typeof responseData === 'object' && responseData !== null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryWriter: Cannot update record `%s`, expected response to be ' + 'an array or object.', recordID) : require("fbjs/lib/invariant")(false) : void 0;
|
164
|
-
this.createRecordIfMissing(root, recordID, path, responseData);
|
165
|
-
this.traverse(root, state);
|
166
|
-
};
|
167
|
-
|
168
|
-
_proto.visitFragment = function visitFragment(fragment, state) {
|
169
|
-
var recordID = state.recordID;
|
170
|
-
|
171
|
-
if (fragment.isDeferred()) {
|
172
|
-
var hash = fragment.getSourceCompositeHash() || fragment.getCompositeHash();
|
173
|
-
|
174
|
-
this._writer.setHasDeferredFragmentData(recordID, hash);
|
175
|
-
|
176
|
-
this.recordUpdate(recordID);
|
177
|
-
} // Skip fragments that do not match the record's concrete type. Fragments
|
178
|
-
// cannot be skipped for optimistic writes because optimistically created
|
179
|
-
// records *may* have a default `Node` type.
|
180
|
-
|
181
|
-
|
182
|
-
if (this._isOptimisticUpdate || require("./isCompatibleRelayFragmentType")(fragment, this._store.getType(recordID))) {
|
183
|
-
if (!this._isOptimisticUpdate && fragment.isTrackingEnabled()) {
|
184
|
-
this._writer.setHasFragmentData(recordID, fragment.getCompositeHash());
|
185
|
-
}
|
186
|
-
|
187
|
-
var path = require("./RelayQueryPath").getPath(state.path, fragment, recordID);
|
188
|
-
|
189
|
-
this.traverse(fragment, (0, _objectSpread2["default"])({}, state, {
|
190
|
-
path: path
|
191
|
-
}));
|
192
|
-
}
|
193
|
-
};
|
194
|
-
|
195
|
-
_proto.visitField = function visitField(field, state) {
|
196
|
-
var recordID = state.recordID,
|
197
|
-
responseData = state.responseData;
|
198
|
-
!(this._writer.getRecordState(recordID) === require("./RelayClassicRecordState").EXISTENT) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryWriter: Cannot update a non-existent record, `%s`.', recordID) : require("fbjs/lib/invariant")(false) : void 0;
|
199
|
-
!(typeof responseData === 'object' && responseData !== null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryWriter: Cannot update record `%s`, expected response to be ' + 'an object.', recordID) : require("fbjs/lib/invariant")(false) : void 0;
|
200
|
-
var serializationKey = field.getSerializationKey();
|
201
|
-
var fieldData = responseData[serializationKey]; // Queried fields that are `undefined` are stored as nulls.
|
202
|
-
|
203
|
-
if (fieldData == null) {
|
204
|
-
if (fieldData === undefined) {
|
205
|
-
if (responseData.hasOwnProperty(serializationKey)) {
|
206
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayQueryWriter: Encountered an explicit `undefined` field `%s` ' + 'on record `%s`, expected response to not contain `undefined`.', field.getDebugName(), recordID) : void 0;
|
207
|
-
return;
|
208
|
-
} else if (this._isOptimisticUpdate) {
|
209
|
-
return;
|
210
|
-
}
|
211
|
-
}
|
212
|
-
|
213
|
-
var storageKey = field.getStorageKey();
|
214
|
-
|
215
|
-
var prevValue = this._store.getField(recordID, storageKey); // Always write to ensure data is stored in the correct recordStore.
|
216
|
-
|
217
|
-
|
218
|
-
this._writer.deleteField(recordID, storageKey);
|
219
|
-
|
220
|
-
if (prevValue !== null) {
|
221
|
-
this.recordUpdate(recordID);
|
222
|
-
}
|
223
|
-
|
224
|
-
return;
|
225
|
-
}
|
226
|
-
|
227
|
-
if (!field.canHaveSubselections()) {
|
228
|
-
this._writeScalar(field, state, recordID, fieldData);
|
229
|
-
} else if (field.isConnection()) {
|
230
|
-
this._writeConnection(field, state, recordID, fieldData);
|
231
|
-
} else if (field.isPlural()) {
|
232
|
-
this._writePluralLink(field, state, recordID, fieldData);
|
233
|
-
} else {
|
234
|
-
this._writeLink(field, state, recordID, fieldData);
|
235
|
-
}
|
236
|
-
};
|
237
|
-
/**
|
238
|
-
* Writes the value for a 'scalar' field such as `id` or `name`. The response
|
239
|
-
* data is expected to be scalar values or arrays of scalar values.
|
240
|
-
*/
|
241
|
-
|
242
|
-
|
243
|
-
_proto._writeScalar = function _writeScalar(field, state, recordID, nextValue) {
|
244
|
-
var storageKey = field.getStorageKey();
|
245
|
-
|
246
|
-
var prevValue = this._store.getField(recordID, storageKey); // always update the store to ensure the value is present in the appropriate
|
247
|
-
// data sink (records/queuedRecords), but only record an update if the value
|
248
|
-
// changed.
|
249
|
-
|
250
|
-
|
251
|
-
this._writer.putField(recordID, storageKey, nextValue); // TODO: Flow: `nextValue` is an array, array indexing should work
|
252
|
-
|
253
|
-
|
254
|
-
if (Array.isArray(prevValue) && Array.isArray(nextValue) && prevValue.length === nextValue.length && prevValue.every(function (prev, ii) {
|
255
|
-
return prev === nextValue[ii];
|
256
|
-
})) {
|
257
|
-
return;
|
258
|
-
} else if (prevValue === nextValue) {
|
259
|
-
return;
|
260
|
-
}
|
261
|
-
|
262
|
-
this.recordUpdate(recordID);
|
263
|
-
};
|
264
|
-
/**
|
265
|
-
* Writes data for connection fields such as `news_feed` or `friends`. The
|
266
|
-
* response data is expected to be array of edge objects.
|
267
|
-
*/
|
268
|
-
|
269
|
-
|
270
|
-
_proto._writeConnection = function _writeConnection(field, state, recordID, connectionData) {
|
271
|
-
var _ConnectionInterface$ = require("relay-runtime").ConnectionInterface.get(),
|
272
|
-
EDGES = _ConnectionInterface$.EDGES; // Each unique combination of filter calls is stored in its own
|
273
|
-
// generated record (ex: `field.orderby(x)` results are separate from
|
274
|
-
// `field.orderby(y)` results).
|
275
|
-
|
276
|
-
|
277
|
-
var storageKey = field.getStorageKey();
|
278
|
-
|
279
|
-
var connectionID = this._store.getLinkedRecordID(recordID, storageKey) || require("./generateClientID")();
|
280
|
-
|
281
|
-
var connectionRecordState = this._store.getRecordState(connectionID);
|
282
|
-
|
283
|
-
var hasEdges = !!(field.getFieldByStorageKey(EDGES) || connectionData != null && typeof connectionData === 'object' && connectionData[EDGES]);
|
284
|
-
|
285
|
-
var path = require("./RelayQueryPath").getPath(state.path, field, connectionID); // always update the store to ensure the value is present in the appropriate
|
286
|
-
// data sink (records/queuedRecords), but only record an update if the value
|
287
|
-
// changed.
|
288
|
-
|
289
|
-
|
290
|
-
this._writer.putRecord(connectionID, null, path);
|
291
|
-
|
292
|
-
this._writer.putLinkedRecordID(recordID, storageKey, connectionID); // record the create/update only if something changed
|
293
|
-
|
294
|
-
|
295
|
-
if (connectionRecordState !== require("./RelayClassicRecordState").EXISTENT) {
|
296
|
-
this.recordUpdate(recordID);
|
297
|
-
this.recordCreate(connectionID);
|
298
|
-
}
|
299
|
-
|
300
|
-
if (hasEdges) {
|
301
|
-
// Only create a range if `edges` field is present
|
302
|
-
// Overwrite an existing range only if the new force index is greater
|
303
|
-
if (!this._writer.hasRange(connectionID) || this._forceIndex && this._forceIndex > this._store.getRangeForceIndex(connectionID)) {
|
304
|
-
this._writer.putRange(connectionID, field.getCallsWithValues(), this._forceIndex);
|
305
|
-
} // Update the connection record regardless of whether a range was written
|
306
|
-
// to also handle cases like an empty edge range or updated page_info.
|
307
|
-
|
308
|
-
|
309
|
-
this.recordUpdate(connectionID);
|
310
|
-
}
|
311
|
-
|
312
|
-
var connectionState = {
|
313
|
-
nodeID: null,
|
314
|
-
path: path,
|
315
|
-
recordID: connectionID,
|
316
|
-
responseData: connectionData
|
317
|
-
};
|
318
|
-
|
319
|
-
this._traverseConnection(field, field, connectionState);
|
320
|
-
};
|
321
|
-
/**
|
322
|
-
* Recurse through connection subfields and write their results. This is
|
323
|
-
* necessary because handling an `edges` field also requires information about
|
324
|
-
* the parent connection field (see `_writeEdges`).
|
325
|
-
*/
|
326
|
-
|
327
|
-
|
328
|
-
_proto._traverseConnection = function _traverseConnection(connection, // the parent connection
|
329
|
-
node, // the parent connection or an intermediary fragment
|
330
|
-
state) {
|
331
|
-
var _this3 = this;
|
332
|
-
|
333
|
-
var _ConnectionInterface$2 = require("relay-runtime").ConnectionInterface.get(),
|
334
|
-
EDGES = _ConnectionInterface$2.EDGES,
|
335
|
-
PAGE_INFO = _ConnectionInterface$2.PAGE_INFO;
|
336
|
-
|
337
|
-
node.getChildren().forEach(function (child) {
|
338
|
-
if (child instanceof require("./RelayQuery").Field) {
|
339
|
-
if (child.getSchemaName() === EDGES) {
|
340
|
-
_this3._writeEdges(connection, child, state);
|
341
|
-
} else if (child.getSchemaName() !== PAGE_INFO) {
|
342
|
-
// Page info is handled by the range
|
343
|
-
// Otherwise, write metadata fields normally (ex: `count`)
|
344
|
-
_this3.visit(child, state);
|
345
|
-
}
|
346
|
-
} else {
|
347
|
-
// Fragment case, recurse keeping track of parent connection
|
348
|
-
_this3._traverseConnection(connection, child, state);
|
349
|
-
}
|
350
|
-
});
|
351
|
-
};
|
352
|
-
/**
|
353
|
-
* Update a connection with newly fetched edges.
|
354
|
-
*/
|
355
|
-
|
356
|
-
|
357
|
-
_proto._writeEdges = function _writeEdges(connection, edges, state) {
|
358
|
-
var _this4 = this;
|
359
|
-
|
360
|
-
var _ConnectionInterface$3 = require("relay-runtime").ConnectionInterface.get(),
|
361
|
-
EDGES = _ConnectionInterface$3.EDGES,
|
362
|
-
NODE = _ConnectionInterface$3.NODE,
|
363
|
-
PAGE_INFO = _ConnectionInterface$3.PAGE_INFO;
|
364
|
-
|
365
|
-
var connectionID = state.recordID,
|
366
|
-
connectionData = state.responseData;
|
367
|
-
!(typeof connectionData === 'object' && connectionData !== null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryWriter: Cannot write edges for malformed connection `%s` on ' + 'record `%s`, expected the response to be an object.', connection.getDebugName(), connectionID) : require("fbjs/lib/invariant")(false) : void 0;
|
368
|
-
var edgesData = connectionData[EDGES]; // Validate response data.
|
369
|
-
|
370
|
-
if (edgesData == null) {
|
371
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayQueryWriter: Cannot write edges for connection `%s` on record ' + '`%s`, expected a response for field `edges`.', connection.getDebugName(), connectionID) : void 0;
|
372
|
-
return;
|
373
|
-
}
|
374
|
-
|
375
|
-
!Array.isArray(edgesData) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryWriter: Cannot write edges for connection `%s` on record ' + '`%s`, expected `edges` to be an array.', connection.getDebugName(), connectionID) : require("fbjs/lib/invariant")(false) : void 0;
|
376
|
-
var rangeCalls = connection.getCallsWithValues();
|
377
|
-
!require("relay-runtime").ConnectionInterface.hasRangeCalls(rangeCalls) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryWriter: Cannot write edges for connection on record ' + '`%s` without `first`, `last`, or `find` argument.', connectionID) : require("fbjs/lib/invariant")(false) : void 0;
|
378
|
-
|
379
|
-
var rangeInfo = this._store.getRangeMetadata(connectionID, rangeCalls);
|
380
|
-
|
381
|
-
!rangeInfo ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryWriter: Expected a range to exist for connection field `%s` ' + 'on record `%s`.', connection.getDebugName(), connectionID) : require("fbjs/lib/invariant")(false) : void 0;
|
382
|
-
var fetchedEdgeIDs = [];
|
383
|
-
var filteredEdges = rangeInfo.filteredEdges;
|
384
|
-
var isUpdate = false;
|
385
|
-
var nextIndex = 0; // Traverse connection edges, reusing existing edges if they exist
|
386
|
-
|
387
|
-
edgesData.forEach(function (edgeData) {
|
388
|
-
// validate response data
|
389
|
-
if (edgeData == null) {
|
390
|
-
return;
|
391
|
-
}
|
392
|
-
|
393
|
-
!(typeof edgeData === 'object' && edgeData) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryWriter: Cannot write edge for connection field `%s` on ' + 'record `%s`, expected an object.', connection.getDebugName(), connectionID) : require("fbjs/lib/invariant")(false) : void 0;
|
394
|
-
var nodeData = edgeData[NODE];
|
395
|
-
|
396
|
-
if (nodeData == null) {
|
397
|
-
return;
|
398
|
-
}
|
399
|
-
|
400
|
-
!(typeof nodeData === 'object') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryWriter: Expected node to be an object for field `%s` on ' + 'record `%s`.', connection.getDebugName(), connectionID) : require("fbjs/lib/invariant")(false) : void 0; // For consistency, edge IDs are calculated from the connection & node ID.
|
401
|
-
// A node ID is only generated if the node does not have an id and
|
402
|
-
// there is no existing edge.
|
403
|
-
|
404
|
-
var prevEdge = filteredEdges[nextIndex++];
|
405
|
-
|
406
|
-
var nodeID = nodeData && nodeData[require("./RelayNodeInterface").ID] || prevEdge && _this4._store.getLinkedRecordID(prevEdge.edgeID, NODE) || require("./generateClientID")(); // TODO: Flow: `nodeID` is `string`
|
407
|
-
// $FlowFixMe(>=0.33.0)
|
408
|
-
|
409
|
-
|
410
|
-
var edgeID = require("./generateClientEdgeID")(connectionID, nodeID);
|
411
|
-
|
412
|
-
var path = require("./RelayQueryPath").getPath(state.path, edges, edgeID);
|
413
|
-
|
414
|
-
_this4.createRecordIfMissing(edges, edgeID, path, null);
|
415
|
-
|
416
|
-
fetchedEdgeIDs.push(edgeID); // Write data for the edge, using `nodeID` as the id for direct descendant
|
417
|
-
// `node` fields. This is necessary for `node`s that do not have an `id`,
|
418
|
-
// which would cause the generated ID here to not match the ID generated
|
419
|
-
// in `_writeLink`.
|
420
|
-
|
421
|
-
_this4.traverse(edges, {
|
422
|
-
/* $FlowFixMe(>=0.66.0) This comment suppresses an error found when Flow
|
423
|
-
* v0.66 was deployed. To see the error delete this comment and
|
424
|
-
* run Flow. */
|
425
|
-
nodeID: nodeID,
|
426
|
-
path: path,
|
427
|
-
recordID: edgeID,
|
428
|
-
responseData: edgeData
|
429
|
-
});
|
430
|
-
|
431
|
-
isUpdate = isUpdate || !prevEdge || edgeID !== prevEdge.edgeID;
|
432
|
-
});
|
433
|
-
|
434
|
-
var pageInfo = connectionData[PAGE_INFO] || require("relay-runtime").ConnectionInterface.getDefaultPageInfo();
|
435
|
-
|
436
|
-
this._writer.putRangeEdges(connectionID, rangeCalls, pageInfo, fetchedEdgeIDs); // Only broadcast an update to the range if an edge was added/changed.
|
437
|
-
// Node-level changes will broadcast at the node ID.
|
438
|
-
|
439
|
-
|
440
|
-
if (isUpdate) {
|
441
|
-
this.recordUpdate(connectionID);
|
442
|
-
}
|
443
|
-
};
|
444
|
-
/**
|
445
|
-
* Writes a plural linked field such as `actors`. The response data is
|
446
|
-
* expected to be an array of item objects. These fields are similar to
|
447
|
-
* connections, but do not support range calls such as `first` or `after`.
|
448
|
-
*/
|
449
|
-
|
450
|
-
|
451
|
-
_proto._writePluralLink = function _writePluralLink(field, state, recordID, fieldData) {
|
452
|
-
var _this5 = this;
|
453
|
-
|
454
|
-
var storageKey = field.getStorageKey();
|
455
|
-
!Array.isArray(fieldData) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryWriter: Expected array data for field `%s` on record `%s`.', field.getDebugName(), recordID) : require("fbjs/lib/invariant")(false) : void 0;
|
456
|
-
|
457
|
-
var prevLinkedIDs = this._store.getLinkedRecordIDs(recordID, storageKey);
|
458
|
-
|
459
|
-
var nextLinkedIDs = [];
|
460
|
-
var nextRecords = {};
|
461
|
-
var isUpdate = false;
|
462
|
-
var nextIndex = 0;
|
463
|
-
fieldData.forEach(function (nextRecord) {
|
464
|
-
// validate response data
|
465
|
-
if (nextRecord == null) {
|
466
|
-
return;
|
467
|
-
}
|
468
|
-
|
469
|
-
!(typeof nextRecord === 'object' && nextRecord) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryWriter: Expected elements for plural field `%s` to be ' + 'objects.', storageKey) : require("fbjs/lib/invariant")(false) : void 0; // Reuse existing generated IDs if the node does not have its own `id`.
|
470
|
-
|
471
|
-
var prevLinkedID = prevLinkedIDs && prevLinkedIDs[nextIndex];
|
472
|
-
|
473
|
-
var nextLinkedID = nextRecord[require("./RelayNodeInterface").ID] || prevLinkedID || require("./generateClientID")();
|
474
|
-
|
475
|
-
nextLinkedIDs.push(nextLinkedID); // $FlowFixMe(>=0.33.0)
|
476
|
-
|
477
|
-
var path = require("./RelayQueryPath").getPath(state.path, field, nextLinkedID); // $FlowFixMe(>=0.33.0)
|
478
|
-
|
479
|
-
|
480
|
-
_this5.createRecordIfMissing(field, nextLinkedID, path, nextRecord); // $FlowFixMe(>=0.33.0)
|
481
|
-
|
482
|
-
|
483
|
-
nextRecords[nextLinkedID] = {
|
484
|
-
record: nextRecord,
|
485
|
-
path: path
|
486
|
-
};
|
487
|
-
isUpdate = isUpdate || nextLinkedID !== prevLinkedID;
|
488
|
-
nextIndex++;
|
489
|
-
}); // Write the linked records before traverse to prevent generating extraneous
|
490
|
-
// client ids.
|
491
|
-
|
492
|
-
/* $FlowFixMe(>=0.66.0) This comment suppresses an error found when Flow
|
493
|
-
* v0.66 was deployed. To see the error delete this comment and run Flow. */
|
494
|
-
|
495
|
-
this._writer.putLinkedRecordIDs(recordID, storageKey, nextLinkedIDs);
|
496
|
-
|
497
|
-
nextLinkedIDs.forEach(function (nextLinkedID) {
|
498
|
-
/* $FlowFixMe(>=0.54.0) This comment suppresses an
|
499
|
-
* error found when Flow v0.54 was deployed. To see the error delete this
|
500
|
-
* comment and run Flow. */
|
501
|
-
var itemData = nextRecords[nextLinkedID];
|
502
|
-
|
503
|
-
if (itemData) {
|
504
|
-
_this5.traverse(field, {
|
505
|
-
nodeID: null,
|
506
|
-
// never propagate `nodeID` past the first linked field
|
507
|
-
path: itemData.path,
|
508
|
-
|
509
|
-
/* $FlowFixMe(>=0.66.0) This comment suppresses an error found when
|
510
|
-
* Flow v0.66 was deployed. To see the error delete this comment and
|
511
|
-
* run Flow. */
|
512
|
-
recordID: nextLinkedID,
|
513
|
-
responseData: itemData.record
|
514
|
-
});
|
515
|
-
}
|
516
|
-
}); // Only broadcast a list-level change if a record was changed/added/removed
|
517
|
-
|
518
|
-
if (isUpdate || !prevLinkedIDs || prevLinkedIDs.length !== nextLinkedIDs.length) {
|
519
|
-
this.recordUpdate(recordID);
|
520
|
-
}
|
521
|
-
};
|
522
|
-
/**
|
523
|
-
* Writes a link from one record to another, for example linking the `viewer`
|
524
|
-
* record to the `actor` record in the query `viewer { actor }`. The `field`
|
525
|
-
* variable is the field being linked (`actor` in the example).
|
526
|
-
*/
|
527
|
-
|
528
|
-
|
529
|
-
_proto._writeLink = function _writeLink(field, state, recordID, fieldData) {
|
530
|
-
var _ConnectionInterface$4 = require("relay-runtime").ConnectionInterface.get(),
|
531
|
-
NODE = _ConnectionInterface$4.NODE;
|
532
|
-
|
533
|
-
var nodeID = state.nodeID;
|
534
|
-
var storageKey = field.getStorageKey();
|
535
|
-
!(typeof fieldData === 'object' && fieldData !== null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryWriter: Expected data for non-scalar field `%s` on record ' + '`%s` to be an object.', field.getDebugName(), recordID) : require("fbjs/lib/invariant")(false) : void 0; // Prefer the actual `id` if present, otherwise generate one (if an id
|
536
|
-
// was already generated it is reused). `node`s within a connection are
|
537
|
-
// a special case as the ID used here must match the one generated prior to
|
538
|
-
// storing the parent `edge`.
|
539
|
-
|
540
|
-
var prevLinkedID = this._store.getLinkedRecordID(recordID, storageKey);
|
541
|
-
|
542
|
-
var nextLinkedID = field.getSchemaName() === NODE && nodeID || fieldData[require("./RelayNodeInterface").ID] || prevLinkedID || require("./generateClientID")(); // $FlowFixMe(>=0.33.0)
|
543
|
-
|
544
|
-
|
545
|
-
var path = require("./RelayQueryPath").getPath(state.path, field, nextLinkedID); // $FlowFixMe(>=0.33.0)
|
546
|
-
|
547
|
-
|
548
|
-
this.createRecordIfMissing(field, nextLinkedID, path, fieldData); // always update the store to ensure the value is present in the appropriate
|
549
|
-
// data sink (record/queuedRecords), but only record an update if the value
|
550
|
-
// changed.
|
551
|
-
// $FlowFixMe(>=0.33.0)
|
552
|
-
|
553
|
-
this._writer.putLinkedRecordID(recordID, storageKey, nextLinkedID);
|
554
|
-
|
555
|
-
if (prevLinkedID !== nextLinkedID) {
|
556
|
-
this.recordUpdate(recordID);
|
557
|
-
}
|
558
|
-
|
559
|
-
this.traverse(field, {
|
560
|
-
nodeID: null,
|
561
|
-
path: path,
|
562
|
-
|
563
|
-
/* $FlowFixMe(>=0.66.0) This comment suppresses an error found when Flow
|
564
|
-
* v0.66 was deployed. To see the error delete this comment and run Flow. */
|
565
|
-
recordID: nextLinkedID,
|
566
|
-
responseData: fieldData
|
567
|
-
});
|
568
|
-
};
|
569
|
-
|
570
|
-
return RelayQueryWriter;
|
571
|
-
}(require("./RelayQueryVisitor"));
|
572
|
-
|
573
|
-
module.exports = RelayQueryWriter;
|
package/lib/RelayReadyState.js
DELETED
@@ -1,83 +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 _toConsumableArray2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/toConsumableArray"));
|
15
|
-
|
16
|
-
/**
|
17
|
-
* @internal
|
18
|
-
*/
|
19
|
-
var RelayReadyState =
|
20
|
-
/*#__PURE__*/
|
21
|
-
function () {
|
22
|
-
function RelayReadyState(onReadyStateChange) {
|
23
|
-
this._onReadyStateChange = onReadyStateChange;
|
24
|
-
this._readyState = {
|
25
|
-
aborted: false,
|
26
|
-
done: false,
|
27
|
-
error: null,
|
28
|
-
events: [],
|
29
|
-
ready: false,
|
30
|
-
stale: false
|
31
|
-
};
|
32
|
-
this._scheduled = false;
|
33
|
-
}
|
34
|
-
|
35
|
-
var _proto = RelayReadyState.prototype;
|
36
|
-
|
37
|
-
_proto.update = function update(nextReadyState, newEvents) {
|
38
|
-
var prevReadyState = this._readyState;
|
39
|
-
|
40
|
-
if (prevReadyState.aborted) {
|
41
|
-
return;
|
42
|
-
}
|
43
|
-
|
44
|
-
if (prevReadyState.done || prevReadyState.error) {
|
45
|
-
if (nextReadyState.stale) {
|
46
|
-
if (prevReadyState.error) {
|
47
|
-
this._mergeState(nextReadyState, newEvents);
|
48
|
-
} // Do nothing if stale data comes after server data.
|
49
|
-
|
50
|
-
} else if (!nextReadyState.aborted) {
|
51
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayReadyState: Invalid state change from `%s` to `%s`.', JSON.stringify(prevReadyState), JSON.stringify(nextReadyState)) : void 0;
|
52
|
-
}
|
53
|
-
|
54
|
-
return;
|
55
|
-
}
|
56
|
-
|
57
|
-
this._mergeState(nextReadyState, newEvents);
|
58
|
-
};
|
59
|
-
|
60
|
-
_proto._mergeState = function _mergeState(nextReadyState, newEvents) {
|
61
|
-
var _this = this;
|
62
|
-
|
63
|
-
this._readyState = (0, _objectSpread2["default"])({}, this._readyState, nextReadyState, {
|
64
|
-
events: newEvents && newEvents.length ? (0, _toConsumableArray2["default"])(this._readyState.events).concat((0, _toConsumableArray2["default"])(newEvents)) : this._readyState.events
|
65
|
-
});
|
66
|
-
|
67
|
-
if (this._scheduled) {
|
68
|
-
return;
|
69
|
-
}
|
70
|
-
|
71
|
-
this._scheduled = true;
|
72
|
-
|
73
|
-
require("fbjs/lib/resolveImmediate")(function () {
|
74
|
-
_this._scheduled = false;
|
75
|
-
|
76
|
-
_this._onReadyStateChange(_this._readyState);
|
77
|
-
});
|
78
|
-
};
|
79
|
-
|
80
|
-
return RelayReadyState;
|
81
|
-
}();
|
82
|
-
|
83
|
-
module.exports = RelayReadyState;
|