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/RelayMutation.js
DELETED
@@ -1,322 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
var _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
|
13
|
-
|
14
|
-
/**
|
15
|
-
* @public
|
16
|
-
*
|
17
|
-
* RelayMutation is the base class for modeling mutations of data.
|
18
|
-
*/
|
19
|
-
var RelayMutation =
|
20
|
-
/*#__PURE__*/
|
21
|
-
function () {
|
22
|
-
function RelayMutation(props) {
|
23
|
-
this._didShowFakeDataWarning = false;
|
24
|
-
this._didValidateConfig = false;
|
25
|
-
this._unresolvedProps = props;
|
26
|
-
}
|
27
|
-
/**
|
28
|
-
* @internal
|
29
|
-
*/
|
30
|
-
|
31
|
-
|
32
|
-
var _proto = RelayMutation.prototype;
|
33
|
-
|
34
|
-
_proto.bindEnvironment = function bindEnvironment(environment) {
|
35
|
-
if (!this._environment) {
|
36
|
-
this._environment = environment;
|
37
|
-
|
38
|
-
this._resolveProps();
|
39
|
-
} else {
|
40
|
-
!(environment === this._environment) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, '%s: Mutation instance cannot be used in different Relay environments.', this.constructor.name) : require("fbjs/lib/invariant")(false) : void 0;
|
41
|
-
}
|
42
|
-
};
|
43
|
-
/**
|
44
|
-
* Each mutation corresponds to a field on the server which is used by clients
|
45
|
-
* to communicate the type of mutation to be executed.
|
46
|
-
*/
|
47
|
-
|
48
|
-
|
49
|
-
_proto.getMutation = function getMutation() {
|
50
|
-
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, '%s: Expected abstract method `getMutation` to be implemented.', this.constructor.name) : require("fbjs/lib/invariant")(false) : void 0;
|
51
|
-
};
|
52
|
-
/**
|
53
|
-
* "Fat queries" represent a predetermined set of fields that may change as a
|
54
|
-
* result of a mutation, and which should therefore be queried in order to get
|
55
|
-
* a consistent view of the data after performing a mutation. In practice, we
|
56
|
-
* query for a subset of those fields because we intersect the fat query with
|
57
|
-
* the tracked query we have for a given node (ie. the pieces of data we've
|
58
|
-
* previously queried for and have therefore written to the store).
|
59
|
-
*
|
60
|
-
* Fat queries can be written like normal GraphQL queries with one main
|
61
|
-
* exception: fat queries use childless non-scalar fields to indicate that
|
62
|
-
* anything under that field may change. For example, the fat query for
|
63
|
-
* feedback_like contains the field `like_sentence` with no child fields.
|
64
|
-
* This means that any field below `like_sentence` may change as a result of
|
65
|
-
* feedback_like.
|
66
|
-
*
|
67
|
-
* When adding a fat query, consider *all* of the data that might change as a
|
68
|
-
* result of the mutation - not just data that we currently use in Relay. We
|
69
|
-
* don't need to worry about overfetching here (this query is never executed
|
70
|
-
* on its own; the infrastructure always intersects it with what is actually
|
71
|
-
* needed), and if we omit fields here we might get odd consistency behavior
|
72
|
-
* in the future when we add new views or modify existing ones.
|
73
|
-
*/
|
74
|
-
|
75
|
-
|
76
|
-
_proto.getFatQuery = function getFatQuery() {
|
77
|
-
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, '%s: Expected abstract method `getFatQuery` to be implemented.', this.constructor.name) : require("fbjs/lib/invariant")(false) : void 0;
|
78
|
-
};
|
79
|
-
/**
|
80
|
-
* These configurations are used to generate the query for the mutation to be
|
81
|
-
* sent to the server and to correctly write the server's response into the
|
82
|
-
* client store.
|
83
|
-
*
|
84
|
-
* Possible configuration types:
|
85
|
-
*
|
86
|
-
* - FIELDS_CHANGE provides configuration for mutation fields.
|
87
|
-
* {
|
88
|
-
* type: MutationTypes.FIELDS_CHANGE;
|
89
|
-
* fieldIDs: {[fieldName: string]: DataID | Array<DataID>};
|
90
|
-
* }
|
91
|
-
* where fieldIDs map `fieldName`s from the fatQuery to a DataID or
|
92
|
-
* array of DataIDs to be updated in the store.
|
93
|
-
*
|
94
|
-
* - RANGE_ADD provides configuration for adding a new edge to a range.
|
95
|
-
* {
|
96
|
-
* type: MutationTypes.RANGE_ADD;
|
97
|
-
* parentName: string;
|
98
|
-
* parentID: string;
|
99
|
-
* connectionName: string;
|
100
|
-
* edgeName: string;
|
101
|
-
* rangeBehaviors:
|
102
|
-
* {[call: string]: RelayClassic.RangeOperation};
|
103
|
-
* }
|
104
|
-
* where `parentName` is the field in the fatQuery that contains the range,
|
105
|
-
* `parentID` is the DataID of `parentName` in the store, `connectionName`
|
106
|
-
* is the name of the range, `edgeName` is the name of the key in server
|
107
|
-
* response that contains the newly created edge, `rangeBehaviors` maps
|
108
|
-
* stringified representation of calls on the connection to
|
109
|
-
* RelayClassic.RangeOperation.
|
110
|
-
*
|
111
|
-
* - NODE_DELETE provides configuration for deleting a node and the
|
112
|
-
* corresponding edge from a range.
|
113
|
-
* {
|
114
|
-
* type: MutationTypes.NODE_DELETE;
|
115
|
-
* parentName: string;
|
116
|
-
* parentID: string;
|
117
|
-
* connectionName: string;
|
118
|
-
* deletedIDFieldName: string;
|
119
|
-
* }
|
120
|
-
* where `parentName`, `parentID` and `connectionName` refer to the same
|
121
|
-
* things as in RANGE_ADD, `deletedIDFieldName` is the name of the key in
|
122
|
-
* the server response that contains the DataID of the deleted node.
|
123
|
-
*
|
124
|
-
* - RANGE_DELETE provides configuration for deleting an edge from a range
|
125
|
-
* but doesn't delete the node.
|
126
|
-
* {
|
127
|
-
* type: MutationTypes.RANGE_DELETE;
|
128
|
-
* parentName: string;
|
129
|
-
* parentID: string;
|
130
|
-
* connectionName: string;
|
131
|
-
* deletedIDFieldName: string | Array<string>;
|
132
|
-
* pathToConnection: Array<string>;
|
133
|
-
* }
|
134
|
-
* where `parentName`, `parentID`, `connectionName` and
|
135
|
-
* `deletedIDFieldName` refer to the same things as in NODE_DELETE.
|
136
|
-
* `deletedIDFieldName` can also be a path from the response root to the
|
137
|
-
* deleted node. `pathToConnection` is a path from `parentName` to
|
138
|
-
* `connectionName`.
|
139
|
-
*
|
140
|
-
* - REQUIRED_CHILDREN is used to append additional children (fragments or
|
141
|
-
* fields) to the mutation query. Any data fetched for these children is
|
142
|
-
* not written to the client store, but you can add code to process it
|
143
|
-
* in the `onSuccess` callback passed to the `RelayEnvironment` `applyUpdate`
|
144
|
-
* method. You may need to use this, for example, to fetch fields on a new
|
145
|
-
* object created by the mutation (and which Relay would normally not
|
146
|
-
* attempt to fetch because it has not previously fetched anything for that
|
147
|
-
* object).
|
148
|
-
* {
|
149
|
-
* type: MutationTypes.REQUIRED_CHILDREN;
|
150
|
-
* children: Array<RelayQuery.Node>;
|
151
|
-
* }
|
152
|
-
*/
|
153
|
-
|
154
|
-
|
155
|
-
_proto.getConfigs = function getConfigs() {
|
156
|
-
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, '%s: Expected abstract method `getConfigs` to be implemented.', this.constructor.name) : require("fbjs/lib/invariant")(false) : void 0;
|
157
|
-
};
|
158
|
-
/**
|
159
|
-
* These variables form the "input" to the mutation query sent to the server.
|
160
|
-
*/
|
161
|
-
|
162
|
-
|
163
|
-
_proto.getVariables = function getVariables() {
|
164
|
-
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, '%s: Expected abstract method `getVariables` to be implemented.', this.constructor.name) : require("fbjs/lib/invariant")(false) : void 0;
|
165
|
-
};
|
166
|
-
/**
|
167
|
-
* These will be sent along with the mutation query to the server.
|
168
|
-
*/
|
169
|
-
|
170
|
-
|
171
|
-
_proto.getFiles = function getFiles() {
|
172
|
-
return null;
|
173
|
-
};
|
174
|
-
/**
|
175
|
-
* When a request is sent to the server, mutations can optionally construct an
|
176
|
-
* optimistic response that has the same shape as the server response payload.
|
177
|
-
* This optimistic response is used to pre-emptively update the client cache
|
178
|
-
* to simulate an instantaneous response.
|
179
|
-
*
|
180
|
-
* The optimistic response may be a subset or superset of the actual response
|
181
|
-
* payload. It can be a subset if certain fields are impossible to create on
|
182
|
-
* the client (and if views are expected to handle the data inconsistency). It
|
183
|
-
* can be a superset of the actual response payload if certain fields that are
|
184
|
-
* affected have not been queried by the client, yet.
|
185
|
-
*/
|
186
|
-
|
187
|
-
|
188
|
-
_proto.getOptimisticResponse = function getOptimisticResponse() {
|
189
|
-
return null;
|
190
|
-
};
|
191
|
-
/**
|
192
|
-
* Optional. Similar to `getConfig`, this is used to create the query
|
193
|
-
* corresponding to the `optimisticResponse`. If not provided, the query
|
194
|
-
* will be inferred from the optimistic response. Most subclasses shouldn't
|
195
|
-
* need to extend this method.
|
196
|
-
*/
|
197
|
-
|
198
|
-
|
199
|
-
_proto.getOptimisticConfigs = function getOptimisticConfigs() {
|
200
|
-
return null;
|
201
|
-
};
|
202
|
-
/**
|
203
|
-
* An optional collision key allows a mutation to identify itself with other
|
204
|
-
* mutations that affect the same fields. Mutations with the same collision
|
205
|
-
* are sent to the server serially and in-order to avoid unpredictable and
|
206
|
-
* potentially incorrect behavior.
|
207
|
-
*/
|
208
|
-
|
209
|
-
|
210
|
-
_proto.getCollisionKey = function getCollisionKey() {
|
211
|
-
return null;
|
212
|
-
};
|
213
|
-
|
214
|
-
_proto._resolveProps = function _resolveProps() {
|
215
|
-
var _this = this;
|
216
|
-
|
217
|
-
var fragments = this.constructor.fragments;
|
218
|
-
var initialVariables = this.constructor.initialVariables || {};
|
219
|
-
var props = this._unresolvedProps;
|
220
|
-
var resolvedProps = (0, _objectSpread2["default"])({}, props);
|
221
|
-
|
222
|
-
require("fbjs/lib/forEachObject")(fragments, function (fragmentBuilder, fragmentName) {
|
223
|
-
var propValue = props[fragmentName];
|
224
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(propValue !== undefined, 'RelayMutation: Expected data for fragment `%s` to be supplied to ' + '`%s` as a prop. Pass an explicit `null` if this is intentional.', fragmentName, _this.constructor.name) : void 0;
|
225
|
-
|
226
|
-
if (propValue == null) {
|
227
|
-
return;
|
228
|
-
}
|
229
|
-
|
230
|
-
if (typeof propValue !== 'object') {
|
231
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayMutation: Expected data for fragment `%s` supplied to `%s` ' + 'to be an object.', fragmentName, _this.constructor.name) : void 0;
|
232
|
-
return;
|
233
|
-
}
|
234
|
-
|
235
|
-
var fragment = require("./RelayQuery").Fragment.create(buildMutationFragment(_this.constructor.name, fragmentName, fragmentBuilder, initialVariables), require("./RelayMetaRoute").get("$RelayMutation_".concat(_this.constructor.name)), initialVariables);
|
236
|
-
|
237
|
-
if (fragment.isPlural()) {
|
238
|
-
!Array.isArray(propValue) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutation: Invalid prop `%s` supplied to `%s`, expected an ' + 'array of records because the corresponding fragment is plural.', fragmentName, _this.constructor.name) : require("fbjs/lib/invariant")(false) : void 0;
|
239
|
-
var dataIDs = propValue.map(function (item, ii) {
|
240
|
-
!(typeof item === 'object' && item != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutation: Invalid prop `%s` supplied to `%s`, ' + 'expected element at index %s to have query data.', fragmentName, _this.constructor.name, ii) : require("fbjs/lib/invariant")(false) : void 0;
|
241
|
-
|
242
|
-
if (process.env.NODE_ENV !== "production") {
|
243
|
-
var hasFragmentData = require("./RelayFragmentPointer").hasFragment(item, fragment);
|
244
|
-
|
245
|
-
if (!hasFragmentData && !_this._didShowFakeDataWarning) {
|
246
|
-
_this._didShowFakeDataWarning = true;
|
247
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayMutation: Expected prop `%s` element at index %s ' + 'supplied to `%s` to be data fetched by Relay. This is ' + 'likely an error unless you are purposely passing in mock ' + "data that conforms to the shape of this mutation's fragment.", fragmentName, ii, _this.constructor.name) : void 0;
|
248
|
-
}
|
249
|
-
}
|
250
|
-
|
251
|
-
var dataID = require("./RelayRecord").getDataIDForObject(item);
|
252
|
-
|
253
|
-
!dataID ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutation: Invalid prop `%s` supplied to `%s`, ' + 'expected element at index %s to have query data.', fragmentName, _this.constructor.name, ii) : require("fbjs/lib/invariant")(false) : void 0;
|
254
|
-
return dataID;
|
255
|
-
});
|
256
|
-
resolvedProps[fragmentName] = dataIDs.map(function (dataID) {
|
257
|
-
return _this._environment.read(fragment, dataID);
|
258
|
-
});
|
259
|
-
} else {
|
260
|
-
!!Array.isArray(propValue) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayMutation: Invalid prop `%s` supplied to `%s`, expected a ' + 'single record because the corresponding fragment is not plural.', fragmentName, _this.constructor.name) : require("fbjs/lib/invariant")(false) : void 0;
|
261
|
-
|
262
|
-
if (process.env.NODE_ENV !== "production") {
|
263
|
-
var hasFragmentData = require("./RelayFragmentPointer").hasFragment(propValue, fragment);
|
264
|
-
|
265
|
-
if (!hasFragmentData && !_this._didShowFakeDataWarning) {
|
266
|
-
_this._didShowFakeDataWarning = true;
|
267
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayMutation: Expected prop `%s` supplied to `%s` to ' + 'be data fetched by Relay. This is likely an error unless ' + 'you are purposely passing in mock data that conforms to ' + "the shape of this mutation's fragment.", fragmentName, _this.constructor.name) : void 0;
|
268
|
-
}
|
269
|
-
}
|
270
|
-
|
271
|
-
var dataID = require("./RelayRecord").getDataIDForObject(propValue);
|
272
|
-
|
273
|
-
if (dataID) {
|
274
|
-
resolvedProps[fragmentName] = _this._environment.read(fragment, dataID);
|
275
|
-
}
|
276
|
-
}
|
277
|
-
});
|
278
|
-
|
279
|
-
this.props = resolvedProps;
|
280
|
-
|
281
|
-
if (!this._didValidateConfig) {
|
282
|
-
this.getConfigs().forEach(function (config) {
|
283
|
-
return require("./validateMutationConfig")(config, _this.constructor.name);
|
284
|
-
});
|
285
|
-
this._didValidateConfig = true;
|
286
|
-
}
|
287
|
-
};
|
288
|
-
|
289
|
-
RelayMutation.getFragment = function getFragment(fragmentName, variableMapping) {
|
290
|
-
var _this2 = this;
|
291
|
-
|
292
|
-
var fragments = this.fragments;
|
293
|
-
var fragmentBuilder = fragments[fragmentName];
|
294
|
-
|
295
|
-
if (!fragmentBuilder) {
|
296
|
-
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, '%s.getFragment(): `%s` is not a valid fragment name. Available ' + 'fragments names: %s', this.name, fragmentName, Object.keys(fragments).map(function (name) {
|
297
|
-
return '`' + name + '`';
|
298
|
-
}).join(', ')) : require("fbjs/lib/invariant")(false) : void 0;
|
299
|
-
}
|
300
|
-
|
301
|
-
var initialVariables = this.initialVariables || {};
|
302
|
-
var prepareVariables = this.prepareVariables;
|
303
|
-
return require("./RelayFragmentReference").createForContainer(function () {
|
304
|
-
return buildMutationFragment(_this2.name, fragmentName, fragmentBuilder, initialVariables);
|
305
|
-
}, initialVariables, variableMapping, prepareVariables);
|
306
|
-
};
|
307
|
-
|
308
|
-
return RelayMutation;
|
309
|
-
}();
|
310
|
-
/**
|
311
|
-
* Wrapper around `buildRQL.Fragment` with contextual error messages.
|
312
|
-
*/
|
313
|
-
|
314
|
-
|
315
|
-
function buildMutationFragment(mutationName, fragmentName, fragmentBuilder, variables) {
|
316
|
-
var fragment = require("./buildRQL").Fragment(fragmentBuilder, variables);
|
317
|
-
|
318
|
-
!fragment ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'Relay.QL defined on mutation `%s` named `%s` is not a valid fragment. ' + 'A typical fragment is defined using: Relay.QL`fragment on Type {...}`', mutationName, fragmentName) : require("fbjs/lib/invariant")(false) : void 0;
|
319
|
-
return fragment;
|
320
|
-
}
|
321
|
-
|
322
|
-
module.exports = RelayMutation;
|
@@ -1,47 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
/**
|
13
|
-
* @internal
|
14
|
-
*
|
15
|
-
* Helper functions to print mutation queries for debugging purposes.
|
16
|
-
*/
|
17
|
-
var RelayMutationDebugPrinter = {
|
18
|
-
printOptimisticMutation: function printOptimisticMutation(query, response) {
|
19
|
-
/* eslint-disable no-console */
|
20
|
-
if (!console.groupCollapsed || !console.groupEnd) {
|
21
|
-
return;
|
22
|
-
}
|
23
|
-
|
24
|
-
RelayMutationDebugPrinter.printMutation(query, 'Optimistic');
|
25
|
-
console.groupCollapsed('Optimistic Response');
|
26
|
-
console.log(response);
|
27
|
-
console.groupEnd();
|
28
|
-
/* eslint-enable no-console */
|
29
|
-
},
|
30
|
-
printMutation: function printMutation(query, name) {
|
31
|
-
/* eslint-disable no-console */
|
32
|
-
if (!console.groupCollapsed || !console.groupEnd) {
|
33
|
-
return;
|
34
|
-
}
|
35
|
-
|
36
|
-
var printedQuery = query ? require("./printRelayQuery")(query) : null;
|
37
|
-
name = name || 'Mutation';
|
38
|
-
console.groupCollapsed(name + ' Variables');
|
39
|
-
console.log(printedQuery ? printedQuery.variables : {});
|
40
|
-
console.groupEnd();
|
41
|
-
console.groupCollapsed(name + ' Query');
|
42
|
-
console.log(printedQuery ? printedQuery.text : '');
|
43
|
-
console.groupEnd();
|
44
|
-
/* eslint-enable no-console */
|
45
|
-
}
|
46
|
-
};
|
47
|
-
module.exports = RelayMutationDebugPrinter;
|