react-relay 2.0.0-rc.2 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +2 -2
- package/lib/ReactRelayContext.js +6 -3
- package/lib/ReactRelayFragmentContainer.js +48 -46
- package/lib/ReactRelayFragmentMockRenderer.js +5 -1
- package/lib/ReactRelayPaginationContainer.js +102 -68
- package/lib/ReactRelayQueryFetcher.js +54 -28
- package/lib/ReactRelayQueryRenderer.js +28 -20
- package/lib/ReactRelayRefetchContainer.js +70 -58
- package/lib/ReactRelayTestMocker.js +56 -43
- package/lib/ReactRelayTypes.js +1 -1
- package/lib/RelayContext.js +8 -2
- package/lib/assertFragmentMap.js +9 -7
- package/lib/buildReactRelayContainer.js +32 -23
- package/lib/index.js +41 -0
- package/lib/isRelayEnvironment.js +1 -1
- package/lib/isRelayVariables.js +1 -1
- package/lib/readContext.js +7 -4
- package/package.json +4 -4
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/classic.js +0 -10
- package/compat.js +0 -10
- package/lib/ConcreteQuery.js +0 -10
- package/lib/GraphQLQueryRunner.js +0 -264
- package/lib/GraphQLRange.js +0 -1124
- package/lib/GraphQLSegment.js +0 -743
- package/lib/GraphQLStoreChangeEmitter.js +0 -141
- package/lib/GraphQLStoreQueryResolver.js +0 -288
- package/lib/GraphQLStoreRangeUtils.js +0 -126
- package/lib/QueryBuilder.js +0 -228
- package/lib/ReactRelayClassicExports.js +0 -29
- package/lib/ReactRelayCompatContainerBuilder.js +0 -175
- package/lib/ReactRelayCompatPublic.js +0 -28
- package/lib/ReactRelayContainerProfiler.js +0 -30
- package/lib/ReactRelayFragmentContainer-flowtest.js +0 -201
- package/lib/ReactRelayPaginationContainer-flowtest.js +0 -213
- package/lib/ReactRelayPublic.js +0 -29
- package/lib/ReactRelayRefetchContainer-flowtest.js +0 -191
- package/lib/RelayCacheProcessor.js +0 -196
- package/lib/RelayChangeTracker.js +0 -83
- package/lib/RelayClassicContainerUtils.js +0 -49
- package/lib/RelayClassicCore.js +0 -34
- package/lib/RelayClassicRecordState.js +0 -31
- package/lib/RelayCompatContainer.js +0 -25
- package/lib/RelayCompatEnvironment.js +0 -27
- package/lib/RelayCompatMutations.js +0 -133
- package/lib/RelayCompatPaginationContainer.js +0 -27
- package/lib/RelayCompatRefetchContainer.js +0 -27
- package/lib/RelayCompatTypes.js +0 -10
- package/lib/RelayContainer.js +0 -889
- package/lib/RelayContainerComparators.js +0 -75
- package/lib/RelayContainerProxy.js +0 -21
- package/lib/RelayDefaultNetworkLayer.js +0 -192
- package/lib/RelayEnvironment.js +0 -449
- package/lib/RelayEnvironmentTypes.js +0 -10
- package/lib/RelayFetchMode.js +0 -17
- package/lib/RelayFragmentPointer.js +0 -161
- package/lib/RelayFragmentReference.js +0 -249
- package/lib/RelayFragmentSpecResolver.js +0 -305
- package/lib/RelayGraphQLMutation.js +0 -288
- package/lib/RelayGraphQLTag.js +0 -42
- package/lib/RelayInternalTypes.js +0 -15
- package/lib/RelayInternals.js +0 -24
- package/lib/RelayMetaRoute.js +0 -35
- package/lib/RelayMockRenderer.js +0 -71
- package/lib/RelayModern-flowtest.js +0 -342
- package/lib/RelayModernFlowtest_badref.graphql.js +0 -10
- package/lib/RelayModernFlowtest_notref.graphql.js +0 -10
- package/lib/RelayModernFlowtest_user.graphql.js +0 -10
- package/lib/RelayModernFlowtest_users.graphql.js +0 -10
- package/lib/RelayMutation.js +0 -322
- package/lib/RelayMutationDebugPrinter.js +0 -47
- package/lib/RelayMutationQuery.js +0 -558
- package/lib/RelayMutationQueue.js +0 -530
- package/lib/RelayMutationRequest.js +0 -103
- package/lib/RelayMutationTracker.js +0 -113
- package/lib/RelayMutationTransaction.js +0 -92
- package/lib/RelayMutationTransactionStatus.js +0 -55
- package/lib/RelayNetworkDebug.js +0 -131
- package/lib/RelayNetworkLayer.js +0 -185
- package/lib/RelayNodeInterface.js +0 -104
- package/lib/RelayOperationDescriptor.js +0 -40
- package/lib/RelayOptimisticMutationUtils.js +0 -208
- package/lib/RelayPendingQueryTracker.js +0 -166
- package/lib/RelayPropTypes.js +0 -57
- package/lib/RelayPublic.js +0 -44
- package/lib/RelayQL.js +0 -128
- package/lib/RelayQuery.js +0 -1584
- package/lib/RelayQueryCaching.js +0 -33
- package/lib/RelayQueryConfig.js +0 -58
- package/lib/RelayQueryPath.js +0 -204
- package/lib/RelayQueryRequest.js +0 -103
- package/lib/RelayQueryTracker.js +0 -86
- package/lib/RelayQueryTransform.js +0 -91
- package/lib/RelayQueryVisitor.js +0 -93
- package/lib/RelayQueryWriter.js +0 -573
- package/lib/RelayReadyState.js +0 -83
- package/lib/RelayReadyStateRenderer.js +0 -145
- package/lib/RelayRecord.js +0 -75
- package/lib/RelayRecordStatusMap.js +0 -57
- package/lib/RelayRecordStore.js +0 -433
- package/lib/RelayRecordWriter.js +0 -601
- package/lib/RelayRefQueryDescriptor.js +0 -27
- package/lib/RelayRenderer.js +0 -268
- package/lib/RelayRootContainer.js +0 -125
- package/lib/RelayRoute.js +0 -92
- package/lib/RelayRouteFragment.js +0 -44
- package/lib/RelaySelector.js +0 -201
- package/lib/RelayShallowMock.js +0 -69
- package/lib/RelayStaticContainer.js +0 -38
- package/lib/RelayStore.js +0 -12
- package/lib/RelayStoreConstants.js +0 -20
- package/lib/RelayStoreData.js +0 -660
- package/lib/RelayTaskQueue.js +0 -189
- package/lib/RelayTypes.js +0 -13
- package/lib/RelayVariable.js +0 -32
- package/lib/RelayVariables.js +0 -92
- package/lib/buildRQL.js +0 -160
- package/lib/callsFromGraphQL.js +0 -74
- package/lib/callsToGraphQL.js +0 -34
- package/lib/checkRelayQueryData.js +0 -250
- package/lib/createRelayQuery.js +0 -17
- package/lib/dedent.js +0 -49
- package/lib/diffRelayQuery.js +0 -757
- package/lib/directivesToGraphQL.js +0 -39
- package/lib/filterRelayQuery.js +0 -29
- package/lib/findRelayQueryLeaves.js +0 -293
- package/lib/flattenRelayQuery.js +0 -121
- package/lib/flattenSplitRelayQueries.js +0 -44
- package/lib/forEachRootCallArg.js +0 -40
- package/lib/fromGraphQL.js +0 -48
- package/lib/generateClientEdgeID.js +0 -22
- package/lib/generateClientID.js +0 -27
- package/lib/generateConcreteFragmentID.js +0 -30
- package/lib/generateForceIndex.js +0 -24
- package/lib/generateRQLFieldAlias.js +0 -39
- package/lib/getRangeBehavior.js +0 -58
- package/lib/getRelayQueries.js +0 -83
- package/lib/intersectRelayQuery.js +0 -149
- package/lib/isClassicRelayContext.js +0 -20
- package/lib/isClassicRelayEnvironment.js +0 -20
- package/lib/isCompatibleRelayFragmentType.js +0 -27
- package/lib/isRelayContainer.js +0 -16
- package/lib/makeLegacyStringishComponentRef.js +0 -52
- package/lib/printRelayOSSQuery.js +0 -329
- package/lib/printRelayQuery.js +0 -26
- package/lib/rangeOperationToMetadataKey.js +0 -25
- package/lib/readRelayQueryData.js +0 -551
- package/lib/relayUnstableBatchedUpdates.js +0 -12
- package/lib/relayUnstableBatchedUpdates.native.js +0 -11
- package/lib/restoreRelayCacheData.js +0 -188
- package/lib/serializeRelayQueryCall.js +0 -42
- package/lib/splitDeferredRelayQueries.js +0 -298
- package/lib/stableStringify.js +0 -85
- package/lib/testEditDistance.js +0 -112
- package/lib/throwFailedPromise.js +0 -26
- package/lib/toGraphQL.js +0 -94
- package/lib/transformRelayQueryPayload.js +0 -145
- package/lib/validateMutationConfig.js +0 -117
- package/lib/validateRelayReadQuery.js +0 -112
- package/lib/writeRelayQueryPayload.js +0 -44
- package/lib/writeRelayUpdatePayload.js +0 -513
- package/react-relay-classic.js +0 -4
- package/react-relay-classic.min.js +0 -9
- package/react-relay-compat.js +0 -4
- package/react-relay-compat.min.js +0 -9
@@ -1,75 +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
|
-
* Compares `objectA` and `objectB` using the provided `isEqual` function.
|
14
|
-
*
|
15
|
-
* If a `filter` object is provided, only its keys will be checked during
|
16
|
-
* comparison.
|
17
|
-
*/
|
18
|
-
function compareObjects(isEqual, objectA, objectB, filter) {
|
19
|
-
var key; // Test for A's keys different from B.
|
20
|
-
|
21
|
-
for (key in objectA) {
|
22
|
-
if (filter && !filter.hasOwnProperty(key)) {
|
23
|
-
continue;
|
24
|
-
}
|
25
|
-
|
26
|
-
if (objectA.hasOwnProperty(key) && (!objectB.hasOwnProperty(key) || !isEqual(objectA[key], objectB[key], key))) {
|
27
|
-
return false;
|
28
|
-
}
|
29
|
-
} // Test for B's keys missing from A.
|
30
|
-
|
31
|
-
|
32
|
-
for (key in objectB) {
|
33
|
-
if (filter && !filter.hasOwnProperty(key)) {
|
34
|
-
continue;
|
35
|
-
}
|
36
|
-
|
37
|
-
if (objectB.hasOwnProperty(key) && !objectA.hasOwnProperty(key)) {
|
38
|
-
return false;
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
return true;
|
43
|
-
}
|
44
|
-
|
45
|
-
function isQueryDataEqual(fragmentPointers, currProp, nextProp, propName) {
|
46
|
-
return (// resolved data did not change
|
47
|
-
fragmentPointers[propName] && currProp === nextProp || // otherwise compare fake data
|
48
|
-
require("relay-runtime").isScalarAndEqual(currProp, nextProp)
|
49
|
-
);
|
50
|
-
}
|
51
|
-
|
52
|
-
function isNonQueryPropEqual(fragments, currProp, nextProp, propName) {
|
53
|
-
return (// ignore props with fragments (instead resolved values are compared)
|
54
|
-
fragments.hasOwnProperty(propName) || // otherwise props must be scalar and === in order to skip
|
55
|
-
require("relay-runtime").isScalarAndEqual(currProp, nextProp)
|
56
|
-
);
|
57
|
-
}
|
58
|
-
/**
|
59
|
-
* Relay-aware comparators for props and state provide a reasonable default
|
60
|
-
* implementation of `shouldComponentUpdate`.
|
61
|
-
*/
|
62
|
-
|
63
|
-
|
64
|
-
var RelayContainerComparators = {
|
65
|
-
areQueryResultsEqual: function areQueryResultsEqual(fragmentPointers, prevQueryData, nextQueryData) {
|
66
|
-
return compareObjects(isQueryDataEqual.bind(null, fragmentPointers), prevQueryData, nextQueryData);
|
67
|
-
},
|
68
|
-
areNonQueryPropsEqual: function areNonQueryPropsEqual(fragments, props, nextProps) {
|
69
|
-
return compareObjects(isNonQueryPropEqual.bind(null, fragments), props, nextProps);
|
70
|
-
},
|
71
|
-
areQueryVariablesEqual: function areQueryVariablesEqual(variables, nextVariables) {
|
72
|
-
return compareObjects(require("relay-runtime").isScalarAndEqual, variables, nextVariables);
|
73
|
-
}
|
74
|
-
};
|
75
|
-
module.exports = RelayContainerComparators;
|
@@ -1,21 +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
|
-
* This feature is deprecated and unavailable in open source.
|
13
|
-
*/
|
14
|
-
|
15
|
-
var RelayContainerProxy = {
|
16
|
-
proxyMethods: function proxyMethods(Container, Component) {},
|
17
|
-
injectProxyMethods: function injectProxyMethods(proxyMethods) {
|
18
|
-
this.proxyMethods = proxyMethods;
|
19
|
-
}
|
20
|
-
};
|
21
|
-
module.exports = RelayContainerProxy;
|
@@ -1,192 +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
|
-
var RelayDefaultNetworkLayer =
|
15
|
-
/*#__PURE__*/
|
16
|
-
function () {
|
17
|
-
// InitWithRetries
|
18
|
-
function RelayDefaultNetworkLayer(uri, init) {
|
19
|
-
this._uri = uri;
|
20
|
-
this._init = (0, _objectSpread2["default"])({}, init); // Facilitate reuse when creating custom network layers.
|
21
|
-
|
22
|
-
this.sendMutation = this.sendMutation.bind(this);
|
23
|
-
this.sendQueries = this.sendQueries.bind(this);
|
24
|
-
this.supports = this.supports.bind(this);
|
25
|
-
}
|
26
|
-
|
27
|
-
var _proto = RelayDefaultNetworkLayer.prototype;
|
28
|
-
|
29
|
-
_proto.sendMutation = function sendMutation(request) {
|
30
|
-
return this._sendMutation(request).then(function (result) {
|
31
|
-
return result.json();
|
32
|
-
}).then(function (payload) {
|
33
|
-
if (payload.hasOwnProperty('errors')) {
|
34
|
-
var error = createRequestError(request, '200', payload);
|
35
|
-
request.reject(error);
|
36
|
-
} else {
|
37
|
-
request.resolve({
|
38
|
-
response: payload.data
|
39
|
-
});
|
40
|
-
}
|
41
|
-
})["catch"](function (error) {
|
42
|
-
return request.reject(error);
|
43
|
-
});
|
44
|
-
};
|
45
|
-
|
46
|
-
_proto.sendQueries = function sendQueries(requests) {
|
47
|
-
var _this = this;
|
48
|
-
|
49
|
-
return Promise.all(requests.map(function (request) {
|
50
|
-
return _this._sendQuery(request).then(function (result) {
|
51
|
-
return result.json();
|
52
|
-
}).then(function (payload) {
|
53
|
-
if (payload.hasOwnProperty('errors')) {
|
54
|
-
var error = createRequestError(request, '200', payload);
|
55
|
-
request.reject(error);
|
56
|
-
} else if (!payload.hasOwnProperty('data')) {
|
57
|
-
request.reject(new Error('Server response was missing for query ' + "`".concat(request.getDebugName(), "`.")));
|
58
|
-
} else {
|
59
|
-
request.resolve({
|
60
|
-
response: payload.data
|
61
|
-
});
|
62
|
-
}
|
63
|
-
})["catch"](function (error) {
|
64
|
-
return request.reject(error);
|
65
|
-
});
|
66
|
-
}));
|
67
|
-
};
|
68
|
-
|
69
|
-
_proto.supports = function supports() {
|
70
|
-
// Does not support the only defined option, "defer".
|
71
|
-
return false;
|
72
|
-
};
|
73
|
-
/**
|
74
|
-
* Sends a POST request with optional files.
|
75
|
-
*/
|
76
|
-
|
77
|
-
|
78
|
-
_proto._sendMutation = function _sendMutation(request) {
|
79
|
-
var init;
|
80
|
-
var files = request.getFiles();
|
81
|
-
|
82
|
-
if (files) {
|
83
|
-
if (!global.FormData) {
|
84
|
-
throw new Error('Uploading files without `FormData` not supported.');
|
85
|
-
}
|
86
|
-
|
87
|
-
var formData = new FormData();
|
88
|
-
formData.append('query', request.getQueryString());
|
89
|
-
formData.append('variables', JSON.stringify(request.getVariables()));
|
90
|
-
|
91
|
-
for (var filename in files) {
|
92
|
-
if (files.hasOwnProperty(filename)) {
|
93
|
-
formData.append(filename, files[filename]);
|
94
|
-
}
|
95
|
-
}
|
96
|
-
|
97
|
-
init = (0, _objectSpread2["default"])({}, this._init, {
|
98
|
-
body: formData,
|
99
|
-
method: 'POST'
|
100
|
-
});
|
101
|
-
} else {
|
102
|
-
init = (0, _objectSpread2["default"])({}, this._init, {
|
103
|
-
body: JSON.stringify({
|
104
|
-
query: request.getQueryString(),
|
105
|
-
variables: request.getVariables()
|
106
|
-
}),
|
107
|
-
headers: (0, _objectSpread2["default"])({}, this._init.headers, {
|
108
|
-
Accept: '*/*',
|
109
|
-
'Content-Type': 'application/json'
|
110
|
-
}),
|
111
|
-
method: 'POST'
|
112
|
-
});
|
113
|
-
}
|
114
|
-
|
115
|
-
return require("fbjs/lib/fetch")(this._uri, init).then(function (response) {
|
116
|
-
return throwOnServerError(request, response);
|
117
|
-
});
|
118
|
-
};
|
119
|
-
/**
|
120
|
-
* Sends a POST request and retries if the request fails or times out.
|
121
|
-
*/
|
122
|
-
|
123
|
-
|
124
|
-
_proto._sendQuery = function _sendQuery(request) {
|
125
|
-
return require("fbjs/lib/fetchWithRetries")(this._uri, (0, _objectSpread2["default"])({}, this._init, {
|
126
|
-
body: JSON.stringify({
|
127
|
-
query: request.getQueryString(),
|
128
|
-
variables: request.getVariables()
|
129
|
-
}),
|
130
|
-
headers: (0, _objectSpread2["default"])({}, this._init.headers, {
|
131
|
-
Accept: '*/*',
|
132
|
-
'Content-Type': 'application/json'
|
133
|
-
}),
|
134
|
-
method: 'POST'
|
135
|
-
}));
|
136
|
-
};
|
137
|
-
|
138
|
-
return RelayDefaultNetworkLayer;
|
139
|
-
}();
|
140
|
-
/**
|
141
|
-
* Rejects HTTP responses with a status code that is not >= 200 and < 300.
|
142
|
-
* This is done to follow the internal behavior of `fetchWithRetries`.
|
143
|
-
*/
|
144
|
-
|
145
|
-
|
146
|
-
function throwOnServerError(request, response) {
|
147
|
-
if (response.status >= 200 && response.status < 300) {
|
148
|
-
return response;
|
149
|
-
} else {
|
150
|
-
return response.text().then(function (payload) {
|
151
|
-
throw createRequestError(request, response.status, payload);
|
152
|
-
});
|
153
|
-
}
|
154
|
-
}
|
155
|
-
/**
|
156
|
-
* Formats an error response from GraphQL server request.
|
157
|
-
*/
|
158
|
-
|
159
|
-
|
160
|
-
function formatRequestErrors(request, errors) {
|
161
|
-
var CONTEXT_BEFORE = 20;
|
162
|
-
var CONTEXT_LENGTH = 60;
|
163
|
-
var queryLines = request.getQueryString().split('\n');
|
164
|
-
return errors.map(function (_ref, ii) {
|
165
|
-
var locations = _ref.locations,
|
166
|
-
message = _ref.message;
|
167
|
-
var prefix = ii + 1 + '. ';
|
168
|
-
var indent = ' '.repeat(prefix.length); //custom errors thrown in graphql-server may not have locations
|
169
|
-
|
170
|
-
var locationMessage = locations ? '\n' + locations.map(function (_ref2) {
|
171
|
-
var column = _ref2.column,
|
172
|
-
line = _ref2.line;
|
173
|
-
var queryLine = queryLines[line - 1];
|
174
|
-
var offset = Math.min(column - 1, CONTEXT_BEFORE);
|
175
|
-
return [queryLine.substr(column - 1 - offset, CONTEXT_LENGTH), ' '.repeat(Math.max(0, offset)) + '^^^'].map(function (messageLine) {
|
176
|
-
return indent + messageLine;
|
177
|
-
}).join('\n');
|
178
|
-
}).join('\n') : '';
|
179
|
-
return prefix + message + locationMessage;
|
180
|
-
}).join('\n');
|
181
|
-
}
|
182
|
-
|
183
|
-
function createRequestError(request, responseStatus, payload) {
|
184
|
-
var requestType = request instanceof require("./RelayMutationRequest") ? 'mutation' : 'query';
|
185
|
-
var errorReason = typeof payload === 'object' ? formatRequestErrors(request, payload.errors) : "Server response had an error status: ".concat(responseStatus);
|
186
|
-
var error = new Error("Server request for ".concat(requestType, " `").concat(request.getDebugName(), "` ") + "failed for the following reasons:\n\n".concat(errorReason));
|
187
|
-
error.source = payload;
|
188
|
-
error.status = responseStatus;
|
189
|
-
return error;
|
190
|
-
}
|
191
|
-
|
192
|
-
module.exports = RelayDefaultNetworkLayer;
|