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
@@ -9,26 +9,38 @@
|
|
9
9
|
*/
|
10
10
|
'use strict';
|
11
11
|
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
13
|
+
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
15
|
+
|
16
|
+
var areEqual = require("fbjs/lib/areEqual");
|
17
|
+
|
18
|
+
var emptyFunction = require("fbjs/lib/emptyFunction");
|
19
|
+
|
20
|
+
var invariant = require("fbjs/lib/invariant");
|
21
|
+
|
22
|
+
var warning = require("fbjs/lib/warning");
|
23
|
+
|
24
|
+
var _require = require("relay-runtime"),
|
25
|
+
Network = _require.Network,
|
26
|
+
isRelayModernEnvironment = _require.isRelayModernEnvironment;
|
27
|
+
|
12
28
|
/**
|
13
29
|
* The next id to return from `generateId()`.
|
14
30
|
*/
|
15
31
|
var nextId = 0;
|
16
|
-
/**
|
17
|
-
* The pending network fetches for the mocked network.
|
18
|
-
*/
|
19
|
-
|
20
|
-
var pendingFetches = [];
|
21
32
|
|
22
33
|
var ReactRelayTestMocker =
|
23
34
|
/*#__PURE__*/
|
24
35
|
function () {
|
25
36
|
function ReactRelayTestMocker(env) {
|
26
|
-
this
|
37
|
+
(0, _defineProperty2["default"])(this, "_defaults", {});
|
38
|
+
(0, _defineProperty2["default"])(this, "_pendingFetches", []);
|
27
39
|
|
28
|
-
if (
|
40
|
+
if (isRelayModernEnvironment(env)) {
|
29
41
|
this._mockNetworkLayer(env);
|
30
42
|
} else {
|
31
|
-
process.env.NODE_ENV !== "production" ?
|
43
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'Netork mocking is currently only supported in Relay Modern. ' + 'You will not be able to resolve requests made with Relay ' + 'Classic environments.') : void 0;
|
32
44
|
}
|
33
45
|
|
34
46
|
this._environment = env;
|
@@ -45,7 +57,7 @@ function () {
|
|
45
57
|
var toRet = nextId.toString();
|
46
58
|
nextId++;
|
47
59
|
return toRet;
|
48
|
-
}
|
60
|
+
}
|
49
61
|
/**
|
50
62
|
* Create a unique identifier for a (query, variables) pair.
|
51
63
|
* @param request: the request associated with the query
|
@@ -55,16 +67,16 @@ function () {
|
|
55
67
|
* @returns a string which can later be used to uniquely identify this query
|
56
68
|
* in the list of pending queries
|
57
69
|
*/
|
58
|
-
|
70
|
+
;
|
59
71
|
|
60
72
|
ReactRelayTestMocker.getIdentifier = function getIdentifier(request) {
|
61
73
|
return request.name;
|
62
|
-
}
|
74
|
+
}
|
63
75
|
/**
|
64
76
|
* Remove variables that we don't need from the query that will make it more
|
65
77
|
* annoying to test (e.g. client_mutation_id, actor_id)
|
66
78
|
*/
|
67
|
-
|
79
|
+
;
|
68
80
|
|
69
81
|
ReactRelayTestMocker.stripUnused = function stripUnused(variables) {
|
70
82
|
if (variables.input) {
|
@@ -75,7 +87,7 @@ function () {
|
|
75
87
|
}
|
76
88
|
|
77
89
|
return variables;
|
78
|
-
}
|
90
|
+
}
|
79
91
|
/**
|
80
92
|
* Replace the environment's network layer with a mocked out one to allow for
|
81
93
|
* better testing. Mocking the network allows testing without using a mocked
|
@@ -83,7 +95,7 @@ function () {
|
|
83
95
|
* in refetch containers, for example. It also allows test writers to see how
|
84
96
|
* their components behave under error conditions.
|
85
97
|
*/
|
86
|
-
|
98
|
+
;
|
87
99
|
|
88
100
|
var _proto = ReactRelayTestMocker.prototype;
|
89
101
|
|
@@ -91,10 +103,8 @@ function () {
|
|
91
103
|
var _this = this;
|
92
104
|
|
93
105
|
var fetch = function fetch(request, variables, cacheConfig) {
|
94
|
-
var resolve =
|
95
|
-
|
96
|
-
var reject = require("fbjs/lib/emptyFunction");
|
97
|
-
|
106
|
+
var resolve = emptyFunction;
|
107
|
+
var reject = emptyFunction;
|
98
108
|
var promise = new Promise(function (res, rej) {
|
99
109
|
resolve = res;
|
100
110
|
reject = rej;
|
@@ -107,7 +117,7 @@ function () {
|
|
107
117
|
return typeof payload === 'function' ? payload(strippedVars) : payload;
|
108
118
|
}
|
109
119
|
|
110
|
-
|
120
|
+
_this._pendingFetches.push({
|
111
121
|
ident: ident,
|
112
122
|
cacheConfig: cacheConfig,
|
113
123
|
deferred: {
|
@@ -117,30 +127,31 @@ function () {
|
|
117
127
|
request: request,
|
118
128
|
variables: variables
|
119
129
|
});
|
130
|
+
|
120
131
|
return promise;
|
121
132
|
};
|
122
133
|
|
123
|
-
function isLoading(ident) {
|
124
|
-
return
|
134
|
+
var isLoading = function isLoading(ident) {
|
135
|
+
return _this._pendingFetches.some(function (pending) {
|
125
136
|
return pending.ident === ident;
|
126
137
|
});
|
127
|
-
}
|
138
|
+
};
|
128
139
|
|
129
|
-
function resolveRawQuery(toResolve, payload) {
|
130
|
-
|
140
|
+
var resolveRawQuery = function resolveRawQuery(toResolve, payload) {
|
141
|
+
_this._pendingFetches = _this._pendingFetches.filter(function (pending) {
|
131
142
|
return pending !== toResolve;
|
132
143
|
});
|
133
144
|
var deferred = toResolve.deferred;
|
134
145
|
deferred.resolve(payload);
|
135
|
-
}
|
146
|
+
};
|
136
147
|
|
137
|
-
function rejectQuery(toResolve, payload) {
|
138
|
-
|
148
|
+
var rejectQuery = function rejectQuery(toResolve, payload) {
|
149
|
+
_this._pendingFetches = _this._pendingFetches.filter(function (pending) {
|
139
150
|
return pending !== toResolve;
|
140
151
|
});
|
141
152
|
var deferred = toResolve.deferred;
|
142
153
|
deferred.reject(payload.error);
|
143
|
-
}
|
154
|
+
};
|
144
155
|
|
145
156
|
env.mock = {
|
146
157
|
isLoading: isLoading,
|
@@ -150,35 +161,35 @@ function () {
|
|
150
161
|
};
|
151
162
|
env.hasMockedNetwork = true;
|
152
163
|
|
153
|
-
env.__setNet(
|
164
|
+
env.__setNet(Network.create(fetch));
|
154
165
|
|
155
166
|
return env;
|
156
167
|
};
|
157
168
|
|
158
169
|
_proto._getDefaults = function _getDefaults() {
|
159
170
|
return this._defaults;
|
160
|
-
}
|
171
|
+
}
|
161
172
|
/**
|
162
173
|
* set a default payload for a given query
|
163
174
|
*/
|
164
|
-
|
175
|
+
;
|
165
176
|
|
166
177
|
_proto.setDefault = function setDefault(toSet) {
|
167
178
|
var query = toSet.query,
|
168
179
|
payload = toSet.payload;
|
169
180
|
var ident = ReactRelayTestMocker.getIdentifier(query.params);
|
170
181
|
this._defaults[ident] = payload;
|
171
|
-
}
|
182
|
+
}
|
172
183
|
/**
|
173
184
|
* remove a default payload for a given query
|
174
185
|
*/
|
175
|
-
|
186
|
+
;
|
176
187
|
|
177
188
|
_proto.unsetDefault = function unsetDefault(toUnset) {
|
178
189
|
var query = toUnset.query;
|
179
190
|
var ident = ReactRelayTestMocker.getIdentifier(query.params);
|
180
191
|
delete this._defaults[ident];
|
181
|
-
}
|
192
|
+
}
|
182
193
|
/**
|
183
194
|
* Write directly to the Relay store instead of trying to resolve a query that
|
184
195
|
* was sent via the network.
|
@@ -187,7 +198,7 @@ function () {
|
|
187
198
|
* (via `createFragmentContainer`). The component under test should also be
|
188
199
|
* wrapped in a `RelayTestRenderer`.
|
189
200
|
*/
|
190
|
-
|
201
|
+
;
|
191
202
|
|
192
203
|
_proto.dataWrite = function dataWrite(config) {
|
193
204
|
var query = config.query,
|
@@ -195,10 +206,10 @@ function () {
|
|
195
206
|
payload = config.payload;
|
196
207
|
var createOperationDescriptor = this._environment.unstable_internal.createOperationDescriptor;
|
197
208
|
var operationDescriptor = createOperationDescriptor(query, variables);
|
198
|
-
!(payload.data != null && payload.errors === undefined) ? process.env.NODE_ENV !== "production" ?
|
209
|
+
!(payload.data != null && payload.errors === undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Only `data` can be written when using `writeDirect`. You may need to ' + 'wrap your payload in an object like `{data: payload}`.') : invariant(false) : void 0;
|
199
210
|
|
200
211
|
this._environment.commitPayload(operationDescriptor, payload.data);
|
201
|
-
}
|
212
|
+
}
|
202
213
|
/**
|
203
214
|
* Write the data specified in config's payload to the instance's environment.
|
204
215
|
* NOTE: callers may need to invoke `jest.runOnlyPendingTimers()` after
|
@@ -207,10 +218,10 @@ function () {
|
|
207
218
|
* @param config: an object containing the data to write and the query and
|
208
219
|
* variables that the payload is simulating a response to
|
209
220
|
*/
|
210
|
-
|
221
|
+
;
|
211
222
|
|
212
223
|
_proto.networkWrite = function networkWrite(config) {
|
213
|
-
!this._environment.hasMockedNetwork ? process.env.NODE_ENV !== "production" ?
|
224
|
+
!this._environment.hasMockedNetwork ? process.env.NODE_ENV !== "production" ? invariant(false, 'You cannot resolve queries without a mocked environment. Did you mean ' + 'to use `writeDirect` instead?') : invariant(false) : void 0;
|
214
225
|
var query = config.query,
|
215
226
|
variables = config.variables,
|
216
227
|
payload = config.payload;
|
@@ -224,14 +235,15 @@ function () {
|
|
224
235
|
}
|
225
236
|
|
226
237
|
var toResolve;
|
227
|
-
|
238
|
+
|
239
|
+
this._pendingFetches.forEach(function (pending) {
|
228
240
|
var pendingVars = pending.variables;
|
229
241
|
|
230
242
|
if (pending.ident === ident) {
|
231
|
-
!(!toResolve || variables) ? process.env.NODE_ENV !== "production" ?
|
243
|
+
!(!toResolve || variables) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Multiple queries with the same name are currently pending. You ' + 'should pass variables to `write` so that it can determine which ' + 'to resolve') : invariant(false) : void 0;
|
232
244
|
|
233
245
|
if (variables) {
|
234
|
-
if (
|
246
|
+
if (areEqual(pendingVars, usedVars)) {
|
235
247
|
toResolve = pending;
|
236
248
|
}
|
237
249
|
} else {
|
@@ -239,8 +251,9 @@ function () {
|
|
239
251
|
}
|
240
252
|
}
|
241
253
|
});
|
254
|
+
|
242
255
|
var varMessage = usedVars ? ' - variables: ' + JSON.stringify(usedVars) : '';
|
243
|
-
!toResolve ? process.env.NODE_ENV !== "production" ?
|
256
|
+
!toResolve ? process.env.NODE_ENV !== "production" ? invariant(false, 'You are attempting to resolve a query that has not been fetched ' + '(%s%s).\n\tPlease ensure you passed the correct variables, or use ' + '`writeDirect` instead.', ident, varMessage) : invariant(false) : void 0;
|
244
257
|
var realPayload = typeof payload === 'function' ? payload(toResolve.variables) : payload; // if there are errors, reject the query
|
245
258
|
|
246
259
|
if (realPayload.errors != null && realPayload.errors.length > 0) {
|
package/lib/ReactRelayTypes.js
CHANGED
package/lib/RelayContext.js
CHANGED
@@ -9,12 +9,18 @@
|
|
9
9
|
*/
|
10
10
|
'use strict';
|
11
11
|
|
12
|
+
var invariant = require("fbjs/lib/invariant");
|
13
|
+
|
14
|
+
var isRelayEnvironment = require("./isRelayEnvironment");
|
15
|
+
|
16
|
+
var isRelayVariables = require("./isRelayVariables");
|
17
|
+
|
12
18
|
/**
|
13
19
|
* Asserts that the input is a matches the `RelayContext` type defined in
|
14
20
|
* `RelayEnvironmentTypes` and returns it as that type.
|
15
21
|
*/
|
16
22
|
function assertRelayContext(relay) {
|
17
|
-
!isRelayContext(relay) ? process.env.NODE_ENV !== "production" ?
|
23
|
+
!isRelayContext(relay) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayContext: Expected `context.relay` to be an object conforming to ' + 'the `RelayContext` interface, got `%s`.', relay) : invariant(false) : void 0;
|
18
24
|
return relay;
|
19
25
|
}
|
20
26
|
/**
|
@@ -24,7 +30,7 @@ function assertRelayContext(relay) {
|
|
24
30
|
|
25
31
|
|
26
32
|
function isRelayContext(context) {
|
27
|
-
return typeof context === 'object' && context !== null && !Array.isArray(context) &&
|
33
|
+
return typeof context === 'object' && context !== null && !Array.isArray(context) && isRelayEnvironment(context.environment) && isRelayVariables(context.variables);
|
28
34
|
}
|
29
35
|
|
30
36
|
module.exports = {
|
package/lib/assertFragmentMap.js
CHANGED
@@ -4,21 +4,23 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* @format
|
9
9
|
*/
|
10
10
|
'use strict';
|
11
11
|
|
12
|
+
var invariant = require("fbjs/lib/invariant");
|
13
|
+
|
12
14
|
/**
|
13
15
|
* Fail fast if the user supplies invalid fragments as input.
|
14
16
|
*/
|
15
|
-
function assertFragmentMap(componentName,
|
16
|
-
!(
|
17
|
+
function assertFragmentMap(componentName, fragmentSpec) {
|
18
|
+
!(fragmentSpec && typeof fragmentSpec === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Could not create Relay Container for `%s`. ' + 'Expected a set of GraphQL fragments, got `%s` instead.', componentName, fragmentSpec) : invariant(false) : void 0;
|
17
19
|
|
18
|
-
for (var key in
|
19
|
-
if (
|
20
|
-
var fragment =
|
21
|
-
!(fragment && (typeof fragment === 'object' || typeof fragment === 'function')) ? process.env.NODE_ENV !== "production" ?
|
20
|
+
for (var key in fragmentSpec) {
|
21
|
+
if (fragmentSpec.hasOwnProperty(key)) {
|
22
|
+
var fragment = fragmentSpec[key];
|
23
|
+
!(fragment && (typeof fragment === 'object' || typeof fragment === 'function')) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Could not create Relay Container for `%s`. ' + 'The value of fragment `%s` was expected to be a fragment, got `%s` instead.', componentName, key, fragment) : invariant(false) : void 0;
|
22
24
|
}
|
23
25
|
}
|
24
26
|
}
|
@@ -9,7 +9,25 @@
|
|
9
9
|
*/
|
10
10
|
'use strict';
|
11
11
|
|
12
|
-
var
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
13
|
+
|
14
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
15
|
+
|
16
|
+
var React = require("react");
|
17
|
+
|
18
|
+
var ReactRelayContext = require("./ReactRelayContext");
|
19
|
+
|
20
|
+
var assertFragmentMap = require("./assertFragmentMap");
|
21
|
+
|
22
|
+
var invariant = require("fbjs/lib/invariant");
|
23
|
+
|
24
|
+
var mapObject = require("fbjs/lib/mapObject");
|
25
|
+
|
26
|
+
var readContext = require("./readContext");
|
27
|
+
|
28
|
+
var _require = require("./ReactRelayContainerUtils"),
|
29
|
+
getComponentName = _require.getComponentName,
|
30
|
+
getContainerName = _require.getContainerName;
|
13
31
|
|
14
32
|
/**
|
15
33
|
* Creates a component class whose instances adapt to the
|
@@ -19,10 +37,8 @@ var _extends2 = require("@babel/runtime/helpers/interopRequireDefault")(require(
|
|
19
37
|
*/
|
20
38
|
function buildReactRelayContainer(ComponentClass, fragmentSpec, createContainerWithFragments) {
|
21
39
|
// Sanity-check user-defined fragment input
|
22
|
-
var containerName =
|
23
|
-
|
24
|
-
require("./assertFragmentMap")(require("./ReactRelayContainerUtils").getComponentName(ComponentClass), fragmentSpec); // Memoize a container for the last environment instance encountered
|
25
|
-
|
40
|
+
var containerName = getContainerName(ComponentClass);
|
41
|
+
assertFragmentMap(getComponentName(ComponentClass), fragmentSpec); // Memoize a container for the last environment instance encountered
|
26
42
|
|
27
43
|
var environment;
|
28
44
|
var Container;
|
@@ -36,13 +52,13 @@ function buildReactRelayContainer(ComponentClass, fragmentSpec, createContainerW
|
|
36
52
|
isRelayModernEnvironment = _require2.isRelayModernEnvironment;
|
37
53
|
|
38
54
|
if (!isRelayModernEnvironment(environment)) {
|
39
|
-
throw new Error('RelayModernContainer: Can only use Relay Modern component ' + "".concat(containerName, " in a Relay Modern environment
|
55
|
+
throw new Error('RelayModernContainer: Can only use Relay Modern component ' + "".concat(containerName, " in a Relay Modern environment!"));
|
40
56
|
}
|
41
57
|
}
|
42
58
|
|
43
59
|
var getFragmentFromTag = environment.unstable_internal.getFragment;
|
44
60
|
|
45
|
-
var _fragments =
|
61
|
+
var _fragments = mapObject(fragmentSpec, getFragmentFromTag);
|
46
62
|
|
47
63
|
Container = createContainerWithFragments(ComponentClass, _fragments); // Attach static lifecycle to wrapper component so React can see it.
|
48
64
|
|
@@ -53,31 +69,24 @@ function buildReactRelayContainer(ComponentClass, fragmentSpec, createContainerW
|
|
53
69
|
return new Container(props);
|
54
70
|
}
|
55
71
|
|
56
|
-
|
57
|
-
|
72
|
+
ContainerConstructor.prototype = React.Component.prototype;
|
73
|
+
ContainerConstructor.displayName = containerName;
|
58
74
|
|
59
|
-
|
60
|
-
|
75
|
+
function forwardRef(props, ref) {
|
76
|
+
var context = readContext(ReactRelayContext);
|
77
|
+
!context ? process.env.NODE_ENV !== "production" ? invariant(false, "".concat(containerName, " tried to render a context that was ") + "not valid this means that ".concat(containerName, " was rendered outside of a ") + 'query renderer.') : invariant(false) : void 0;
|
78
|
+
return React.createElement(ContainerConstructor, (0, _extends2["default"])({}, props, {
|
61
79
|
__relayContext: context,
|
62
80
|
componentRef: props.componentRef || ref
|
63
81
|
}));
|
64
82
|
}
|
65
83
|
|
66
84
|
forwardRef.displayName = containerName;
|
67
|
-
|
68
|
-
var ForwardContainer = require("react").forwardRef(forwardRef);
|
85
|
+
var ForwardContainer = React.forwardRef(forwardRef);
|
69
86
|
|
70
87
|
if (process.env.NODE_ENV !== "production") {
|
71
|
-
|
72
|
-
|
73
|
-
ForwardContainer.__ComponentClass = ComponentClass; // Classic container static methods.
|
74
|
-
|
75
|
-
/* $FlowFixMe(>=0.89.0 site=www,mobile,react_native_fb,oss) Suppressing
|
76
|
-
* errors found while preparing to upgrade to 0.89.0 */
|
77
|
-
|
78
|
-
ForwardContainer.getFragment = function getFragmentOnModernContainer() {
|
79
|
-
throw new Error("RelayModernContainer: ".concat(containerName, ".getFragment() was called on ") + 'a Relay Modern component by a Relay Classic or Relay Compat ' + 'component.\n' + 'When using Relay Modern and Relay Classic in the same ' + 'application, ensure components use Relay Compat to work in ' + 'both environments.\n' + 'See: http://facebook.github.io/relay/docs/relay-compat.html');
|
80
|
-
};
|
88
|
+
// Used by RelayModernTestUtils
|
89
|
+
ForwardContainer.__ComponentClass = ComponentClass;
|
81
90
|
}
|
82
91
|
/* $FlowFixMe(>=0.89.0 site=www,mobile,react_native_fb,oss) Suppressing errors
|
83
92
|
* found while preparing to upgrade to 0.89.0 */
|
package/lib/index.js
ADDED
@@ -0,0 +1,41 @@
|
|
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 ReactRelayContext = require("./ReactRelayContext");
|
13
|
+
|
14
|
+
var ReactRelayFragmentContainer = require("./ReactRelayFragmentContainer");
|
15
|
+
|
16
|
+
var ReactRelayPaginationContainer = require("./ReactRelayPaginationContainer");
|
17
|
+
|
18
|
+
var ReactRelayQueryRenderer = require("./ReactRelayQueryRenderer");
|
19
|
+
|
20
|
+
var ReactRelayRefetchContainer = require("./ReactRelayRefetchContainer");
|
21
|
+
|
22
|
+
var RelayRuntime = require("relay-runtime");
|
23
|
+
|
24
|
+
/**
|
25
|
+
* The public interface to React Relay.
|
26
|
+
*/
|
27
|
+
module.exports = {
|
28
|
+
QueryRenderer: ReactRelayQueryRenderer,
|
29
|
+
MutationTypes: RelayRuntime.MutationTypes,
|
30
|
+
RangeOperations: RelayRuntime.RangeOperations,
|
31
|
+
ReactRelayContext: ReactRelayContext,
|
32
|
+
applyOptimisticMutation: RelayRuntime.applyOptimisticMutation,
|
33
|
+
commitLocalUpdate: RelayRuntime.commitLocalUpdate,
|
34
|
+
commitMutation: RelayRuntime.commitMutation,
|
35
|
+
createFragmentContainer: ReactRelayFragmentContainer.createContainer,
|
36
|
+
createPaginationContainer: ReactRelayPaginationContainer.createContainer,
|
37
|
+
createRefetchContainer: ReactRelayRefetchContainer.createContainer,
|
38
|
+
fetchQuery: RelayRuntime.fetchQuery,
|
39
|
+
graphql: RelayRuntime.graphql,
|
40
|
+
requestSubscription: RelayRuntime.requestSubscription
|
41
|
+
};
|
package/lib/isRelayVariables.js
CHANGED
package/lib/readContext.js
CHANGED
@@ -4,16 +4,19 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* @format
|
9
9
|
*/
|
10
10
|
'use strict';
|
11
11
|
|
12
|
-
var
|
12
|
+
var React = require("react");
|
13
|
+
|
14
|
+
var _React$__SECRET_INTER =
|
13
15
|
/* $FlowFixMe Flow doesn't know about React's internals for good reason,
|
14
16
|
but for now, Relay needs the dispatcher to read context. */
|
15
|
-
|
16
|
-
|
17
|
+
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
18
|
+
ReactCurrentDispatcher = _React$__SECRET_INTER.ReactCurrentDispatcher,
|
19
|
+
ReactCurrentOwner = _React$__SECRET_INTER.ReactCurrentOwner;
|
17
20
|
|
18
21
|
function readContext(Context) {
|
19
22
|
var dispatcher = ReactCurrentDispatcher != null ? ReactCurrentDispatcher.current : ReactCurrentOwner.currentDispatcher;
|
package/package.json
CHANGED
@@ -1,22 +1,21 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-relay",
|
3
3
|
"description": "A framework for building GraphQL-driven React applications.",
|
4
|
-
"version": "
|
4
|
+
"version": "5.0.0",
|
5
5
|
"keywords": [
|
6
6
|
"graphql",
|
7
7
|
"relay",
|
8
8
|
"react"
|
9
9
|
],
|
10
10
|
"license": "MIT",
|
11
|
-
"homepage": "https://
|
11
|
+
"homepage": "https://relay.dev",
|
12
12
|
"bugs": "https://github.com/facebook/relay/issues",
|
13
13
|
"repository": "facebook/relay",
|
14
14
|
"dependencies": {
|
15
15
|
"@babel/runtime": "^7.0.0",
|
16
16
|
"fbjs": "^1.0.0",
|
17
17
|
"nullthrows": "^1.1.0",
|
18
|
-
"
|
19
|
-
"relay-runtime": "2.0.0-rc.2"
|
18
|
+
"relay-runtime": "5.0.0"
|
20
19
|
},
|
21
20
|
"peerDependencies": {
|
22
21
|
"react": "^16.5.0"
|
@@ -24,5 +23,6 @@
|
|
24
23
|
"directories": {
|
25
24
|
"": "./"
|
26
25
|
},
|
26
|
+
"main": "index.js",
|
27
27
|
"haste_commonjs": true
|
28
28
|
}
|