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/QueryBuilder.js
DELETED
@@ -1,228 +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_CALLS = [];
|
13
|
-
var EMPTY_CHILDREN = [];
|
14
|
-
var EMPTY_DIRECTIVES = [];
|
15
|
-
var EMPTY_METADATA = {};
|
16
|
-
|
17
|
-
if (process.env.NODE_ENV !== "production") {
|
18
|
-
Object.freeze(EMPTY_CALLS);
|
19
|
-
Object.freeze(EMPTY_CHILDREN);
|
20
|
-
Object.freeze(EMPTY_DIRECTIVES);
|
21
|
-
Object.freeze(EMPTY_METADATA);
|
22
|
-
}
|
23
|
-
/**
|
24
|
-
* @internal
|
25
|
-
*
|
26
|
-
* Helper methods for constructing concrete query objects.
|
27
|
-
*/
|
28
|
-
|
29
|
-
|
30
|
-
var QueryBuilder = {
|
31
|
-
createBatchCallVariable: function createBatchCallVariable(sourceQueryID, jsonPath) {
|
32
|
-
return {
|
33
|
-
kind: 'BatchCallVariable',
|
34
|
-
sourceQueryID: sourceQueryID,
|
35
|
-
jsonPath: jsonPath
|
36
|
-
};
|
37
|
-
},
|
38
|
-
createCall: function createCall(name, value, type) {
|
39
|
-
return {
|
40
|
-
kind: 'Call',
|
41
|
-
name: name,
|
42
|
-
metadata: {
|
43
|
-
type: type || null
|
44
|
-
},
|
45
|
-
value: value
|
46
|
-
};
|
47
|
-
},
|
48
|
-
createCallValue: function createCallValue(callValue) {
|
49
|
-
return {
|
50
|
-
kind: 'CallValue',
|
51
|
-
callValue: callValue
|
52
|
-
};
|
53
|
-
},
|
54
|
-
createCallVariable: function createCallVariable(callVariableName) {
|
55
|
-
return {
|
56
|
-
kind: 'CallVariable',
|
57
|
-
callVariableName: callVariableName
|
58
|
-
};
|
59
|
-
},
|
60
|
-
createDirective: function createDirective(name, args) {
|
61
|
-
return {
|
62
|
-
args: args,
|
63
|
-
kind: 'Directive',
|
64
|
-
name: name
|
65
|
-
};
|
66
|
-
},
|
67
|
-
createDirectiveArgument: function createDirectiveArgument(name, value) {
|
68
|
-
return {
|
69
|
-
name: name,
|
70
|
-
value: value
|
71
|
-
};
|
72
|
-
},
|
73
|
-
createField: function createField(partialField) {
|
74
|
-
var partialMetadata = partialField.metadata || EMPTY_METADATA;
|
75
|
-
return {
|
76
|
-
alias: partialField.alias,
|
77
|
-
calls: partialField.calls || EMPTY_CALLS,
|
78
|
-
children: partialField.children || EMPTY_CHILDREN,
|
79
|
-
directives: partialField.directives || EMPTY_DIRECTIVES,
|
80
|
-
fieldName: partialField.fieldName,
|
81
|
-
kind: 'Field',
|
82
|
-
metadata: {
|
83
|
-
canHaveSubselections: !!partialMetadata.canHaveSubselections,
|
84
|
-
inferredRootCallName: partialMetadata.inferredRootCallName,
|
85
|
-
inferredPrimaryKey: partialMetadata.inferredPrimaryKey,
|
86
|
-
isConnection: !!partialMetadata.isConnection,
|
87
|
-
isFindable: !!partialMetadata.isFindable,
|
88
|
-
isGenerated: !!partialMetadata.isGenerated,
|
89
|
-
isPlural: !!partialMetadata.isPlural,
|
90
|
-
isRequisite: !!partialMetadata.isRequisite,
|
91
|
-
isAbstract: !!partialMetadata.isAbstract
|
92
|
-
},
|
93
|
-
type: partialField.type
|
94
|
-
};
|
95
|
-
},
|
96
|
-
createFragment: function createFragment(partialFragment) {
|
97
|
-
var metadata = partialFragment.metadata || EMPTY_METADATA;
|
98
|
-
return {
|
99
|
-
children: partialFragment.children || EMPTY_CHILDREN,
|
100
|
-
directives: partialFragment.directives || EMPTY_DIRECTIVES,
|
101
|
-
id: require("./generateConcreteFragmentID")(),
|
102
|
-
kind: 'Fragment',
|
103
|
-
metadata: {
|
104
|
-
isAbstract: !!metadata.isAbstract,
|
105
|
-
pattern: !!metadata.pattern,
|
106
|
-
plural: !!metadata.plural // match the `@relay` argument name
|
107
|
-
|
108
|
-
},
|
109
|
-
name: partialFragment.name,
|
110
|
-
type: partialFragment.type
|
111
|
-
};
|
112
|
-
},
|
113
|
-
createMutation: function createMutation(partialMutation) {
|
114
|
-
var metadata = partialMutation.metadata || EMPTY_METADATA;
|
115
|
-
return {
|
116
|
-
calls: partialMutation.calls || EMPTY_CALLS,
|
117
|
-
children: partialMutation.children || EMPTY_CHILDREN,
|
118
|
-
directives: partialMutation.directives || EMPTY_DIRECTIVES,
|
119
|
-
kind: 'Mutation',
|
120
|
-
metadata: {
|
121
|
-
inputType: metadata.inputType
|
122
|
-
},
|
123
|
-
name: partialMutation.name,
|
124
|
-
responseType: partialMutation.responseType
|
125
|
-
};
|
126
|
-
},
|
127
|
-
createQuery: function createQuery(partialQuery) {
|
128
|
-
var metadata = partialQuery.metadata || EMPTY_METADATA;
|
129
|
-
var calls = [];
|
130
|
-
var identifyingArgName = metadata.identifyingArgName;
|
131
|
-
|
132
|
-
if (identifyingArgName == null && require("./RelayNodeInterface").isNodeRootCall(partialQuery.fieldName)) {
|
133
|
-
identifyingArgName = require("./RelayNodeInterface").ID;
|
134
|
-
}
|
135
|
-
|
136
|
-
if (identifyingArgName != null) {
|
137
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(partialQuery.identifyingArgValue != null, 'QueryBuilder.createQuery(): An argument value may be required for ' + 'query `%s(%s: ???)`.', partialQuery.fieldName, identifyingArgName) : void 0;
|
138
|
-
calls = [QueryBuilder.createCall(identifyingArgName, partialQuery.identifyingArgValue, metadata.identifyingArgType)];
|
139
|
-
}
|
140
|
-
|
141
|
-
return {
|
142
|
-
calls: calls,
|
143
|
-
children: partialQuery.children || EMPTY_CHILDREN,
|
144
|
-
directives: partialQuery.directives || EMPTY_DIRECTIVES,
|
145
|
-
fieldName: partialQuery.fieldName,
|
146
|
-
isDeferred: !!(partialQuery.isDeferred || metadata.isDeferred),
|
147
|
-
kind: 'Query',
|
148
|
-
metadata: {
|
149
|
-
identifyingArgName: identifyingArgName,
|
150
|
-
identifyingArgType: metadata.identifyingArgType,
|
151
|
-
isAbstract: !!metadata.isAbstract,
|
152
|
-
isPlural: !!metadata.isPlural
|
153
|
-
},
|
154
|
-
name: partialQuery.name,
|
155
|
-
type: partialQuery.type
|
156
|
-
};
|
157
|
-
},
|
158
|
-
createSubscription: function createSubscription(partialSubscription) {
|
159
|
-
var metadata = partialSubscription.metadata || EMPTY_METADATA;
|
160
|
-
return {
|
161
|
-
calls: partialSubscription.calls || EMPTY_CALLS,
|
162
|
-
children: partialSubscription.children || EMPTY_CHILDREN,
|
163
|
-
directives: partialSubscription.directives || EMPTY_DIRECTIVES,
|
164
|
-
kind: 'Subscription',
|
165
|
-
metadata: {
|
166
|
-
inputType: metadata.inputType
|
167
|
-
},
|
168
|
-
name: partialSubscription.name,
|
169
|
-
responseType: partialSubscription.responseType
|
170
|
-
};
|
171
|
-
},
|
172
|
-
getBatchCallVariable: function getBatchCallVariable(node) {
|
173
|
-
if (isConcreteKind(node, 'BatchCallVariable')) {
|
174
|
-
return node;
|
175
|
-
}
|
176
|
-
},
|
177
|
-
getCallVariable: function getCallVariable(node) {
|
178
|
-
if (isConcreteKind(node, 'CallVariable')) {
|
179
|
-
return node;
|
180
|
-
}
|
181
|
-
},
|
182
|
-
getField: function getField(node) {
|
183
|
-
if (isConcreteKind(node, 'Field')) {
|
184
|
-
return node;
|
185
|
-
}
|
186
|
-
},
|
187
|
-
getFragment: function getFragment(node) {
|
188
|
-
if (isConcreteKind(node, 'Fragment')) {
|
189
|
-
return node;
|
190
|
-
}
|
191
|
-
},
|
192
|
-
getFragmentDefinition: function getFragmentDefinition(node) {
|
193
|
-
if (isConcreteKind(node, 'FragmentDefinition')) {
|
194
|
-
return node;
|
195
|
-
}
|
196
|
-
},
|
197
|
-
getFragmentSpread: function getFragmentSpread(node) {
|
198
|
-
if (isConcreteKind(node, 'FragmentSpread')) {
|
199
|
-
return node;
|
200
|
-
}
|
201
|
-
},
|
202
|
-
getOperationDefinition: function getOperationDefinition(node) {
|
203
|
-
if (isConcreteKind(node, 'OperationDefinition')) {
|
204
|
-
return node;
|
205
|
-
}
|
206
|
-
},
|
207
|
-
getMutation: function getMutation(node) {
|
208
|
-
if (isConcreteKind(node, 'Mutation')) {
|
209
|
-
return node;
|
210
|
-
}
|
211
|
-
},
|
212
|
-
getQuery: function getQuery(node) {
|
213
|
-
if (isConcreteKind(node, 'Query')) {
|
214
|
-
return node;
|
215
|
-
}
|
216
|
-
},
|
217
|
-
getSubscription: function getSubscription(node) {
|
218
|
-
if (isConcreteKind(node, 'Subscription')) {
|
219
|
-
return node;
|
220
|
-
}
|
221
|
-
}
|
222
|
-
};
|
223
|
-
|
224
|
-
function isConcreteKind(node, kind) {
|
225
|
-
return typeof node === 'object' && node !== null && node.kind === kind;
|
226
|
-
}
|
227
|
-
|
228
|
-
module.exports = QueryBuilder;
|
@@ -1,29 +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
|
-
var _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
|
13
|
-
|
14
|
-
// As early as possible, check for the existence of the JavaScript globals which
|
15
|
-
// React Relay relies upon, and produce a clear message if they do not exist.
|
16
|
-
if (process.env.NODE_ENV !== "production") {
|
17
|
-
if (typeof Map !== 'function' || typeof Set !== 'function' || typeof Promise !== 'function' || typeof Object.assign !== 'function' || typeof Array.prototype.find !== 'function') {
|
18
|
-
throw new Error('react-relay requires Map, Set, Promise, Object.assign, and Array#find ' + 'to exist. Use a polyfill to provide these for older browsers.');
|
19
|
-
}
|
20
|
-
} // By default, assume that GraphQL is served at `/graphql` on the same domain.
|
21
|
-
// To override, use `Relay.injectNetworkLayer`.
|
22
|
-
|
23
|
-
|
24
|
-
require("./RelayStore").injectDefaultNetworkLayer(new (require("./RelayDefaultNetworkLayer"))('/graphql'));
|
25
|
-
|
26
|
-
module.exports = (0, _objectSpread2["default"])({}, require("./RelayPublic"), {
|
27
|
-
// Expose the default network layer to allow convenient re-configuration.
|
28
|
-
DefaultNetworkLayer: require("./RelayDefaultNetworkLayer")
|
29
|
-
});
|
@@ -1,175 +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 _extends2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/extends"));
|
13
|
-
|
14
|
-
var _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
|
15
|
-
|
16
|
-
/**
|
17
|
-
* `injectDefaultVariablesProvider()` allows classic versions of a container to
|
18
|
-
* inject default variable values for a fragment via the arguments of any
|
19
|
-
* references to it. This is useful for fragments that need to reference
|
20
|
-
* global query constants (e.g. the device pixel ratio) but may be included
|
21
|
-
* in classic queries that do not define the necessary param.
|
22
|
-
*/
|
23
|
-
var injectedDefaultVariablesProvider = null;
|
24
|
-
|
25
|
-
function injectDefaultVariablesProvider(variablesProvider) {
|
26
|
-
!!injectedDefaultVariablesProvider ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'injectDefaultVariablesProvider must be called no more than once.') : require("fbjs/lib/invariant")(false) : void 0;
|
27
|
-
injectedDefaultVariablesProvider = variablesProvider;
|
28
|
-
}
|
29
|
-
/**
|
30
|
-
* Sets a logging function that logs whether a compat container was rendered in
|
31
|
-
* a modern or classic environment.
|
32
|
-
*/
|
33
|
-
|
34
|
-
|
35
|
-
var injectedCompatLoggingFunction = function injectedCompatLoggingFunction() {};
|
36
|
-
|
37
|
-
function injectCompatLoggingFunction(loggingFunction) {
|
38
|
-
injectedCompatLoggingFunction = loggingFunction;
|
39
|
-
}
|
40
|
-
/**
|
41
|
-
* Creates a component class whose instances adapt to the
|
42
|
-
* `context.relay.environment` in which they are rendered and which have the
|
43
|
-
* necessary static methods (`getFragment()` etc) to be composed within classic
|
44
|
-
* `Relay.Containers`.
|
45
|
-
*
|
46
|
-
* The returned constructor uses the given `createContainerForEnvironment` to
|
47
|
-
* construct a new container type whenever a new environment is encountered;
|
48
|
-
* while the constructor is being used for the same environment (the expected
|
49
|
-
* majority case) this value is memoized to avoid creating unnecessary extra
|
50
|
-
* container definitions or unwrapping the environment-specific fragment
|
51
|
-
* defintions unnecessarily.
|
52
|
-
*/
|
53
|
-
|
54
|
-
|
55
|
-
function buildCompatContainer(ComponentClass, fragmentSpec, createContainerWithFragments) {
|
56
|
-
var compatModuleName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'unknown';
|
57
|
-
|
58
|
-
// Sanity-check user-defined fragment input
|
59
|
-
var containerName = require("./ReactRelayContainerUtils").getContainerName(ComponentClass);
|
60
|
-
|
61
|
-
require("./assertFragmentMap")(require("./ReactRelayContainerUtils").getComponentName(ComponentClass), fragmentSpec);
|
62
|
-
|
63
|
-
var injectedDefaultVariables = null;
|
64
|
-
|
65
|
-
function getDefaultVariables() {
|
66
|
-
if (injectedDefaultVariables == null) {
|
67
|
-
injectedDefaultVariables = injectedDefaultVariablesProvider ? injectedDefaultVariablesProvider() : {};
|
68
|
-
}
|
69
|
-
|
70
|
-
return injectedDefaultVariables;
|
71
|
-
} // Similar to RelayContainer.getFragment(), except that this returns a
|
72
|
-
// FragmentSpread in order to support referencing root variables.
|
73
|
-
|
74
|
-
|
75
|
-
function getFragment(fragmentName, variableMapping) {
|
76
|
-
injectedCompatLoggingFunction(compatModuleName, false);
|
77
|
-
var taggedNode = fragmentSpec[fragmentName];
|
78
|
-
!taggedNode ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'ReactRelayCompatContainerBuilder: Expected a fragment named `%s` to be defined ' + 'on `%s`.', fragmentName, containerName) : require("fbjs/lib/invariant")(false) : void 0;
|
79
|
-
|
80
|
-
var fragment = require("./RelayGraphQLTag").getClassicFragment(taggedNode);
|
81
|
-
|
82
|
-
var args = (0, _objectSpread2["default"])({}, getDefaultVariables(), variableMapping || {});
|
83
|
-
return {
|
84
|
-
kind: 'FragmentSpread',
|
85
|
-
args: args,
|
86
|
-
fragment: fragment
|
87
|
-
};
|
88
|
-
}
|
89
|
-
|
90
|
-
function hasVariable(variableName) {
|
91
|
-
return Object.keys(fragmentSpec).some(function (fragmentName) {
|
92
|
-
var fragment = require("./RelayGraphQLTag").getClassicFragment(fragmentSpec[fragmentName]);
|
93
|
-
|
94
|
-
return fragment.argumentDefinitions.some(function (argDef) {
|
95
|
-
return argDef.name === variableName;
|
96
|
-
});
|
97
|
-
});
|
98
|
-
} // Memoize a container for the last environment instance encountered
|
99
|
-
|
100
|
-
|
101
|
-
var environment;
|
102
|
-
var Container;
|
103
|
-
|
104
|
-
function ContainerConstructor(props) {
|
105
|
-
if (Container == null || props.__relayContext.environment !== environment) {
|
106
|
-
environment = props.__relayContext.environment;
|
107
|
-
injectedCompatLoggingFunction(compatModuleName, require("relay-runtime").isRelayModernEnvironment(environment));
|
108
|
-
var getFragmentFromTag = environment.unstable_internal.getFragment;
|
109
|
-
|
110
|
-
var _fragments = require("fbjs/lib/mapObject")(fragmentSpec, getFragmentFromTag);
|
111
|
-
|
112
|
-
Container = createContainerWithFragments(ComponentClass, _fragments); // Attach static lifecycle to wrapper component so React can see it.
|
113
|
-
|
114
|
-
ContainerConstructor.getDerivedStateFromProps = Container.getDerivedStateFromProps;
|
115
|
-
} // $FlowFixMe
|
116
|
-
|
117
|
-
|
118
|
-
return new Container(props);
|
119
|
-
}
|
120
|
-
|
121
|
-
function forwardRef(props, ref) {
|
122
|
-
var context = require("./readContext")(require("./ReactRelayContext"));
|
123
|
-
|
124
|
-
!context ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/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.') : require("fbjs/lib/invariant")(false) : void 0;
|
125
|
-
return require("react").createElement(ContainerConstructor, (0, _extends2["default"])({}, props, {
|
126
|
-
__relayContext: context,
|
127
|
-
componentRef: props.componentRef || ref
|
128
|
-
}));
|
129
|
-
}
|
130
|
-
|
131
|
-
forwardRef.displayName = containerName;
|
132
|
-
|
133
|
-
var ForwardContainer = require("react").forwardRef(forwardRef); // Classic container static methods
|
134
|
-
|
135
|
-
/* $FlowFixMe(>=0.89.0 site=www,mobile,react_native_fb,oss) Suppressing errors
|
136
|
-
* found while preparing to upgrade to 0.89.0 */
|
137
|
-
|
138
|
-
|
139
|
-
ForwardContainer.getFragment = getFragment;
|
140
|
-
/* $FlowFixMe(>=0.89.0 site=www,mobile,react_native_fb,oss) Suppressing errors
|
141
|
-
* found while preparing to upgrade to 0.89.0 */
|
142
|
-
|
143
|
-
ForwardContainer.getFragmentNames = function () {
|
144
|
-
return Object.keys(fragmentSpec);
|
145
|
-
};
|
146
|
-
/* $FlowFixMe(>=0.89.0 site=www,mobile,react_native_fb,oss) Suppressing errors
|
147
|
-
* found while preparing to upgrade to 0.89.0 */
|
148
|
-
|
149
|
-
|
150
|
-
ForwardContainer.hasFragment = function (name) {
|
151
|
-
return fragmentSpec.hasOwnProperty(name);
|
152
|
-
};
|
153
|
-
/* $FlowFixMe(>=0.89.0 site=www,mobile,react_native_fb,oss) Suppressing errors
|
154
|
-
* found while preparing to upgrade to 0.89.0 */
|
155
|
-
|
156
|
-
|
157
|
-
ForwardContainer.hasVariable = hasVariable;
|
158
|
-
|
159
|
-
if (process.env.NODE_ENV !== "production") {
|
160
|
-
/* $FlowFixMe(>=0.89.0 site=www,mobile,react_native_fb,oss) Suppressing
|
161
|
-
* errors found while preparing to upgrade to 0.89.0 */
|
162
|
-
ForwardContainer.__ComponentClass = ComponentClass;
|
163
|
-
} // Create a back-reference from the Component to the Container for cases
|
164
|
-
// where a Classic Component might refer to itself, expecting a Container.
|
165
|
-
|
166
|
-
|
167
|
-
ComponentClass.__container__ = ForwardContainer;
|
168
|
-
return ForwardContainer;
|
169
|
-
}
|
170
|
-
|
171
|
-
module.exports = {
|
172
|
-
injectDefaultVariablesProvider: injectDefaultVariablesProvider,
|
173
|
-
injectCompatLoggingFunction: injectCompatLoggingFunction,
|
174
|
-
buildCompatContainer: buildCompatContainer
|
175
|
-
};
|
@@ -1,28 +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
|
-
* The public interface to React Relay which supports a compatibility mode to
|
14
|
-
* continue to work with the classic Relay runtime.
|
15
|
-
*/
|
16
|
-
module.exports = {
|
17
|
-
QueryRenderer: require("./ReactRelayQueryRenderer"),
|
18
|
-
MutationTypes: require("relay-runtime").MutationTypes,
|
19
|
-
RangeOperations: require("relay-runtime").RangeOperations,
|
20
|
-
applyOptimisticMutation: require("./RelayCompatMutations").applyUpdate,
|
21
|
-
commitMutation: require("./RelayCompatMutations").commitUpdate,
|
22
|
-
createFragmentContainer: require("./RelayCompatContainer").createContainer,
|
23
|
-
createPaginationContainer: require("./RelayCompatPaginationContainer").createContainer,
|
24
|
-
createRefetchContainer: require("./RelayCompatRefetchContainer").createContainer,
|
25
|
-
fetchQuery: require("relay-runtime").fetchQuery,
|
26
|
-
graphql: require("relay-runtime").graphql,
|
27
|
-
injectDefaultVariablesProvider: require("./ReactRelayCompatContainerBuilder").injectDefaultVariablesProvider
|
28
|
-
};
|
@@ -1,30 +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
|
-
function profileContainer(Container, containerName) {
|
13
|
-
require("relay-runtime").RelayProfiler.instrumentMethods(Container.prototype, {
|
14
|
-
constructor: "".concat(containerName, ".prototype.constructor"),
|
15
|
-
UNSAFE_componentWillReceiveProps: "".concat(containerName, ".prototype.UNSAFE_componentWillReceiveProps"),
|
16
|
-
componentWillUnmount: "".concat(containerName, ".prototype.componentWillUnmount"),
|
17
|
-
shouldComponentUpdate: "".concat(containerName, ".prototype.shouldComponentUpdate")
|
18
|
-
}); // Copy static getDerivedStateFromProps() to the instrumented constructor.
|
19
|
-
// This is necessary to support the react-lifecycle-compat poyfill.
|
20
|
-
// This can be removed once react-relay requires React 16.3+.
|
21
|
-
|
22
|
-
|
23
|
-
if (Container.prototype !== null && typeof Container.prototype === 'object' && typeof Container.getDerivedStateFromProps === 'function') {
|
24
|
-
Container.prototype.constructor.getDerivedStateFromProps = Container.getDerivedStateFromProps;
|
25
|
-
}
|
26
|
-
}
|
27
|
-
|
28
|
-
module.exports = {
|
29
|
-
profileContainer: profileContainer
|
30
|
-
};
|
@@ -1,201 +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
|
-
var _inheritsLoose2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/inheritsLoose"));
|
13
|
-
|
14
|
-
var _defineProperty2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/defineProperty"));
|
15
|
-
|
16
|
-
var _taggedTemplateLiteral2 = require("@babel/runtime/helpers/interopRequireDefault")(require("./taggedTemplateLiteral"));
|
17
|
-
|
18
|
-
function _templateObject2() {
|
19
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["\n fragment ReactRelayFragmentContainerFlowtest_Bar_viewer on Viewer {\n actor {\n id\n }\n }\n "]);
|
20
|
-
|
21
|
-
_templateObject2 = function _templateObject2() {
|
22
|
-
return data;
|
23
|
-
};
|
24
|
-
|
25
|
-
return data;
|
26
|
-
}
|
27
|
-
|
28
|
-
function _templateObject() {
|
29
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["\n fragment ReactRelayFragmentContainerFlowtest_Foo_viewer on Viewer {\n actor {\n id\n }\n }\n "]);
|
30
|
-
|
31
|
-
_templateObject = function _templateObject() {
|
32
|
-
return data;
|
33
|
-
};
|
34
|
-
|
35
|
-
return data;
|
36
|
-
}
|
37
|
-
|
38
|
-
/**
|
39
|
-
* Verifies that normal prop type checking, as well as the methods proxying Relay does, is
|
40
|
-
* type-checked correctly on Relay components.
|
41
|
-
*/
|
42
|
-
var FooComponent = function FooComponent(_ref) {
|
43
|
-
var requiredProp = _ref.requiredProp;
|
44
|
-
return require("react").createElement("div", null, requiredProp);
|
45
|
-
}; // Note that we must reassign to a new identifier to make sure flow doesn't propogate types without
|
46
|
-
// the relay type definition doing the work.
|
47
|
-
|
48
|
-
|
49
|
-
var Foo = require("./ReactRelayPublic").createFragmentContainer(FooComponent, require("./ReactRelayPublic").graphql(_templateObject()));
|
50
|
-
|
51
|
-
var BarComponent =
|
52
|
-
/*#__PURE__*/
|
53
|
-
function (_React$Component) {
|
54
|
-
(0, _inheritsLoose2["default"])(BarComponent, _React$Component);
|
55
|
-
|
56
|
-
function BarComponent() {
|
57
|
-
return _React$Component.apply(this, arguments) || this;
|
58
|
-
}
|
59
|
-
|
60
|
-
var _proto = BarComponent.prototype;
|
61
|
-
|
62
|
-
_proto.getNum = function getNum() {
|
63
|
-
return 42;
|
64
|
-
};
|
65
|
-
|
66
|
-
_proto.render = function render() {
|
67
|
-
var reqLen = this.props.requiredProp.length;
|
68
|
-
var optionalProp = this.props.optionalProp;
|
69
|
-
/** $FlowExpectedError: `optionalProp` might be null **/
|
70
|
-
|
71
|
-
var optionalFoo = this.props.optionalProp.foo;
|
72
|
-
/** $FlowExpectedError: there is no prop `missingProp` **/
|
73
|
-
|
74
|
-
var missing = this.props.missingProp;
|
75
|
-
var defLen = this.props.defaultProp.length; // always a valid string, so no error
|
76
|
-
|
77
|
-
return require("react").createElement("div", null, reqLen && optionalProp && optionalFoo && missing && defLen);
|
78
|
-
};
|
79
|
-
|
80
|
-
return BarComponent;
|
81
|
-
}(require("react").Component);
|
82
|
-
|
83
|
-
(0, _defineProperty2["default"])(BarComponent, "defaultProps", {
|
84
|
-
defaultProp: 'default'
|
85
|
-
});
|
86
|
-
|
87
|
-
var Bar = require("./ReactRelayPublic").createFragmentContainer(BarComponent, require("./ReactRelayPublic").graphql(_templateObject2()));
|
88
|
-
|
89
|
-
module.exports = {
|
90
|
-
checkMissingPropOnFunctionalComponent: function checkMissingPropOnFunctionalComponent() {
|
91
|
-
/** $FlowExpectedError: Foo missing `requiredProp` **/
|
92
|
-
return require("react").createElement(Foo, null);
|
93
|
-
},
|
94
|
-
checkMinimalPropsOnFunctionalComponent: function checkMinimalPropsOnFunctionalComponent() {
|
95
|
-
// Fine, no expected errors
|
96
|
-
return require("react").createElement(Foo, {
|
97
|
-
requiredProp: "foo"
|
98
|
-
});
|
99
|
-
},
|
100
|
-
checkMissingPropOnClassComponent: function checkMissingPropOnClassComponent() {
|
101
|
-
/** $FlowExpectedError: Bar missing `requiredProp` **/
|
102
|
-
return require("react").createElement(Bar, null);
|
103
|
-
},
|
104
|
-
checkMinimalPropsOnClassComponent: function checkMinimalPropsOnClassComponent() {
|
105
|
-
// All is well
|
106
|
-
return require("react").createElement(Bar, {
|
107
|
-
requiredProp: "foo"
|
108
|
-
});
|
109
|
-
},
|
110
|
-
checkWrongPropType: function checkWrongPropType() {
|
111
|
-
/** $FlowExpectedError: Bar wrong `requiredProp` type, should be string **/
|
112
|
-
return require("react").createElement(Bar, {
|
113
|
-
requiredProp: 17
|
114
|
-
});
|
115
|
-
},
|
116
|
-
checkWrongOptionalType: function checkWrongOptionalType() {
|
117
|
-
/** $FlowExpectedError: Bar wrong `optionalProp` type, should be `{foo: string}` **/
|
118
|
-
return require("react").createElement(Bar, {
|
119
|
-
optionalProp: "wrongType",
|
120
|
-
requiredProp: "foo"
|
121
|
-
});
|
122
|
-
},
|
123
|
-
checkNullOptionalType: function checkNullOptionalType() {
|
124
|
-
/** $FlowExpectedError: Bar `optionalProp` must be omitted or truthy, not null **/
|
125
|
-
return require("react").createElement(Bar, {
|
126
|
-
optionalProp: null,
|
127
|
-
requiredProp: "foo"
|
128
|
-
});
|
129
|
-
},
|
130
|
-
checkWrongDefaultPropType: function checkWrongDefaultPropType() {
|
131
|
-
/** $FlowExpectedError: Bar wrong `defaultProp` type, should be string **/
|
132
|
-
return require("react").createElement(Bar, {
|
133
|
-
defaultProp: false,
|
134
|
-
requiredProp: "foo"
|
135
|
-
});
|
136
|
-
},
|
137
|
-
checkAllPossibleProps: function checkAllPossibleProps() {
|
138
|
-
// All is well
|
139
|
-
return require("react").createElement(Bar, {
|
140
|
-
defaultProp: "bar",
|
141
|
-
optionalProp: {
|
142
|
-
foo: 42
|
143
|
-
},
|
144
|
-
requiredProp: "foo"
|
145
|
-
});
|
146
|
-
},
|
147
|
-
checkMinimalPropSpread: function checkMinimalPropSpread() {
|
148
|
-
// All is well
|
149
|
-
var props = {
|
150
|
-
requiredProp: 'foo'
|
151
|
-
};
|
152
|
-
return require("react").createElement(Bar, props);
|
153
|
-
},
|
154
|
-
checkMissingPropSpread: function checkMissingPropSpread() {
|
155
|
-
var props = {
|
156
|
-
defaultProp: 'foo'
|
157
|
-
};
|
158
|
-
/** $FlowExpectedError: Bar missing `requiredProp` with spread **/
|
159
|
-
|
160
|
-
return require("react").createElement(Bar, props);
|
161
|
-
},
|
162
|
-
checkStaticsAndMethodsProxying: function checkStaticsAndMethodsProxying() {
|
163
|
-
var ProxyChecker =
|
164
|
-
/*#__PURE__*/
|
165
|
-
function (_React$PureComponent) {
|
166
|
-
(0, _inheritsLoose2["default"])(ProxyChecker, _React$PureComponent);
|
167
|
-
|
168
|
-
function ProxyChecker() {
|
169
|
-
return _React$PureComponent.apply(this, arguments) || this;
|
170
|
-
}
|
171
|
-
|
172
|
-
var _proto2 = ProxyChecker.prototype;
|
173
|
-
|
174
|
-
_proto2.getString = function getString() {
|
175
|
-
var ok = this._barRef ? this._barRef.getNum() : 'default'; // legit
|
176
|
-
|
177
|
-
/** $FlowExpectedError: Bar does not have `missingMethod` **/
|
178
|
-
|
179
|
-
var bad = this._barRef ? this._barRef.missingMethod() : 'default';
|
180
|
-
/** $FlowExpectedError: Bar `getNum` gives number, but `getString` assumes string **/
|
181
|
-
|
182
|
-
return bad ? 'not good' : ok;
|
183
|
-
};
|
184
|
-
|
185
|
-
_proto2.render = function render() {
|
186
|
-
var _this = this;
|
187
|
-
|
188
|
-
return require("react").createElement(Bar, {
|
189
|
-
componentRef: function componentRef(ref) {
|
190
|
-
_this._barRef = ref;
|
191
|
-
},
|
192
|
-
requiredProp: "bar"
|
193
|
-
});
|
194
|
-
};
|
195
|
-
|
196
|
-
return ProxyChecker;
|
197
|
-
}(require("react").PureComponent);
|
198
|
-
|
199
|
-
return require("react").createElement(ProxyChecker, null);
|
200
|
-
}
|
201
|
-
};
|