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/RelayRecordWriter.js
DELETED
@@ -1,601 +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 EMPTY = '';
|
13
|
-
|
14
|
-
var APPEND = require("relay-runtime").RangeOperations.APPEND,
|
15
|
-
PREPEND = require("relay-runtime").RangeOperations.PREPEND,
|
16
|
-
REMOVE = require("relay-runtime").RangeOperations.REMOVE;
|
17
|
-
|
18
|
-
var FILTER_CALLS = require("./RelayRecord").MetadataKey.FILTER_CALLS,
|
19
|
-
FORCE_INDEX = require("./RelayRecord").MetadataKey.FORCE_INDEX,
|
20
|
-
MUTATION_IDS = require("./RelayRecord").MetadataKey.MUTATION_IDS,
|
21
|
-
PATH = require("./RelayRecord").MetadataKey.PATH,
|
22
|
-
RANGE = require("./RelayRecord").MetadataKey.RANGE,
|
23
|
-
RESOLVED_FRAGMENT_MAP = require("./RelayRecord").MetadataKey.RESOLVED_FRAGMENT_MAP,
|
24
|
-
RESOLVED_FRAGMENT_MAP_GENERATION = require("./RelayRecord").MetadataKey.RESOLVED_FRAGMENT_MAP_GENERATION,
|
25
|
-
STATUS = require("./RelayRecord").MetadataKey.STATUS;
|
26
|
-
/**
|
27
|
-
* @internal
|
28
|
-
*
|
29
|
-
* `RelayRecordWriter` is the helper module to write data into RelayRecordStore.
|
30
|
-
*/
|
31
|
-
|
32
|
-
|
33
|
-
var RelayRecordWriter =
|
34
|
-
/*#__PURE__*/
|
35
|
-
function () {
|
36
|
-
function RelayRecordWriter(records, rootCallMap, isOptimistic, nodeConnectionMap, cacheWriter, clientMutationID) {
|
37
|
-
this._cacheWriter = cacheWriter;
|
38
|
-
this._clientMutationID = clientMutationID;
|
39
|
-
this._isOptimisticWrite = isOptimistic;
|
40
|
-
this._nodeConnectionMap = nodeConnectionMap || {};
|
41
|
-
this._records = records;
|
42
|
-
this._rootCallMap = rootCallMap;
|
43
|
-
}
|
44
|
-
/**
|
45
|
-
* Get the data ID associated with a storage key (and optionally an
|
46
|
-
* identifying argument value) for a root query.
|
47
|
-
*/
|
48
|
-
|
49
|
-
|
50
|
-
var _proto = RelayRecordWriter.prototype;
|
51
|
-
|
52
|
-
_proto.getDataID = function getDataID(storageKey, identifyingArgValue) {
|
53
|
-
if (require("./RelayNodeInterface").isNodeRootCall(storageKey)) {
|
54
|
-
!(identifyingArgValue != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter.getDataID(): Argument to `%s()` ' + 'cannot be null or undefined.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
|
55
|
-
return identifyingArgValue;
|
56
|
-
}
|
57
|
-
|
58
|
-
if (identifyingArgValue == null) {
|
59
|
-
identifyingArgValue = EMPTY;
|
60
|
-
}
|
61
|
-
|
62
|
-
if (this._rootCallMap.hasOwnProperty(storageKey) && this._rootCallMap[storageKey].hasOwnProperty(identifyingArgValue)) {
|
63
|
-
return this._rootCallMap[storageKey][identifyingArgValue];
|
64
|
-
}
|
65
|
-
};
|
66
|
-
/**
|
67
|
-
* Associate a data ID with a storage key (and optionally an identifying
|
68
|
-
* argument value) for a root query.
|
69
|
-
*/
|
70
|
-
|
71
|
-
|
72
|
-
_proto.putDataID = function putDataID(storageKey, identifyingArgValue, dataID) {
|
73
|
-
if (require("./RelayNodeInterface").isNodeRootCall(storageKey)) {
|
74
|
-
!(identifyingArgValue != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter.putDataID(): Argument to `%s()` ' + 'cannot be null or undefined.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
|
75
|
-
return;
|
76
|
-
}
|
77
|
-
|
78
|
-
if (identifyingArgValue == null) {
|
79
|
-
identifyingArgValue = EMPTY;
|
80
|
-
}
|
81
|
-
|
82
|
-
this._rootCallMap[storageKey] = this._rootCallMap[storageKey] || {};
|
83
|
-
this._rootCallMap[storageKey][identifyingArgValue] = dataID;
|
84
|
-
|
85
|
-
if (this._cacheWriter) {
|
86
|
-
this._cacheWriter.writeRootCall(storageKey, identifyingArgValue, dataID);
|
87
|
-
}
|
88
|
-
};
|
89
|
-
/**
|
90
|
-
* Returns the status of the record stored at `dataID`.
|
91
|
-
*/
|
92
|
-
|
93
|
-
|
94
|
-
_proto.getRecordState = function getRecordState(dataID) {
|
95
|
-
var record = this._records[dataID];
|
96
|
-
|
97
|
-
if (record === null) {
|
98
|
-
return 'NONEXISTENT';
|
99
|
-
} else if (record === undefined) {
|
100
|
-
return 'UNKNOWN';
|
101
|
-
}
|
102
|
-
|
103
|
-
return 'EXISTENT';
|
104
|
-
};
|
105
|
-
/**
|
106
|
-
* Create an empty record at `dataID` if a record does not already exist.
|
107
|
-
*/
|
108
|
-
|
109
|
-
|
110
|
-
_proto.putRecord = function putRecord(dataID, typeName, path) {
|
111
|
-
var prevRecord = this._getRecordForWrite(dataID);
|
112
|
-
|
113
|
-
if (prevRecord) {
|
114
|
-
return;
|
115
|
-
}
|
116
|
-
|
117
|
-
var nextRecord = require("./RelayRecord").createWithFields(dataID, {
|
118
|
-
__typename: typeName
|
119
|
-
});
|
120
|
-
|
121
|
-
if (this._isOptimisticWrite) {
|
122
|
-
this._setClientMutationID(nextRecord);
|
123
|
-
}
|
124
|
-
|
125
|
-
if (require("./RelayRecord").isClientID(dataID) && path) {
|
126
|
-
nextRecord[PATH] = path;
|
127
|
-
}
|
128
|
-
|
129
|
-
this._records[dataID] = nextRecord;
|
130
|
-
var cacheWriter = this._cacheWriter;
|
131
|
-
|
132
|
-
if (!this._isOptimisticWrite && cacheWriter) {
|
133
|
-
cacheWriter.writeField(dataID, '__dataID__', dataID, typeName);
|
134
|
-
}
|
135
|
-
};
|
136
|
-
/**
|
137
|
-
* Returns the path to a non-refetchable record.
|
138
|
-
*/
|
139
|
-
|
140
|
-
|
141
|
-
_proto.getPathToRecord = function getPathToRecord(dataID) {
|
142
|
-
return this._getField(dataID, PATH);
|
143
|
-
};
|
144
|
-
/**
|
145
|
-
* Check whether a given record has received data for a deferred fragment.
|
146
|
-
*/
|
147
|
-
|
148
|
-
|
149
|
-
_proto.hasFragmentData = function hasFragmentData(dataID, fragmentID) {
|
150
|
-
var resolvedFragmentMap = this._getField(dataID, RESOLVED_FRAGMENT_MAP);
|
151
|
-
|
152
|
-
!(typeof resolvedFragmentMap === 'object' || resolvedFragmentMap == null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter.hasFragmentData(): Expected the map of ' + 'resolved deferred fragments associated with record `%s` to be null or ' + 'an object. Found a(n) `%s`.', dataID, typeof resolvedFragmentMap) : require("fbjs/lib/invariant")(false) : void 0;
|
153
|
-
return !!(resolvedFragmentMap && resolvedFragmentMap[fragmentID]);
|
154
|
-
};
|
155
|
-
/**
|
156
|
-
* Mark a given record as having received data for a deferred fragment.
|
157
|
-
*/
|
158
|
-
|
159
|
-
|
160
|
-
_proto.setHasDeferredFragmentData = function setHasDeferredFragmentData(dataID, fragmentID) {
|
161
|
-
this._setHasFragmentData(dataID, fragmentID, true);
|
162
|
-
};
|
163
|
-
/**
|
164
|
-
* Mark a given record as having received data for a fragment.
|
165
|
-
*/
|
166
|
-
|
167
|
-
|
168
|
-
_proto.setHasFragmentData = function setHasFragmentData(dataID, fragmentID) {
|
169
|
-
this._setHasFragmentData(dataID, fragmentID, false);
|
170
|
-
};
|
171
|
-
|
172
|
-
_proto._setHasFragmentData = function _setHasFragmentData(dataID, fragmentID, updateFragmentGeneration) {
|
173
|
-
var record = this._getRecordForWrite(dataID);
|
174
|
-
|
175
|
-
!record ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter.setHasFragmentData(): Expected record `%s` ' + 'to exist before marking it as having received data for the deferred ' + 'fragment with id `%s`.', dataID, fragmentID) : require("fbjs/lib/invariant")(false) : void 0;
|
176
|
-
var resolvedFragmentMap = record[RESOLVED_FRAGMENT_MAP];
|
177
|
-
|
178
|
-
if (typeof resolvedFragmentMap !== 'object' || !resolvedFragmentMap) {
|
179
|
-
resolvedFragmentMap = {};
|
180
|
-
}
|
181
|
-
|
182
|
-
resolvedFragmentMap[fragmentID] = true;
|
183
|
-
record[RESOLVED_FRAGMENT_MAP] = resolvedFragmentMap;
|
184
|
-
|
185
|
-
if (updateFragmentGeneration) {
|
186
|
-
if (typeof record[RESOLVED_FRAGMENT_MAP_GENERATION] === 'number') {
|
187
|
-
record[RESOLVED_FRAGMENT_MAP_GENERATION]++;
|
188
|
-
} else {
|
189
|
-
record[RESOLVED_FRAGMENT_MAP_GENERATION] = 0;
|
190
|
-
}
|
191
|
-
}
|
192
|
-
};
|
193
|
-
/**
|
194
|
-
* Delete the record at `dataID`, setting its value to `null`.
|
195
|
-
*/
|
196
|
-
|
197
|
-
|
198
|
-
_proto.deleteRecord = function deleteRecord(dataID) {
|
199
|
-
this._records[dataID] = null; // Remove any links for this record
|
200
|
-
|
201
|
-
if (!this._isOptimisticWrite) {
|
202
|
-
delete this._nodeConnectionMap[dataID];
|
203
|
-
|
204
|
-
if (this._cacheWriter) {
|
205
|
-
this._cacheWriter.writeNode(dataID, null);
|
206
|
-
}
|
207
|
-
}
|
208
|
-
};
|
209
|
-
|
210
|
-
_proto.getType = function getType(dataID) {
|
211
|
-
// `__typename` property is typed as `string`
|
212
|
-
return this._getField(dataID, '__typename');
|
213
|
-
};
|
214
|
-
/**
|
215
|
-
* Returns the value of the field for the given dataID.
|
216
|
-
*/
|
217
|
-
|
218
|
-
|
219
|
-
_proto.getField = function getField(dataID, storageKey) {
|
220
|
-
return this._getField(dataID, storageKey);
|
221
|
-
};
|
222
|
-
/**
|
223
|
-
* Sets the value of a scalar field.
|
224
|
-
*/
|
225
|
-
|
226
|
-
|
227
|
-
_proto.putField = function putField(dataID, storageKey, value) {
|
228
|
-
var record = this._getRecordForWrite(dataID);
|
229
|
-
|
230
|
-
!record ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter.putField(): Expected record `%s` to exist before ' + 'writing field `%s`.', dataID, storageKey) : require("fbjs/lib/invariant")(false) : void 0;
|
231
|
-
record[storageKey] = value;
|
232
|
-
|
233
|
-
if (!this._isOptimisticWrite && this._cacheWriter) {
|
234
|
-
var typeName = record.__typename;
|
235
|
-
|
236
|
-
this._cacheWriter.writeField(dataID, storageKey, value, typeName);
|
237
|
-
}
|
238
|
-
};
|
239
|
-
/**
|
240
|
-
* Clears the value of a field by setting it to null/undefined.
|
241
|
-
*/
|
242
|
-
|
243
|
-
|
244
|
-
_proto.deleteField = function deleteField(dataID, storageKey) {
|
245
|
-
var record = this._getRecordForWrite(dataID);
|
246
|
-
|
247
|
-
!record ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter.deleteField(): Expected record `%s` to exist before ' + 'deleting field `%s`.', dataID, storageKey) : require("fbjs/lib/invariant")(false) : void 0;
|
248
|
-
record[storageKey] = null;
|
249
|
-
|
250
|
-
if (!this._isOptimisticWrite && this._cacheWriter) {
|
251
|
-
this._cacheWriter.writeField(dataID, storageKey, null);
|
252
|
-
}
|
253
|
-
};
|
254
|
-
/**
|
255
|
-
* Returns the Data ID of a linked record (eg the ID of the `address` record
|
256
|
-
* in `actor{address}`).
|
257
|
-
*/
|
258
|
-
|
259
|
-
|
260
|
-
_proto.getLinkedRecordID = function getLinkedRecordID(dataID, storageKey) {
|
261
|
-
var field = this._getField(dataID, storageKey);
|
262
|
-
|
263
|
-
if (field == null) {
|
264
|
-
return field;
|
265
|
-
}
|
266
|
-
|
267
|
-
var record = require("./RelayRecord").getRecord(field);
|
268
|
-
|
269
|
-
!record ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter.getLinkedRecordID(): Expected field `%s` for record ' + '`%s` to have a linked record.', storageKey, dataID) : require("fbjs/lib/invariant")(false) : void 0;
|
270
|
-
return require("./RelayRecord").getDataID(record);
|
271
|
-
};
|
272
|
-
/**
|
273
|
-
* Creates/updates a link between two records via the given field.
|
274
|
-
*/
|
275
|
-
|
276
|
-
|
277
|
-
_proto.putLinkedRecordID = function putLinkedRecordID(parentID, storageKey, recordID) {
|
278
|
-
var parent = this._getRecordForWrite(parentID);
|
279
|
-
|
280
|
-
!parent ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter.putLinkedRecordID(): Expected record `%s` to exist ' + 'before linking to record `%s`.', parentID, recordID) : require("fbjs/lib/invariant")(false) : void 0;
|
281
|
-
|
282
|
-
var fieldValue = require("./RelayRecord").create(recordID);
|
283
|
-
|
284
|
-
parent[storageKey] = fieldValue;
|
285
|
-
|
286
|
-
if (!this._isOptimisticWrite && this._cacheWriter) {
|
287
|
-
this._cacheWriter.writeField(parentID, storageKey, fieldValue);
|
288
|
-
}
|
289
|
-
};
|
290
|
-
/**
|
291
|
-
* Returns an array of Data ID for a plural linked field (eg the actor IDs of
|
292
|
-
* the `likers` in `story{likers}`).
|
293
|
-
*/
|
294
|
-
|
295
|
-
|
296
|
-
_proto.getLinkedRecordIDs = function getLinkedRecordIDs(dataID, storageKey) {
|
297
|
-
var field = this._getField(dataID, storageKey);
|
298
|
-
|
299
|
-
if (field == null) {
|
300
|
-
return field;
|
301
|
-
}
|
302
|
-
|
303
|
-
!Array.isArray(field) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter.getLinkedRecordIDs(): Expected field `%s` for ' + 'record `%s` to have an array of linked records.', storageKey, dataID) : require("fbjs/lib/invariant")(false) : void 0;
|
304
|
-
return field.map(function (element, ii) {
|
305
|
-
var record = require("./RelayRecord").getRecord(element);
|
306
|
-
|
307
|
-
!record ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter.getLinkedRecordIDs(): Expected element at index ' + '%s in field `%s` for record `%s` to be a linked record.', ii, storageKey, dataID) : require("fbjs/lib/invariant")(false) : void 0;
|
308
|
-
return require("./RelayRecord").getDataID(record);
|
309
|
-
});
|
310
|
-
};
|
311
|
-
/**
|
312
|
-
* Creates/updates a one-to-many link between records via the given field.
|
313
|
-
*/
|
314
|
-
|
315
|
-
|
316
|
-
_proto.putLinkedRecordIDs = function putLinkedRecordIDs(parentID, storageKey, recordIDs) {
|
317
|
-
var parent = this._getRecordForWrite(parentID);
|
318
|
-
|
319
|
-
!parent ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter.putLinkedRecordIDs(): Expected record `%s` to exist ' + 'before linking records.', parentID) : require("fbjs/lib/invariant")(false) : void 0;
|
320
|
-
var records = recordIDs.map(function (recordID) {
|
321
|
-
return require("./RelayRecord").create(recordID);
|
322
|
-
});
|
323
|
-
parent[storageKey] = records;
|
324
|
-
|
325
|
-
if (!this._isOptimisticWrite && this._cacheWriter) {
|
326
|
-
this._cacheWriter.writeField(parentID, storageKey, records);
|
327
|
-
}
|
328
|
-
};
|
329
|
-
/**
|
330
|
-
* Get the force index associated with the range at `connectionID`.
|
331
|
-
*/
|
332
|
-
|
333
|
-
|
334
|
-
_proto.getRangeForceIndex = function getRangeForceIndex(connectionID) {
|
335
|
-
var forceIndex = this._getField(connectionID, FORCE_INDEX);
|
336
|
-
|
337
|
-
if (forceIndex === null) {
|
338
|
-
return -1;
|
339
|
-
}
|
340
|
-
|
341
|
-
return forceIndex || 0;
|
342
|
-
};
|
343
|
-
/**
|
344
|
-
* Get the condition calls that were used to fetch the given connection.
|
345
|
-
* Ex: for a field `photos.orderby(recent)`, this would be
|
346
|
-
* [{name: 'orderby', value: 'recent'}]
|
347
|
-
*/
|
348
|
-
|
349
|
-
|
350
|
-
_proto.getRangeFilterCalls = function getRangeFilterCalls(connectionID) {
|
351
|
-
return this._getField(connectionID, FILTER_CALLS);
|
352
|
-
};
|
353
|
-
/**
|
354
|
-
* Creates a range at `dataID` with an optional `forceIndex`.
|
355
|
-
*/
|
356
|
-
|
357
|
-
|
358
|
-
_proto.putRange = function putRange(connectionID, calls, forceIndex) {
|
359
|
-
!!this._isOptimisticWrite ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter.putRange(): Cannot create a queued range.') : require("fbjs/lib/invariant")(false) : void 0;
|
360
|
-
|
361
|
-
var record = this._getRecordForWrite(connectionID);
|
362
|
-
|
363
|
-
!record ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter.putRange(): Expected record `%s` to exist before ' + 'adding a range.', connectionID) : require("fbjs/lib/invariant")(false) : void 0;
|
364
|
-
var range = new (require("./GraphQLRange"))();
|
365
|
-
var filterCalls = getFilterCalls(calls);
|
366
|
-
forceIndex = forceIndex || 0;
|
367
|
-
record[FILTER_CALLS] = filterCalls;
|
368
|
-
record[FORCE_INDEX] = forceIndex;
|
369
|
-
record[RANGE] = range;
|
370
|
-
var cacheWriter = this._cacheWriter;
|
371
|
-
|
372
|
-
if (!this._isOptimisticWrite && cacheWriter) {
|
373
|
-
cacheWriter.writeField(connectionID, FILTER_CALLS, filterCalls);
|
374
|
-
cacheWriter.writeField(connectionID, FORCE_INDEX, forceIndex);
|
375
|
-
cacheWriter.writeField(connectionID, RANGE, range);
|
376
|
-
}
|
377
|
-
};
|
378
|
-
/**
|
379
|
-
* Returns whether there is a range at `connectionID`.
|
380
|
-
*/
|
381
|
-
|
382
|
-
|
383
|
-
_proto.hasRange = function hasRange(connectionID) {
|
384
|
-
return !!this._getField(connectionID, RANGE);
|
385
|
-
};
|
386
|
-
/**
|
387
|
-
* Adds newly fetched edges to a range.
|
388
|
-
*/
|
389
|
-
|
390
|
-
|
391
|
-
_proto.putRangeEdges = function putRangeEdges(connectionID, calls, pageInfo, edges) {
|
392
|
-
var _this = this;
|
393
|
-
|
394
|
-
var range = this._getField(connectionID, RANGE);
|
395
|
-
|
396
|
-
!range ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter.putRangeEdges(): Expected record `%s` to exist and ' + 'have a range.', connectionID) : require("fbjs/lib/invariant")(false) : void 0;
|
397
|
-
var edgeRecords = [];
|
398
|
-
edges.forEach(function (edgeID) {
|
399
|
-
var edgeRecord = _this._getRangeEdgeRecord(edgeID);
|
400
|
-
|
401
|
-
edgeRecords.push(edgeRecord);
|
402
|
-
|
403
|
-
var nodeID = require("./RelayRecord").getDataID(edgeRecord.node);
|
404
|
-
|
405
|
-
_this._addConnectionForNode(connectionID, nodeID);
|
406
|
-
});
|
407
|
-
range.addItems(calls, edgeRecords, pageInfo);
|
408
|
-
|
409
|
-
if (!this._isOptimisticWrite && this._cacheWriter) {
|
410
|
-
this._cacheWriter.writeField(connectionID, RANGE, range);
|
411
|
-
}
|
412
|
-
};
|
413
|
-
/**
|
414
|
-
* Prepend, append, or delete edges to/from a range.
|
415
|
-
*/
|
416
|
-
|
417
|
-
|
418
|
-
_proto.applyRangeUpdate = function applyRangeUpdate(connectionID, edgeID, operation) {
|
419
|
-
if (this._isOptimisticWrite) {
|
420
|
-
this._applyOptimisticRangeUpdate(connectionID, edgeID, operation);
|
421
|
-
} else {
|
422
|
-
this._applyServerRangeUpdate(connectionID, edgeID, operation);
|
423
|
-
}
|
424
|
-
};
|
425
|
-
/**
|
426
|
-
* Get edge data in a format compatibile with `GraphQLRange`.
|
427
|
-
* TODO: change `GraphQLRange` to accept `(edgeID, cursor, nodeID)` tuple
|
428
|
-
*/
|
429
|
-
|
430
|
-
|
431
|
-
_proto._getRangeEdgeRecord = function _getRangeEdgeRecord(edgeID) {
|
432
|
-
var _ConnectionInterface$ = require("relay-runtime").ConnectionInterface.get(),
|
433
|
-
CURSOR = _ConnectionInterface$.CURSOR,
|
434
|
-
NODE = _ConnectionInterface$.NODE;
|
435
|
-
|
436
|
-
var nodeID = this.getLinkedRecordID(edgeID, NODE);
|
437
|
-
!nodeID ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter: Expected edge `%s` to have a `node` record.', edgeID) : require("fbjs/lib/invariant")(false) : void 0;
|
438
|
-
return require("./RelayRecord").createWithFields(edgeID, {
|
439
|
-
cursor: this.getField(edgeID, CURSOR),
|
440
|
-
node: require("./RelayRecord").create(nodeID)
|
441
|
-
});
|
442
|
-
};
|
443
|
-
|
444
|
-
_proto._applyOptimisticRangeUpdate = function _applyOptimisticRangeUpdate(connectionID, edgeID, operation) {
|
445
|
-
var record = this._getRecordForWrite(connectionID);
|
446
|
-
|
447
|
-
if (!record) {
|
448
|
-
record = require("./RelayRecord").create(connectionID);
|
449
|
-
this._records[connectionID] = record;
|
450
|
-
}
|
451
|
-
|
452
|
-
this._setClientMutationID(record);
|
453
|
-
|
454
|
-
var key = require("./rangeOperationToMetadataKey")[operation];
|
455
|
-
|
456
|
-
var queue = record[key];
|
457
|
-
|
458
|
-
if (!queue) {
|
459
|
-
queue = [];
|
460
|
-
record[key] = queue;
|
461
|
-
}
|
462
|
-
|
463
|
-
if (operation === PREPEND) {
|
464
|
-
queue.unshift(edgeID);
|
465
|
-
} else {
|
466
|
-
queue.push(edgeID);
|
467
|
-
}
|
468
|
-
};
|
469
|
-
|
470
|
-
_proto._applyServerRangeUpdate = function _applyServerRangeUpdate(connectionID, edgeID, operation) {
|
471
|
-
var range = this._getField(connectionID, RANGE);
|
472
|
-
|
473
|
-
!range ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter: Cannot apply `%s` update to non-existent record ' + '`%s`.', operation, connectionID) : require("fbjs/lib/invariant")(false) : void 0;
|
474
|
-
|
475
|
-
if (operation === REMOVE) {
|
476
|
-
range.removeEdgeWithID(edgeID);
|
477
|
-
var nodeID = this.getLinkedRecordID(edgeID, 'node');
|
478
|
-
|
479
|
-
if (nodeID) {
|
480
|
-
this._removeConnectionForNode(connectionID, nodeID);
|
481
|
-
}
|
482
|
-
} else {
|
483
|
-
var edgeRecord = this._getRangeEdgeRecord(edgeID);
|
484
|
-
|
485
|
-
var _nodeID = require("./RelayRecord").getDataID(edgeRecord.node);
|
486
|
-
|
487
|
-
this._addConnectionForNode(connectionID, _nodeID);
|
488
|
-
|
489
|
-
if (operation === APPEND) {
|
490
|
-
range.appendEdge(this._getRangeEdgeRecord(edgeID));
|
491
|
-
} else {
|
492
|
-
range.prependEdge(this._getRangeEdgeRecord(edgeID));
|
493
|
-
}
|
494
|
-
}
|
495
|
-
|
496
|
-
if (this._cacheWriter) {
|
497
|
-
this._cacheWriter.writeField(connectionID, RANGE, range);
|
498
|
-
}
|
499
|
-
};
|
500
|
-
/**
|
501
|
-
* Record that the node is contained in the connection.
|
502
|
-
*/
|
503
|
-
|
504
|
-
|
505
|
-
_proto._addConnectionForNode = function _addConnectionForNode(connectionID, nodeID) {
|
506
|
-
var connectionMap = this._nodeConnectionMap[nodeID];
|
507
|
-
|
508
|
-
if (!connectionMap) {
|
509
|
-
connectionMap = {};
|
510
|
-
this._nodeConnectionMap[nodeID] = connectionMap;
|
511
|
-
}
|
512
|
-
|
513
|
-
connectionMap[connectionID] = true;
|
514
|
-
};
|
515
|
-
/**
|
516
|
-
* Record that the given node is no longer part of the connection.
|
517
|
-
*/
|
518
|
-
|
519
|
-
|
520
|
-
_proto._removeConnectionForNode = function _removeConnectionForNode(connectionID, nodeID) {
|
521
|
-
var connectionMap = this._nodeConnectionMap[nodeID];
|
522
|
-
|
523
|
-
if (connectionMap) {
|
524
|
-
delete connectionMap[connectionID];
|
525
|
-
|
526
|
-
if (Object.keys(connectionMap).length === 0) {
|
527
|
-
delete this._nodeConnectionMap[nodeID];
|
528
|
-
}
|
529
|
-
}
|
530
|
-
};
|
531
|
-
/**
|
532
|
-
* If the record is in the store, gets a version of the record
|
533
|
-
* in the store being used for writes.
|
534
|
-
*/
|
535
|
-
|
536
|
-
|
537
|
-
_proto._getRecordForWrite = function _getRecordForWrite(dataID) {
|
538
|
-
var record = this._records[dataID];
|
539
|
-
|
540
|
-
if (!record) {
|
541
|
-
return record;
|
542
|
-
}
|
543
|
-
|
544
|
-
if (this._isOptimisticWrite) {
|
545
|
-
this._setClientMutationID(record);
|
546
|
-
}
|
547
|
-
|
548
|
-
return record;
|
549
|
-
};
|
550
|
-
/**
|
551
|
-
* Get the value of the field from the first version of the record for which
|
552
|
-
* the field is defined, returning `null` if the record has been deleted or
|
553
|
-
* `undefined` if the record has not been fetched.
|
554
|
-
*/
|
555
|
-
|
556
|
-
|
557
|
-
_proto._getField = function _getField(dataID, storageKey) {
|
558
|
-
var record = this._records[dataID];
|
559
|
-
|
560
|
-
if (record === null) {
|
561
|
-
return null;
|
562
|
-
} else if (record && record.hasOwnProperty(storageKey)) {
|
563
|
-
return record[storageKey];
|
564
|
-
} else {
|
565
|
-
return undefined;
|
566
|
-
}
|
567
|
-
};
|
568
|
-
/**
|
569
|
-
* Injects the client mutation id associated with the record store instance
|
570
|
-
* into the given record.
|
571
|
-
*/
|
572
|
-
|
573
|
-
|
574
|
-
_proto._setClientMutationID = function _setClientMutationID(record) {
|
575
|
-
var clientMutationID = this._clientMutationID;
|
576
|
-
!clientMutationID ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordWriter: _clientMutationID cannot be null/undefined.') : require("fbjs/lib/invariant")(false) : void 0;
|
577
|
-
var mutationIDs = record[MUTATION_IDS] || [];
|
578
|
-
|
579
|
-
if (mutationIDs.indexOf(clientMutationID) === -1) {
|
580
|
-
mutationIDs.push(clientMutationID);
|
581
|
-
record[MUTATION_IDS] = mutationIDs;
|
582
|
-
}
|
583
|
-
|
584
|
-
record[STATUS] = require("./RelayRecordStatusMap").setOptimisticStatus(0, true);
|
585
|
-
};
|
586
|
-
|
587
|
-
return RelayRecordWriter;
|
588
|
-
}();
|
589
|
-
/**
|
590
|
-
* Filter calls to only those that specify conditions on the returned results
|
591
|
-
* (ex: `orderby(TOP_STORIES)`), removing generic calls (ex: `first`, `find`).
|
592
|
-
*/
|
593
|
-
|
594
|
-
|
595
|
-
function getFilterCalls(calls) {
|
596
|
-
return calls.filter(function (call) {
|
597
|
-
return !require("relay-runtime").ConnectionInterface.isConnectionCall(call);
|
598
|
-
});
|
599
|
-
}
|
600
|
-
|
601
|
-
module.exports = RelayRecordWriter;
|
@@ -1,27 +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-local
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
/**
|
13
|
-
* @internal
|
14
|
-
*
|
15
|
-
* Represents a node that will eventually become a "ref query".
|
16
|
-
*
|
17
|
-
* Includes the `nodePath` (ancestor nodes) that can be used to construct an
|
18
|
-
* appropriate the JSONPath for the query.
|
19
|
-
*
|
20
|
-
* @see splitDeferredRelayQueries
|
21
|
-
*/
|
22
|
-
var RelayRefQueryDescriptor = function RelayRefQueryDescriptor(node, nodePath) {
|
23
|
-
this.node = node;
|
24
|
-
this.nodePath = nodePath;
|
25
|
-
};
|
26
|
-
|
27
|
-
module.exports = RelayRefQueryDescriptor;
|