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
@@ -1,558 +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 _toConsumableArray2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/toConsumableArray"));
|
13
|
-
|
14
|
-
var REFETCH = require("relay-runtime").RangeOperations.REFETCH;
|
15
|
-
|
16
|
-
/**
|
17
|
-
* @internal
|
18
|
-
*
|
19
|
-
* Constructs query fragments that are sent with mutations, which should ensure
|
20
|
-
* that any records changed as a result of mutations are brought up-to-date.
|
21
|
-
*
|
22
|
-
* The fragments are a minimal subset created by intersecting the "fat query"
|
23
|
-
* (fields that a mutation declares may have changed) with the "tracked query"
|
24
|
-
* (fields representing data previously queried and written into the store).
|
25
|
-
*/
|
26
|
-
var RelayMutationQuery = {
|
27
|
-
/**
|
28
|
-
* Accepts a mapping from field names to data IDs. The field names must exist
|
29
|
-
* as top-level fields in the fat query. These top-level fields are used to
|
30
|
-
* re-fetch any data that has changed for records identified by the data IDs.
|
31
|
-
*
|
32
|
-
* The supplied mapping may contain multiple field names. In addition, each
|
33
|
-
* field name may map to an array of data IDs if the field is plural.
|
34
|
-
*/
|
35
|
-
buildFragmentForFields: function buildFragmentForFields(_ref) {
|
36
|
-
var fatQuery = _ref.fatQuery,
|
37
|
-
fieldIDs = _ref.fieldIDs,
|
38
|
-
tracker = _ref.tracker;
|
39
|
-
var mutatedFields = [];
|
40
|
-
|
41
|
-
require("fbjs/lib/forEachObject")(fieldIDs, function (dataIDOrIDs, fieldName) {
|
42
|
-
var fatField = getFieldFromFatQuery(fatQuery, fieldName);
|
43
|
-
var dataIDs = [].concat(dataIDOrIDs);
|
44
|
-
var trackedChildren = [];
|
45
|
-
dataIDs.forEach(function (dataID) {
|
46
|
-
trackedChildren.push.apply(trackedChildren, (0, _toConsumableArray2["default"])(tracker.getTrackedChildrenForID(dataID)));
|
47
|
-
});
|
48
|
-
var trackedField = fatField.clone(trackedChildren);
|
49
|
-
var mutationField = null;
|
50
|
-
|
51
|
-
if (trackedField) {
|
52
|
-
mutationField = require("./intersectRelayQuery")(trackedField, fatField);
|
53
|
-
|
54
|
-
if (mutationField) {
|
55
|
-
mutatedFields.push(mutationField);
|
56
|
-
}
|
57
|
-
}
|
58
|
-
/* eslint-disable no-console */
|
59
|
-
|
60
|
-
|
61
|
-
if (process.env.NODE_ENV !== "production" && console.groupCollapsed && console.groupEnd) {
|
62
|
-
console.groupCollapsed('Building fragment for `' + fieldName + '`');
|
63
|
-
console.log(require("./RelayNodeInterface").ID + ': ', dataIDOrIDs);
|
64
|
-
|
65
|
-
var RelayMutationDebugPrinter = require("./RelayMutationDebugPrinter");
|
66
|
-
|
67
|
-
RelayMutationDebugPrinter.printMutation(trackedField && buildMutationFragment(fatQuery, [trackedField]), 'Tracked Fragment');
|
68
|
-
RelayMutationDebugPrinter.printMutation(buildMutationFragment(fatQuery, [fatField]), 'Fat Fragment');
|
69
|
-
RelayMutationDebugPrinter.printMutation(mutationField && buildMutationFragment(fatQuery, [mutationField]), 'Intersected Fragment');
|
70
|
-
console.groupEnd();
|
71
|
-
}
|
72
|
-
/* eslint-enable no-console */
|
73
|
-
|
74
|
-
});
|
75
|
-
|
76
|
-
return buildMutationFragment(fatQuery, mutatedFields);
|
77
|
-
},
|
78
|
-
|
79
|
-
/**
|
80
|
-
* Creates a fragment used to update any data as a result of a mutation that
|
81
|
-
* deletes an edge from a connection. The primary difference between this and
|
82
|
-
* `createForFields` is whether or not the connection edges are re-fetched.
|
83
|
-
*
|
84
|
-
* `connectionName`
|
85
|
-
* Name of the connection field from which the edge is being deleted.
|
86
|
-
*
|
87
|
-
* `parentID`
|
88
|
-
* ID of the parent record containing the connection which may have metadata
|
89
|
-
* that needs to be re-fetched.
|
90
|
-
*
|
91
|
-
* `parentName`
|
92
|
-
* Name of the top-level field in the fat query that corresponds to the
|
93
|
-
* parent record.
|
94
|
-
*/
|
95
|
-
buildFragmentForEdgeDeletion: function buildFragmentForEdgeDeletion(_ref2) {
|
96
|
-
var fatQuery = _ref2.fatQuery,
|
97
|
-
connectionName = _ref2.connectionName,
|
98
|
-
parentID = _ref2.parentID,
|
99
|
-
parentName = _ref2.parentName,
|
100
|
-
tracker = _ref2.tracker;
|
101
|
-
var fatParent = getFieldFromFatQuery(fatQuery, parentName); // The connection may not be explicit in the fat query, but if it is, we
|
102
|
-
// try to validate it.
|
103
|
-
|
104
|
-
getConnectionAndValidate(fatParent, parentName, connectionName);
|
105
|
-
var mutatedFields = [];
|
106
|
-
var trackedParent = fatParent.clone(tracker.getTrackedChildrenForID(parentID));
|
107
|
-
|
108
|
-
if (trackedParent) {
|
109
|
-
var filterUnterminatedRange = function filterUnterminatedRange(node) {
|
110
|
-
return node.getSchemaName() === connectionName;
|
111
|
-
};
|
112
|
-
|
113
|
-
var mutatedField = require("./intersectRelayQuery")(trackedParent, fatParent, filterUnterminatedRange);
|
114
|
-
|
115
|
-
if (mutatedField) {
|
116
|
-
// If we skipped validation above, we get a second chance here.
|
117
|
-
getConnectionAndValidate(mutatedField, parentName, connectionName);
|
118
|
-
mutatedFields.push(mutatedField);
|
119
|
-
}
|
120
|
-
}
|
121
|
-
|
122
|
-
return buildMutationFragment(fatQuery, mutatedFields);
|
123
|
-
},
|
124
|
-
|
125
|
-
/**
|
126
|
-
* Creates a fragment used to fetch data necessary to insert a new edge into
|
127
|
-
* an existing connection.
|
128
|
-
*
|
129
|
-
* `connectionName`
|
130
|
-
* Name of the connection field into which the edge is being inserted.
|
131
|
-
*
|
132
|
-
* `parentID`
|
133
|
-
* ID of the parent record containing the connection which may have metadata
|
134
|
-
* that needs to be re-fetched.
|
135
|
-
*
|
136
|
-
* `edgeName`
|
137
|
-
* Name of the top-level field in the fat query that corresponds to the
|
138
|
-
* newly inserted edge.
|
139
|
-
*
|
140
|
-
* `parentName`
|
141
|
-
* Name of the top-level field in the fat query that corresponds to the
|
142
|
-
* parent record. If not supplied, metadata on the parent record and any
|
143
|
-
* connections without entries in `rangeBehaviors` will not be updated.
|
144
|
-
*/
|
145
|
-
buildFragmentForEdgeInsertion: function buildFragmentForEdgeInsertion(_ref3) {
|
146
|
-
var fatQuery = _ref3.fatQuery,
|
147
|
-
connectionName = _ref3.connectionName,
|
148
|
-
parentID = _ref3.parentID,
|
149
|
-
edgeName = _ref3.edgeName,
|
150
|
-
parentName = _ref3.parentName,
|
151
|
-
rangeBehaviors = _ref3.rangeBehaviors,
|
152
|
-
tracker = _ref3.tracker;
|
153
|
-
var mutatedFields = [];
|
154
|
-
var keysWithoutRangeBehavior = {};
|
155
|
-
var trackedChildren = tracker.getTrackedChildrenForID(parentID);
|
156
|
-
var trackedConnections = [];
|
157
|
-
trackedChildren.forEach(function (trackedChild) {
|
158
|
-
trackedConnections.push.apply(trackedConnections, (0, _toConsumableArray2["default"])(findDescendantFields(trackedChild, connectionName)));
|
159
|
-
});
|
160
|
-
|
161
|
-
if (trackedConnections.length) {
|
162
|
-
// If the first instance of the connection passes validation, all will.
|
163
|
-
validateConnection(parentName, connectionName, trackedConnections[0]);
|
164
|
-
var mutatedEdgeFields = [];
|
165
|
-
trackedConnections.forEach(function (trackedConnection) {
|
166
|
-
var trackedEdges = findDescendantFields(trackedConnection, 'edges');
|
167
|
-
|
168
|
-
if (!trackedEdges.length) {
|
169
|
-
return;
|
170
|
-
}
|
171
|
-
|
172
|
-
var callsWithValues = trackedConnection.getRangeBehaviorCalls();
|
173
|
-
|
174
|
-
var rangeBehavior = require("./getRangeBehavior")(rangeBehaviors, callsWithValues);
|
175
|
-
/* eslint-disable no-console */
|
176
|
-
|
177
|
-
|
178
|
-
if (process.env.NODE_ENV !== "production" && console.groupCollapsed && console.groupEnd) {
|
179
|
-
var serializeRelayQueryCall = require("./serializeRelayQueryCall");
|
180
|
-
|
181
|
-
var serializedCalls = callsWithValues.map(serializeRelayQueryCall).sort().join('');
|
182
|
-
console.log(serializedCalls + ': ' + (rangeBehavior || ''));
|
183
|
-
}
|
184
|
-
/* eslint-enable no-console */
|
185
|
-
|
186
|
-
|
187
|
-
if (rangeBehavior && rangeBehavior !== REFETCH) {
|
188
|
-
// Include edges from all connections that exist in `rangeBehaviors`.
|
189
|
-
// This may add duplicates, but they will eventually be flattened.
|
190
|
-
trackedEdges.forEach(function (trackedEdge) {
|
191
|
-
mutatedEdgeFields.push.apply(mutatedEdgeFields, (0, _toConsumableArray2["default"])(trackedEdge.getChildren()));
|
192
|
-
});
|
193
|
-
} else {
|
194
|
-
// If the connection is not in `rangeBehaviors` or we have explicitly
|
195
|
-
// set the behavior to `refetch`, re-fetch it.
|
196
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(rangeBehavior === REFETCH, 'RelayMutation: The connection `%s` on the mutation field `%s` ' + 'that corresponds to the ID `%s` did not match any of the ' + '`rangeBehaviors` specified in your RANGE_ADD config. This means ' + 'that the entire connection will be refetched. Configure a range ' + 'behavior for this mutation in order to fetch only the new edge ' + 'and to enable optimistic mutations or use `refetch` to squelch ' + 'this warning.', trackedConnection.getStorageKey(), parentName, parentID) : void 0;
|
197
|
-
keysWithoutRangeBehavior[trackedConnection.getShallowHash()] = true;
|
198
|
-
}
|
199
|
-
});
|
200
|
-
|
201
|
-
if (mutatedEdgeFields.length) {
|
202
|
-
mutatedFields.push(buildEdgeField(parentID, edgeName, mutatedEdgeFields));
|
203
|
-
}
|
204
|
-
}
|
205
|
-
|
206
|
-
if (parentName != null) {
|
207
|
-
var fatParent = getFieldFromFatQuery(fatQuery, parentName); // The connection may not be explicit in the fat query, but if it is, we
|
208
|
-
// try to validate it.
|
209
|
-
|
210
|
-
getConnectionAndValidate(fatParent, parentName, connectionName);
|
211
|
-
var trackedParent = fatParent.clone(trackedChildren);
|
212
|
-
|
213
|
-
if (trackedParent) {
|
214
|
-
var filterUnterminatedRange = function filterUnterminatedRange(node) {
|
215
|
-
return node.getSchemaName() === connectionName && !keysWithoutRangeBehavior.hasOwnProperty(node.getShallowHash());
|
216
|
-
};
|
217
|
-
|
218
|
-
var mutatedParent = require("./intersectRelayQuery")(trackedParent, fatParent, filterUnterminatedRange);
|
219
|
-
|
220
|
-
if (mutatedParent) {
|
221
|
-
mutatedFields.push(mutatedParent);
|
222
|
-
}
|
223
|
-
}
|
224
|
-
}
|
225
|
-
|
226
|
-
return buildMutationFragment(fatQuery, mutatedFields);
|
227
|
-
},
|
228
|
-
|
229
|
-
/**
|
230
|
-
* Creates a fragment used to fetch the given optimistic response.
|
231
|
-
*/
|
232
|
-
buildFragmentForOptimisticUpdate: function buildFragmentForOptimisticUpdate(_ref4) {
|
233
|
-
var response = _ref4.response,
|
234
|
-
fatQuery = _ref4.fatQuery;
|
235
|
-
|
236
|
-
// Silences RelayQueryNode being incompatible with sub-class RelayQueryField
|
237
|
-
// A detailed error description is available in #7635477
|
238
|
-
var mutatedFields = require("./RelayOptimisticMutationUtils").inferRelayFieldsFromData(response);
|
239
|
-
|
240
|
-
return buildMutationFragment(fatQuery, mutatedFields);
|
241
|
-
},
|
242
|
-
|
243
|
-
/**
|
244
|
-
* Creates a RelayQuery.Mutation used to fetch the given optimistic response.
|
245
|
-
*/
|
246
|
-
buildQueryForOptimisticUpdate: function buildQueryForOptimisticUpdate(_ref5) {
|
247
|
-
var fatQuery = _ref5.fatQuery,
|
248
|
-
mutation = _ref5.mutation,
|
249
|
-
response = _ref5.response;
|
250
|
-
var children = [require("nullthrows")(RelayMutationQuery.buildFragmentForOptimisticUpdate({
|
251
|
-
response: response,
|
252
|
-
fatQuery: fatQuery
|
253
|
-
}))];
|
254
|
-
return require("./RelayQuery").Mutation.build('OptimisticQuery', fatQuery.getType(), mutation.calls[0].name, null, children, mutation.metadata);
|
255
|
-
},
|
256
|
-
|
257
|
-
/**
|
258
|
-
* Creates a RelayQuery.Mutation for the given config. See type
|
259
|
-
* `DeclarativeMutationConfig` and the `buildFragmentForEdgeInsertion`,
|
260
|
-
* `buildFragmentForEdgeDeletion` and `buildFragmentForFields` methods above
|
261
|
-
* for possible configs.
|
262
|
-
*/
|
263
|
-
buildQuery: function buildQuery(_ref6) {
|
264
|
-
var configs = _ref6.configs,
|
265
|
-
fatQuery = _ref6.fatQuery,
|
266
|
-
input = _ref6.input,
|
267
|
-
mutationName = _ref6.mutationName,
|
268
|
-
mutation = _ref6.mutation,
|
269
|
-
tracker = _ref6.tracker;
|
270
|
-
|
271
|
-
var _ConnectionInterface$ = require("relay-runtime").ConnectionInterface.get(),
|
272
|
-
CLIENT_MUTATION_ID = _ConnectionInterface$.CLIENT_MUTATION_ID;
|
273
|
-
|
274
|
-
var children = [require("./RelayQuery").Field.build({
|
275
|
-
fieldName: CLIENT_MUTATION_ID,
|
276
|
-
type: 'String',
|
277
|
-
metadata: {
|
278
|
-
isRequisite: true
|
279
|
-
}
|
280
|
-
})];
|
281
|
-
|
282
|
-
if (process.env.NODE_ENV !== "production" && console.groupCollapsed && console.groupEnd) {
|
283
|
-
console.groupCollapsed('Mutation Configs');
|
284
|
-
}
|
285
|
-
|
286
|
-
configs.forEach(function (config) {
|
287
|
-
switch (config.type) {
|
288
|
-
case require("relay-runtime").MutationTypes.REQUIRED_CHILDREN:
|
289
|
-
var newChildren = config.children.map(function (child) {
|
290
|
-
return require("./RelayQuery").Fragment.create(child, require("./RelayMetaRoute").get('$buildQuery'), {});
|
291
|
-
});
|
292
|
-
children = children.concat(newChildren);
|
293
|
-
|
294
|
-
if (process.env.NODE_ENV !== "production" && console.groupCollapsed && console.groupEnd) {
|
295
|
-
var RelayMutationDebugPrinter = require("./RelayMutationDebugPrinter");
|
296
|
-
|
297
|
-
console.groupCollapsed('REQUIRED_CHILDREN');
|
298
|
-
newChildren.forEach(function (child, index) {
|
299
|
-
console.groupCollapsed(index);
|
300
|
-
RelayMutationDebugPrinter.printMutation(child);
|
301
|
-
console.groupEnd();
|
302
|
-
});
|
303
|
-
console.groupEnd();
|
304
|
-
}
|
305
|
-
|
306
|
-
break;
|
307
|
-
|
308
|
-
case require("relay-runtime").MutationTypes.RANGE_ADD:
|
309
|
-
if (process.env.NODE_ENV !== "production" && console.groupCollapsed && console.groupEnd) {
|
310
|
-
console.groupCollapsed('RANGE_ADD');
|
311
|
-
}
|
312
|
-
|
313
|
-
children.push(RelayMutationQuery.buildFragmentForEdgeInsertion({
|
314
|
-
// $FlowFixMe TODO T25557273 - fix nullability
|
315
|
-
connectionName: config.connectionName,
|
316
|
-
edgeName: config.edgeName,
|
317
|
-
fatQuery: fatQuery,
|
318
|
-
// $FlowFixMe TODO T25557273 - fix nullability
|
319
|
-
parentID: config.parentID,
|
320
|
-
parentName: config.parentName,
|
321
|
-
rangeBehaviors: sanitizeRangeBehaviors( // $FlowFixMe TODO T25557273 - fix nullability
|
322
|
-
config.rangeBehaviors),
|
323
|
-
tracker: tracker
|
324
|
-
}));
|
325
|
-
|
326
|
-
if (process.env.NODE_ENV !== "production" && console.groupCollapsed && console.groupEnd) {
|
327
|
-
console.groupEnd();
|
328
|
-
}
|
329
|
-
|
330
|
-
break;
|
331
|
-
|
332
|
-
case require("relay-runtime").MutationTypes.RANGE_DELETE:
|
333
|
-
case require("relay-runtime").MutationTypes.NODE_DELETE:
|
334
|
-
var edgeDeletion = RelayMutationQuery.buildFragmentForEdgeDeletion({
|
335
|
-
// $FlowFixMe TODO T25557273 - fix nullability
|
336
|
-
connectionName: config.connectionName,
|
337
|
-
fatQuery: fatQuery,
|
338
|
-
// $FlowFixMe TODO T25557273 - fix nullability
|
339
|
-
parentID: config.parentID,
|
340
|
-
// $FlowFixMe TODO T25557273 - fix nullability
|
341
|
-
parentName: config.parentName,
|
342
|
-
tracker: tracker
|
343
|
-
});
|
344
|
-
children.push(edgeDeletion);
|
345
|
-
var deletedIDFieldName = Array.isArray(config.deletedIDFieldName) ? config.deletedIDFieldName.concat(require("./RelayNodeInterface").ID) : [config.deletedIDFieldName];
|
346
|
-
var nodeDeletion = buildFragmentForDeletedConnectionNodeID(deletedIDFieldName, fatQuery);
|
347
|
-
children.push(nodeDeletion);
|
348
|
-
|
349
|
-
if (process.env.NODE_ENV !== "production" && console.groupCollapsed && console.groupEnd) {
|
350
|
-
var configType = config === require("relay-runtime").MutationTypes.RANGE_DELETE ? 'RANGE_DELETE' : 'NODE_DELETE';
|
351
|
-
console.groupCollapsed(configType);
|
352
|
-
|
353
|
-
var _RelayMutationDebugPrinter = require("./RelayMutationDebugPrinter");
|
354
|
-
|
355
|
-
_RelayMutationDebugPrinter.printMutation(edgeDeletion, 'Edge Fragment');
|
356
|
-
|
357
|
-
_RelayMutationDebugPrinter.printMutation(nodeDeletion, 'Node Fragment');
|
358
|
-
|
359
|
-
console.groupEnd();
|
360
|
-
}
|
361
|
-
|
362
|
-
break;
|
363
|
-
|
364
|
-
case require("relay-runtime").MutationTypes.FIELDS_CHANGE:
|
365
|
-
if (process.env.NODE_ENV !== "production" && console.groupCollapsed && console.groupEnd) {
|
366
|
-
console.groupCollapsed('FIELDS_CHANGE');
|
367
|
-
}
|
368
|
-
|
369
|
-
children.push(RelayMutationQuery.buildFragmentForFields({
|
370
|
-
fatQuery: fatQuery,
|
371
|
-
fieldIDs: config.fieldIDs,
|
372
|
-
tracker: tracker
|
373
|
-
}));
|
374
|
-
|
375
|
-
if (process.env.NODE_ENV !== "production" && console.groupCollapsed && console.groupEnd) {
|
376
|
-
console.groupEnd();
|
377
|
-
}
|
378
|
-
|
379
|
-
break;
|
380
|
-
|
381
|
-
default:
|
382
|
-
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutationQuery: Unrecognized config key `%s` for `%s`.', config.type, mutationName) : require("fbjs/lib/invariant")(false) : void 0;
|
383
|
-
}
|
384
|
-
});
|
385
|
-
|
386
|
-
if (process.env.NODE_ENV !== "production" && console.groupCollapsed && console.groupEnd) {
|
387
|
-
console.groupEnd();
|
388
|
-
}
|
389
|
-
|
390
|
-
return require("./RelayQuery").Mutation.build(mutationName, fatQuery.getType(), mutation.calls[0].name, input, children.filter(function (child) {
|
391
|
-
return child != null;
|
392
|
-
}), mutation.metadata);
|
393
|
-
}
|
394
|
-
};
|
395
|
-
|
396
|
-
function getFieldFromFatQuery(fatQuery, fieldName) {
|
397
|
-
var field = fatQuery.getFieldByStorageKey(fieldName);
|
398
|
-
!field ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutationQuery: Invalid field name on fat query, `%s`.', fieldName) : require("fbjs/lib/invariant")(false) : void 0;
|
399
|
-
return field;
|
400
|
-
}
|
401
|
-
|
402
|
-
function buildMutationFragment(fatQuery, fields) {
|
403
|
-
var fragment = require("./RelayQuery").Fragment.build('MutationQuery', fatQuery.getType(), fields);
|
404
|
-
|
405
|
-
!(fragment instanceof require("./RelayQuery").Fragment) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutationQuery: Expected a fragment.') : require("fbjs/lib/invariant")(false) : void 0;
|
406
|
-
return fragment;
|
407
|
-
}
|
408
|
-
|
409
|
-
function buildFragmentForDeletedConnectionNodeID(fieldNames, fatQuery) {
|
410
|
-
!(fieldNames.length > 0) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutationQuery: Invalid deleted node id name.') : require("fbjs/lib/invariant")(false) : void 0;
|
411
|
-
|
412
|
-
var field = require("./RelayQuery").Field.build({
|
413
|
-
fieldName: fieldNames[fieldNames.length - 1],
|
414
|
-
type: 'String'
|
415
|
-
});
|
416
|
-
|
417
|
-
for (var ii = fieldNames.length - 2; ii >= 0; ii--) {
|
418
|
-
field = require("./RelayQuery").Field.build({
|
419
|
-
fieldName: fieldNames[ii],
|
420
|
-
type: require("./RelayNodeInterface").ANY_TYPE,
|
421
|
-
children: [field],
|
422
|
-
metadata: {
|
423
|
-
canHaveSubselections: true
|
424
|
-
}
|
425
|
-
});
|
426
|
-
}
|
427
|
-
|
428
|
-
return buildMutationFragment(fatQuery, [field]);
|
429
|
-
}
|
430
|
-
|
431
|
-
function buildEdgeField(parentID, edgeName, edgeFields) {
|
432
|
-
var fields = [require("./RelayQuery").Field.build({
|
433
|
-
fieldName: 'cursor',
|
434
|
-
type: 'String'
|
435
|
-
}), require("./RelayQuery").Field.build({
|
436
|
-
fieldName: require("./RelayNodeInterface").TYPENAME,
|
437
|
-
type: 'String'
|
438
|
-
})];
|
439
|
-
|
440
|
-
if (require("relay-runtime").ConnectionInterface.get().EDGES_HAVE_SOURCE_FIELD && !require("./RelayRecord").isClientID(parentID)) {
|
441
|
-
fields.push(require("./RelayQuery").Field.build({
|
442
|
-
children: [require("./RelayQuery").Field.build({
|
443
|
-
fieldName: require("./RelayNodeInterface").ID,
|
444
|
-
type: 'String'
|
445
|
-
}), require("./RelayQuery").Field.build({
|
446
|
-
fieldName: require("./RelayNodeInterface").TYPENAME,
|
447
|
-
type: 'String'
|
448
|
-
})],
|
449
|
-
fieldName: 'source',
|
450
|
-
metadata: {
|
451
|
-
canHaveSubselections: true
|
452
|
-
},
|
453
|
-
type: require("./RelayNodeInterface").ANY_TYPE
|
454
|
-
}));
|
455
|
-
}
|
456
|
-
|
457
|
-
fields.push.apply(fields, (0, _toConsumableArray2["default"])(edgeFields));
|
458
|
-
|
459
|
-
var edgeField = require("./flattenRelayQuery")(require("./RelayQuery").Field.build({
|
460
|
-
children: fields,
|
461
|
-
fieldName: edgeName,
|
462
|
-
metadata: {
|
463
|
-
canHaveSubselections: true
|
464
|
-
},
|
465
|
-
type: require("./RelayNodeInterface").ANY_TYPE
|
466
|
-
}));
|
467
|
-
|
468
|
-
!(edgeField instanceof require("./RelayQuery").Field) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutationQuery: Expected a field.') : require("fbjs/lib/invariant")(false) : void 0;
|
469
|
-
return edgeField;
|
470
|
-
}
|
471
|
-
|
472
|
-
function sanitizeRangeBehaviors(rangeBehaviors) {
|
473
|
-
// Prior to 0.4.1 you would have to specify the args in your range behaviors
|
474
|
-
// in the same order they appeared in your query. From 0.4.1 onward, args in a
|
475
|
-
// range behavior key must be in alphabetical order.
|
476
|
-
// No need to sanitize if defined as a function
|
477
|
-
if (typeof rangeBehaviors === 'function') {
|
478
|
-
return rangeBehaviors;
|
479
|
-
}
|
480
|
-
|
481
|
-
var unsortedKeys;
|
482
|
-
|
483
|
-
require("fbjs/lib/forEachObject")(rangeBehaviors, function (value, key) {
|
484
|
-
if (key !== '') {
|
485
|
-
var keyParts = key // Remove the last parenthesis
|
486
|
-
.slice(0, -1) // Slice on unescaped parentheses followed immediately by a `.`
|
487
|
-
.split(/\)\./);
|
488
|
-
var sortedKey = keyParts.sort().join(').') + (keyParts.length ? ')' : '');
|
489
|
-
|
490
|
-
if (sortedKey !== key) {
|
491
|
-
unsortedKeys = unsortedKeys || [];
|
492
|
-
unsortedKeys.push(key);
|
493
|
-
}
|
494
|
-
}
|
495
|
-
});
|
496
|
-
|
497
|
-
if (unsortedKeys) {
|
498
|
-
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutation: To define a range behavior key without sorting ' + 'the arguments alphabetically is disallowed as of Relay 0.5.1. Please ' + 'sort the argument names of the range behavior key%s `%s`%s.', unsortedKeys.length === 1 ? '' : 's', unsortedKeys.length === 1 ? unsortedKeys[0] : unsortedKeys.length === 2 ? "".concat(unsortedKeys[0], "` and `").concat(unsortedKeys[1]) : unsortedKeys.slice(0, -1).join('`, `'), unsortedKeys.length > 2 ? ", and `".concat(unsortedKeys.slice(-1), "`") : '') : require("fbjs/lib/invariant")(false) : void 0;
|
499
|
-
}
|
500
|
-
|
501
|
-
return rangeBehaviors;
|
502
|
-
}
|
503
|
-
/**
|
504
|
-
* Confirms that the `connection` field extracted from the fat query at
|
505
|
-
* `parentName` -> `connectionName` is actually a connection.
|
506
|
-
*/
|
507
|
-
|
508
|
-
|
509
|
-
function validateConnection(parentName, connectionName, connection) {
|
510
|
-
!connection.isConnection() ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutationQuery: Expected field `%s`%s to be a connection.', connectionName, parentName ? ' on `' + parentName + '`' : '') : require("fbjs/lib/invariant")(false) : void 0;
|
511
|
-
}
|
512
|
-
/**
|
513
|
-
* Convenience wrapper around validateConnection that gracefully attempts to
|
514
|
-
* extract the connection identified by `connectionName` from the `parentField`.
|
515
|
-
* If the connection isn't present (because it wasn't in the fat query or
|
516
|
-
* because it didn't survive query intersection), validation is skipped.
|
517
|
-
*/
|
518
|
-
|
519
|
-
|
520
|
-
function getConnectionAndValidate(parentField, parentName, connectionName) {
|
521
|
-
var connections = findDescendantFields(parentField, connectionName);
|
522
|
-
|
523
|
-
if (connections.length) {
|
524
|
-
// If the first instance of the connection passes validation, all will.
|
525
|
-
validateConnection(parentName, connectionName, connections[0]);
|
526
|
-
}
|
527
|
-
}
|
528
|
-
/**
|
529
|
-
* Finds all direct and indirect child fields of `node` with the given
|
530
|
-
* field name.
|
531
|
-
*/
|
532
|
-
|
533
|
-
|
534
|
-
function findDescendantFields(rootNode, fieldName) {
|
535
|
-
var fields = [];
|
536
|
-
|
537
|
-
function traverse(node) {
|
538
|
-
if (node instanceof require("./RelayQuery").Field) {
|
539
|
-
if (node.getSchemaName() === fieldName) {
|
540
|
-
fields.push(node);
|
541
|
-
return;
|
542
|
-
}
|
543
|
-
}
|
544
|
-
|
545
|
-
if (node === rootNode || node instanceof require("./RelayQuery").Fragment) {
|
546
|
-
// Search fragments and the root node for matching fields, but skip
|
547
|
-
// descendant non-matching fields.
|
548
|
-
node.getChildren().forEach(function (child) {
|
549
|
-
return traverse(child);
|
550
|
-
});
|
551
|
-
}
|
552
|
-
}
|
553
|
-
|
554
|
-
traverse(rootNode);
|
555
|
-
return fields;
|
556
|
-
}
|
557
|
-
|
558
|
-
module.exports = RelayMutationQuery;
|