@apollo/client 3.7.9 → 3.7.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apollo-client.cjs +196 -153
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/core/types/DataProxy.d.ts +3 -2
- package/cache/core/types/DataProxy.d.ts.map +1 -1
- package/cache/core/types/DataProxy.js.map +1 -1
- package/core/ApolloClient.d.ts +3 -3
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js +10 -4
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +2 -1
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +8 -5
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.d.ts +1 -0
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +52 -43
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +73 -56
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +73 -56
- package/errors/errors.cjs +17 -17
- package/errors/errors.cjs.map +1 -1
- package/errors/errors.cjs.native.js +17 -17
- package/errors/index.d.ts +24 -8
- package/errors/index.d.ts.map +1 -1
- package/errors/index.js +17 -19
- package/errors/index.js.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/link/core/types.d.ts +4 -0
- package/link/core/types.d.ts.map +1 -1
- package/link/core/types.js.map +1 -1
- package/link/http/createHttpLink.d.ts.map +1 -1
- package/link/http/createHttpLink.js +19 -3
- package/link/http/createHttpLink.js.map +1 -1
- package/link/http/http.cjs +52 -15
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +52 -15
- package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
- package/link/http/parseAndCheckHttpResponse.js +29 -14
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/subscriptions/index.d.ts.map +1 -1
- package/link/subscriptions/index.js +8 -3
- package/link/subscriptions/index.js.map +1 -1
- package/link/subscriptions/subscriptions.cjs +8 -3
- package/link/subscriptions/subscriptions.cjs.map +1 -1
- package/link/subscriptions/subscriptions.cjs.native.js +8 -3
- package/package.json +21 -22
- package/react/hooks/hooks.cjs +38 -45
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +38 -45
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +11 -20
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts.map +1 -1
- package/react/hooks/useMutation.js +2 -1
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +1 -3
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +27 -26
- package/react/hooks/useQuery.js.map +1 -1
- package/testing/core/itAsync.js.map +1 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
- package/testing/react/MockedProvider.js +5 -4
- package/testing/react/MockedProvider.js.map +1 -1
- package/testing/testing.cjs +4 -2
- package/testing/testing.cjs.map +1 -1
- package/testing/testing.cjs.native.js +4 -2
- package/utilities/common/incrementalResult.d.ts +2 -1
- package/utilities/common/incrementalResult.d.ts.map +1 -1
- package/utilities/common/incrementalResult.js +4 -0
- package/utilities/common/incrementalResult.js.map +1 -1
- package/utilities/graphql/getFromAST.d.ts.map +1 -1
- package/utilities/graphql/getFromAST.js +7 -3
- package/utilities/graphql/getFromAST.js.map +1 -1
- package/utilities/utilities.cjs +7 -3
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +7 -3
- package/version.js +1 -1
package/apollo-client.cjs
CHANGED
|
@@ -380,17 +380,21 @@ function checkDocument(doc) {
|
|
|
380
380
|
}
|
|
381
381
|
function getOperationDefinition(doc) {
|
|
382
382
|
checkDocument(doc);
|
|
383
|
-
return doc.definitions.filter(function (definition) {
|
|
383
|
+
return doc.definitions.filter(function (definition) {
|
|
384
|
+
return definition.kind === 'OperationDefinition';
|
|
385
|
+
})[0];
|
|
384
386
|
}
|
|
385
387
|
function getOperationName(doc) {
|
|
386
388
|
return (doc.definitions
|
|
387
389
|
.filter(function (definition) {
|
|
388
|
-
return definition.kind === 'OperationDefinition' && definition.name;
|
|
390
|
+
return definition.kind === 'OperationDefinition' && !!definition.name;
|
|
389
391
|
})
|
|
390
392
|
.map(function (x) { return x.name.value; })[0] || null);
|
|
391
393
|
}
|
|
392
394
|
function getFragmentDefinitions(doc) {
|
|
393
|
-
return doc.definitions.filter(function (definition) {
|
|
395
|
+
return doc.definitions.filter(function (definition) {
|
|
396
|
+
return definition.kind === 'FragmentDefinition';
|
|
397
|
+
});
|
|
394
398
|
}
|
|
395
399
|
function getQueryDefinition(doc) {
|
|
396
400
|
var queryDef = getOperationDefinition(doc);
|
|
@@ -1071,6 +1075,9 @@ function isExecutionPatchResult(value) {
|
|
|
1071
1075
|
return (isExecutionPatchIncrementalResult(value) ||
|
|
1072
1076
|
isExecutionPatchInitialResult(value));
|
|
1073
1077
|
}
|
|
1078
|
+
function isApolloPayloadResult(value) {
|
|
1079
|
+
return isNonNullObject(value) && "payload" in value;
|
|
1080
|
+
}
|
|
1074
1081
|
function mergeIncrementalData(prevResult, result) {
|
|
1075
1082
|
var mergedData = prevResult;
|
|
1076
1083
|
var merger = new DeepMerger();
|
|
@@ -1353,7 +1360,7 @@ var concat = ApolloLink.concat;
|
|
|
1353
1360
|
|
|
1354
1361
|
var execute = ApolloLink.execute;
|
|
1355
1362
|
|
|
1356
|
-
var version = '3.7.
|
|
1363
|
+
var version = '3.7.11';
|
|
1357
1364
|
|
|
1358
1365
|
function isNodeResponse(value) {
|
|
1359
1366
|
return !!value.body;
|
|
@@ -1518,20 +1525,56 @@ function responseIterator(response) {
|
|
|
1518
1525
|
throw new Error("Unknown body type for responseIterator. Please pass a streamable response.");
|
|
1519
1526
|
}
|
|
1520
1527
|
|
|
1528
|
+
var PROTOCOL_ERRORS_SYMBOL = Symbol();
|
|
1529
|
+
function graphQLResultHasProtocolErrors(result) {
|
|
1530
|
+
if (result.extensions) {
|
|
1531
|
+
return Array.isArray(result.extensions[PROTOCOL_ERRORS_SYMBOL]);
|
|
1532
|
+
}
|
|
1533
|
+
return false;
|
|
1534
|
+
}
|
|
1535
|
+
function isApolloError(err) {
|
|
1536
|
+
return err.hasOwnProperty('graphQLErrors');
|
|
1537
|
+
}
|
|
1538
|
+
var generateErrorMessage = function (err) {
|
|
1539
|
+
var errors = tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray([], err.graphQLErrors, true), err.clientErrors, true), err.protocolErrors, true);
|
|
1540
|
+
if (err.networkError)
|
|
1541
|
+
errors.push(err.networkError);
|
|
1542
|
+
return errors
|
|
1543
|
+
.map(function (err) { return isNonNullObject(err) && err.message || 'Error message not found.'; })
|
|
1544
|
+
.join('\n');
|
|
1545
|
+
};
|
|
1546
|
+
var ApolloError = (function (_super) {
|
|
1547
|
+
tslib.__extends(ApolloError, _super);
|
|
1548
|
+
function ApolloError(_a) {
|
|
1549
|
+
var graphQLErrors = _a.graphQLErrors, protocolErrors = _a.protocolErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;
|
|
1550
|
+
var _this = _super.call(this, errorMessage) || this;
|
|
1551
|
+
_this.name = 'ApolloError';
|
|
1552
|
+
_this.graphQLErrors = graphQLErrors || [];
|
|
1553
|
+
_this.protocolErrors = protocolErrors || [];
|
|
1554
|
+
_this.clientErrors = clientErrors || [];
|
|
1555
|
+
_this.networkError = networkError || null;
|
|
1556
|
+
_this.message = errorMessage || generateErrorMessage(_this);
|
|
1557
|
+
_this.extraInfo = extraInfo;
|
|
1558
|
+
_this.__proto__ = ApolloError.prototype;
|
|
1559
|
+
return _this;
|
|
1560
|
+
}
|
|
1561
|
+
return ApolloError;
|
|
1562
|
+
}(Error));
|
|
1563
|
+
|
|
1521
1564
|
var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
|
|
1522
1565
|
function readMultipartBody(response, observer) {
|
|
1523
|
-
var _a, _b, _c;
|
|
1566
|
+
var _a, _b, _c, _d;
|
|
1524
1567
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1525
|
-
var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running,
|
|
1526
|
-
var
|
|
1527
|
-
return tslib.__generator(this, function (
|
|
1528
|
-
switch (
|
|
1568
|
+
var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _e, value, done, chunk, bi, message, i, headers, contentType_1, body, result, next;
|
|
1569
|
+
var _f, _g;
|
|
1570
|
+
return tslib.__generator(this, function (_h) {
|
|
1571
|
+
switch (_h.label) {
|
|
1529
1572
|
case 0:
|
|
1530
1573
|
if (TextDecoder === undefined) {
|
|
1531
1574
|
throw new Error("TextDecoder must be defined in the environment: please import a polyfill.");
|
|
1532
1575
|
}
|
|
1533
1576
|
decoder = new TextDecoder("utf-8");
|
|
1534
|
-
contentType = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get(
|
|
1577
|
+
contentType = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type");
|
|
1535
1578
|
delimiter = "boundary=";
|
|
1536
1579
|
boundaryVal = (contentType === null || contentType === void 0 ? void 0 : contentType.includes(delimiter))
|
|
1537
1580
|
? contentType === null || contentType === void 0 ? void 0 : contentType.substring((contentType === null || contentType === void 0 ? void 0 : contentType.indexOf(delimiter)) + delimiter.length).replace(/['"]/g, "").replace(/\;(.*)/gm, "").trim()
|
|
@@ -1540,22 +1583,22 @@ function readMultipartBody(response, observer) {
|
|
|
1540
1583
|
buffer = "";
|
|
1541
1584
|
iterator = responseIterator(response);
|
|
1542
1585
|
running = true;
|
|
1543
|
-
|
|
1586
|
+
_h.label = 1;
|
|
1544
1587
|
case 1:
|
|
1545
1588
|
if (!running) return [3, 3];
|
|
1546
1589
|
return [4, iterator.next()];
|
|
1547
1590
|
case 2:
|
|
1548
|
-
|
|
1591
|
+
_e = _h.sent(), value = _e.value, done = _e.done;
|
|
1549
1592
|
chunk = typeof value === "string" ? value : decoder.decode(value);
|
|
1550
1593
|
running = !done;
|
|
1551
1594
|
buffer += chunk;
|
|
1552
1595
|
bi = buffer.indexOf(boundary);
|
|
1553
1596
|
while (bi > -1) {
|
|
1554
1597
|
message = void 0;
|
|
1555
|
-
|
|
1598
|
+
_f = [
|
|
1556
1599
|
buffer.slice(0, bi),
|
|
1557
1600
|
buffer.slice(bi + boundary.length),
|
|
1558
|
-
], message =
|
|
1601
|
+
], message = _f[0], buffer = _f[1];
|
|
1559
1602
|
if (message.trim()) {
|
|
1560
1603
|
i = message.indexOf("\r\n\r\n");
|
|
1561
1604
|
headers = parseHeaders(message.slice(0, i));
|
|
@@ -1570,8 +1613,21 @@ function readMultipartBody(response, observer) {
|
|
|
1570
1613
|
if (Object.keys(result).length > 1 ||
|
|
1571
1614
|
"data" in result ||
|
|
1572
1615
|
"incremental" in result ||
|
|
1573
|
-
"errors" in result
|
|
1574
|
-
|
|
1616
|
+
"errors" in result ||
|
|
1617
|
+
"payload" in result) {
|
|
1618
|
+
if (isApolloPayloadResult(result)) {
|
|
1619
|
+
next = {};
|
|
1620
|
+
if ("payload" in result) {
|
|
1621
|
+
next = tslib.__assign({}, result.payload);
|
|
1622
|
+
}
|
|
1623
|
+
if ("errors" in result) {
|
|
1624
|
+
next = tslib.__assign(tslib.__assign({}, next), { extensions: tslib.__assign(tslib.__assign({}, ("extensions" in next ? next.extensions : null)), (_g = {}, _g[PROTOCOL_ERRORS_SYMBOL] = result.errors, _g)) });
|
|
1625
|
+
}
|
|
1626
|
+
(_b = observer.next) === null || _b === void 0 ? void 0 : _b.call(observer, next);
|
|
1627
|
+
}
|
|
1628
|
+
else {
|
|
1629
|
+
(_c = observer.next) === null || _c === void 0 ? void 0 : _c.call(observer, result);
|
|
1630
|
+
}
|
|
1575
1631
|
}
|
|
1576
1632
|
}
|
|
1577
1633
|
catch (err) {
|
|
@@ -1582,7 +1638,7 @@ function readMultipartBody(response, observer) {
|
|
|
1582
1638
|
}
|
|
1583
1639
|
return [3, 1];
|
|
1584
1640
|
case 3:
|
|
1585
|
-
(
|
|
1641
|
+
(_d = observer.complete) === null || _d === void 0 ? void 0 : _d.call(observer);
|
|
1586
1642
|
return [2];
|
|
1587
1643
|
}
|
|
1588
1644
|
});
|
|
@@ -1880,13 +1936,28 @@ var createHttpLink = function (linkOptions) {
|
|
|
1880
1936
|
var definitionIsMutation = function (d) {
|
|
1881
1937
|
return d.kind === 'OperationDefinition' && d.operation === 'mutation';
|
|
1882
1938
|
};
|
|
1939
|
+
var definitionIsSubscription = function (d) {
|
|
1940
|
+
return d.kind === 'OperationDefinition' && d.operation === 'subscription';
|
|
1941
|
+
};
|
|
1942
|
+
var isSubscription = definitionIsSubscription(getMainDefinition(operation.query));
|
|
1943
|
+
var hasDefer = hasDirectives(['defer'], operation.query);
|
|
1883
1944
|
if (useGETForQueries &&
|
|
1884
1945
|
!operation.query.definitions.some(definitionIsMutation)) {
|
|
1885
1946
|
options.method = 'GET';
|
|
1886
1947
|
}
|
|
1887
|
-
if (
|
|
1948
|
+
if (hasDefer || isSubscription) {
|
|
1888
1949
|
options.headers = options.headers || {};
|
|
1889
|
-
|
|
1950
|
+
var acceptHeader = "multipart/mixed;";
|
|
1951
|
+
if (isSubscription && hasDefer) {
|
|
1952
|
+
__DEV__ && tsInvariant.invariant.warn("Multipart-subscriptions do not support @defer");
|
|
1953
|
+
}
|
|
1954
|
+
if (isSubscription) {
|
|
1955
|
+
acceptHeader += 'boundary=graphql;subscriptionSpec=1.0,application/json';
|
|
1956
|
+
}
|
|
1957
|
+
else if (hasDefer) {
|
|
1958
|
+
acceptHeader += 'deferSpec=20220824,application/json';
|
|
1959
|
+
}
|
|
1960
|
+
options.headers.accept = acceptHeader;
|
|
1890
1961
|
}
|
|
1891
1962
|
if (options.method === 'GET') {
|
|
1892
1963
|
var _d = rewriteURIForGET(chosenURI, body), newURI = _d.newURI, parseError = _d.parseError;
|
|
@@ -4226,44 +4297,6 @@ var InMemoryCache = (function (_super) {
|
|
|
4226
4297
|
return InMemoryCache;
|
|
4227
4298
|
}(ApolloCache));
|
|
4228
4299
|
|
|
4229
|
-
function isApolloError(err) {
|
|
4230
|
-
return err.hasOwnProperty('graphQLErrors');
|
|
4231
|
-
}
|
|
4232
|
-
var generateErrorMessage = function (err) {
|
|
4233
|
-
var message = '';
|
|
4234
|
-
if (isNonEmptyArray(err.graphQLErrors) || isNonEmptyArray(err.clientErrors)) {
|
|
4235
|
-
var errors = (err.graphQLErrors || [])
|
|
4236
|
-
.concat(err.clientErrors || []);
|
|
4237
|
-
errors.forEach(function (error) {
|
|
4238
|
-
var errorMessage = error
|
|
4239
|
-
? error.message
|
|
4240
|
-
: 'Error message not found.';
|
|
4241
|
-
message += "".concat(errorMessage, "\n");
|
|
4242
|
-
});
|
|
4243
|
-
}
|
|
4244
|
-
if (err.networkError) {
|
|
4245
|
-
message += "".concat(err.networkError.message, "\n");
|
|
4246
|
-
}
|
|
4247
|
-
message = message.replace(/\n$/, '');
|
|
4248
|
-
return message;
|
|
4249
|
-
};
|
|
4250
|
-
var ApolloError = (function (_super) {
|
|
4251
|
-
tslib.__extends(ApolloError, _super);
|
|
4252
|
-
function ApolloError(_a) {
|
|
4253
|
-
var graphQLErrors = _a.graphQLErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;
|
|
4254
|
-
var _this = _super.call(this, errorMessage) || this;
|
|
4255
|
-
_this.name = 'ApolloError';
|
|
4256
|
-
_this.graphQLErrors = graphQLErrors || [];
|
|
4257
|
-
_this.clientErrors = clientErrors || [];
|
|
4258
|
-
_this.networkError = networkError || null;
|
|
4259
|
-
_this.message = errorMessage || generateErrorMessage(_this);
|
|
4260
|
-
_this.extraInfo = extraInfo;
|
|
4261
|
-
_this.__proto__ = ApolloError.prototype;
|
|
4262
|
-
return _this;
|
|
4263
|
-
}
|
|
4264
|
-
return ApolloError;
|
|
4265
|
-
}(Error));
|
|
4266
|
-
|
|
4267
4300
|
exports.NetworkStatus = void 0;
|
|
4268
4301
|
(function (NetworkStatus) {
|
|
4269
4302
|
NetworkStatus[NetworkStatus["loading"] = 1] = "loading";
|
|
@@ -4610,7 +4643,7 @@ var ObservableQuery = (function (_super) {
|
|
|
4610
4643
|
};
|
|
4611
4644
|
ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
|
|
4612
4645
|
this.queryManager.setObservableQuery(this);
|
|
4613
|
-
return this.queryManager
|
|
4646
|
+
return this.queryManager['fetchConcastWithInfo'](this.queryId, options, newNetworkStatus);
|
|
4614
4647
|
};
|
|
4615
4648
|
ObservableQuery.prototype.updatePolling = function () {
|
|
4616
4649
|
var _this = this;
|
|
@@ -4663,7 +4696,7 @@ var ObservableQuery = (function (_super) {
|
|
|
4663
4696
|
}
|
|
4664
4697
|
return this.last;
|
|
4665
4698
|
};
|
|
4666
|
-
ObservableQuery.prototype.
|
|
4699
|
+
ObservableQuery.prototype.reobserveAsConcast = function (newOptions, newNetworkStatus) {
|
|
4667
4700
|
var _this = this;
|
|
4668
4701
|
this.isTornDown = false;
|
|
4669
4702
|
var useDisposableConcast = newNetworkStatus === exports.NetworkStatus.refetch ||
|
|
@@ -4689,7 +4722,7 @@ var ObservableQuery = (function (_super) {
|
|
|
4689
4722
|
}
|
|
4690
4723
|
}
|
|
4691
4724
|
var variables = options.variables && tslib.__assign({}, options.variables);
|
|
4692
|
-
var
|
|
4725
|
+
var _a = this.fetch(options, newNetworkStatus), concast = _a.concast, fromLink = _a.fromLink;
|
|
4693
4726
|
var observer = {
|
|
4694
4727
|
next: function (result) {
|
|
4695
4728
|
_this.reportResult(result, variables);
|
|
@@ -4698,7 +4731,7 @@ var ObservableQuery = (function (_super) {
|
|
|
4698
4731
|
_this.reportError(error, variables);
|
|
4699
4732
|
},
|
|
4700
4733
|
};
|
|
4701
|
-
if (!useDisposableConcast) {
|
|
4734
|
+
if (!useDisposableConcast && fromLink) {
|
|
4702
4735
|
if (this.concast && this.observer) {
|
|
4703
4736
|
this.concast.removeObserver(this.observer);
|
|
4704
4737
|
}
|
|
@@ -4706,7 +4739,10 @@ var ObservableQuery = (function (_super) {
|
|
|
4706
4739
|
this.observer = observer;
|
|
4707
4740
|
}
|
|
4708
4741
|
concast.addObserver(observer);
|
|
4709
|
-
return concast
|
|
4742
|
+
return concast;
|
|
4743
|
+
};
|
|
4744
|
+
ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
|
|
4745
|
+
return this.reobserveAsConcast(newOptions, newNetworkStatus).promise;
|
|
4710
4746
|
};
|
|
4711
4747
|
ObservableQuery.prototype.observe = function () {
|
|
4712
4748
|
this.reportResult(this.getCurrentResult(false), this.variables);
|
|
@@ -5877,10 +5913,17 @@ var QueryManager = (function () {
|
|
|
5877
5913
|
}
|
|
5878
5914
|
_this.broadcastQueries();
|
|
5879
5915
|
}
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
}
|
|
5916
|
+
var hasErrors = graphQLResultHasError(result);
|
|
5917
|
+
var hasProtocolErrors = graphQLResultHasProtocolErrors(result);
|
|
5918
|
+
if (hasErrors || hasProtocolErrors) {
|
|
5919
|
+
var errors = {};
|
|
5920
|
+
if (hasErrors) {
|
|
5921
|
+
errors.graphQLErrors = result.errors;
|
|
5922
|
+
}
|
|
5923
|
+
if (hasProtocolErrors) {
|
|
5924
|
+
errors.protocolErrors = result.extensions[PROTOCOL_ERRORS_SYMBOL];
|
|
5925
|
+
}
|
|
5926
|
+
throw new ApolloError(errors);
|
|
5884
5927
|
}
|
|
5885
5928
|
return result;
|
|
5886
5929
|
});
|
|
@@ -6012,6 +6055,9 @@ var QueryManager = (function () {
|
|
|
6012
6055
|
});
|
|
6013
6056
|
};
|
|
6014
6057
|
QueryManager.prototype.fetchQueryObservable = function (queryId, options, networkStatus) {
|
|
6058
|
+
return this.fetchConcastWithInfo(queryId, options, networkStatus).concast;
|
|
6059
|
+
};
|
|
6060
|
+
QueryManager.prototype.fetchConcastWithInfo = function (queryId, options, networkStatus) {
|
|
6015
6061
|
var _this = this;
|
|
6016
6062
|
if (networkStatus === void 0) { networkStatus = exports.NetworkStatus.loading; }
|
|
6017
6063
|
var query = this.transform(options.query).document;
|
|
@@ -6030,24 +6076,36 @@ var QueryManager = (function () {
|
|
|
6030
6076
|
});
|
|
6031
6077
|
var fromVariables = function (variables) {
|
|
6032
6078
|
normalized.variables = variables;
|
|
6033
|
-
var
|
|
6079
|
+
var sourcesWithInfo = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
|
|
6034
6080
|
if (normalized.fetchPolicy !== "standby" &&
|
|
6035
|
-
|
|
6081
|
+
sourcesWithInfo.sources.length > 0 &&
|
|
6036
6082
|
queryInfo.observableQuery) {
|
|
6037
6083
|
queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
|
|
6038
6084
|
}
|
|
6039
|
-
return
|
|
6085
|
+
return sourcesWithInfo;
|
|
6040
6086
|
};
|
|
6041
6087
|
var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
|
|
6042
6088
|
this.fetchCancelFns.set(queryId, function (reason) {
|
|
6043
6089
|
cleanupCancelFn();
|
|
6044
6090
|
setTimeout(function () { return concast.cancel(reason); });
|
|
6045
6091
|
});
|
|
6046
|
-
var concast
|
|
6047
|
-
|
|
6048
|
-
|
|
6092
|
+
var concast, containsDataFromLink;
|
|
6093
|
+
if (this.transform(normalized.query).hasClientExports) {
|
|
6094
|
+
concast = new Concast(this.localState
|
|
6095
|
+
.addExportedVariables(normalized.query, normalized.variables, normalized.context)
|
|
6096
|
+
.then(fromVariables).then(function (sourcesWithInfo) { return sourcesWithInfo.sources; }));
|
|
6097
|
+
containsDataFromLink = true;
|
|
6098
|
+
}
|
|
6099
|
+
else {
|
|
6100
|
+
var sourcesWithInfo = fromVariables(normalized.variables);
|
|
6101
|
+
containsDataFromLink = sourcesWithInfo.fromLink;
|
|
6102
|
+
concast = new Concast(sourcesWithInfo.sources);
|
|
6103
|
+
}
|
|
6049
6104
|
concast.promise.then(cleanupCancelFn, cleanupCancelFn);
|
|
6050
|
-
return
|
|
6105
|
+
return {
|
|
6106
|
+
concast: concast,
|
|
6107
|
+
fromLink: containsDataFromLink,
|
|
6108
|
+
};
|
|
6051
6109
|
};
|
|
6052
6110
|
QueryManager.prototype.refetchQueries = function (_a) {
|
|
6053
6111
|
var _this = this;
|
|
@@ -6171,54 +6229,40 @@ var QueryManager = (function () {
|
|
|
6171
6229
|
case "cache-first": {
|
|
6172
6230
|
var diff = readCache();
|
|
6173
6231
|
if (diff.complete) {
|
|
6174
|
-
return [
|
|
6175
|
-
resultsFromCache(diff, queryInfo.markReady()),
|
|
6176
|
-
];
|
|
6232
|
+
return { fromLink: false, sources: [resultsFromCache(diff, queryInfo.markReady())] };
|
|
6177
6233
|
}
|
|
6178
6234
|
if (returnPartialData || shouldNotify) {
|
|
6179
|
-
return [
|
|
6180
|
-
resultsFromCache(diff),
|
|
6181
|
-
resultsFromLink(),
|
|
6182
|
-
];
|
|
6235
|
+
return { fromLink: true, sources: [resultsFromCache(diff), resultsFromLink()] };
|
|
6183
6236
|
}
|
|
6184
|
-
return [
|
|
6185
|
-
resultsFromLink(),
|
|
6186
|
-
];
|
|
6237
|
+
return { fromLink: true, sources: [resultsFromLink()] };
|
|
6187
6238
|
}
|
|
6188
6239
|
case "cache-and-network": {
|
|
6189
6240
|
var diff = readCache();
|
|
6190
6241
|
if (diff.complete || returnPartialData || shouldNotify) {
|
|
6191
|
-
return [
|
|
6192
|
-
resultsFromCache(diff),
|
|
6193
|
-
resultsFromLink(),
|
|
6194
|
-
];
|
|
6242
|
+
return { fromLink: true, sources: [resultsFromCache(diff), resultsFromLink()] };
|
|
6195
6243
|
}
|
|
6196
|
-
return [
|
|
6197
|
-
resultsFromLink(),
|
|
6198
|
-
];
|
|
6244
|
+
return { fromLink: true, sources: [resultsFromLink()] };
|
|
6199
6245
|
}
|
|
6200
6246
|
case "cache-only":
|
|
6201
|
-
return [
|
|
6202
|
-
resultsFromCache(readCache(), queryInfo.markReady()),
|
|
6203
|
-
];
|
|
6247
|
+
return { fromLink: false, sources: [resultsFromCache(readCache(), queryInfo.markReady())] };
|
|
6204
6248
|
case "network-only":
|
|
6205
6249
|
if (shouldNotify) {
|
|
6206
|
-
return [
|
|
6207
|
-
resultsFromCache(readCache()),
|
|
6208
|
-
resultsFromLink(),
|
|
6209
|
-
];
|
|
6250
|
+
return { fromLink: true, sources: [resultsFromCache(readCache()), resultsFromLink()] };
|
|
6210
6251
|
}
|
|
6211
|
-
return [resultsFromLink()];
|
|
6252
|
+
return { fromLink: true, sources: [resultsFromLink()] };
|
|
6212
6253
|
case "no-cache":
|
|
6213
6254
|
if (shouldNotify) {
|
|
6214
|
-
return
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6255
|
+
return {
|
|
6256
|
+
fromLink: true,
|
|
6257
|
+
sources: [
|
|
6258
|
+
resultsFromCache(queryInfo.getDiff()),
|
|
6259
|
+
resultsFromLink(),
|
|
6260
|
+
],
|
|
6261
|
+
};
|
|
6218
6262
|
}
|
|
6219
|
-
return [resultsFromLink()];
|
|
6263
|
+
return { fromLink: true, sources: [resultsFromLink()] };
|
|
6220
6264
|
case "standby":
|
|
6221
|
-
return [];
|
|
6265
|
+
return { fromLink: false, sources: [] };
|
|
6222
6266
|
}
|
|
6223
6267
|
};
|
|
6224
6268
|
QueryManager.prototype.getQuery = function (queryId) {
|
|
@@ -6374,12 +6418,18 @@ var ApolloClient = (function () {
|
|
|
6374
6418
|
return this.cache.readFragment(options, optimistic);
|
|
6375
6419
|
};
|
|
6376
6420
|
ApolloClient.prototype.writeQuery = function (options) {
|
|
6377
|
-
this.cache.writeQuery(options);
|
|
6378
|
-
|
|
6421
|
+
var ref = this.cache.writeQuery(options);
|
|
6422
|
+
if (options.broadcast !== false) {
|
|
6423
|
+
this.queryManager.broadcastQueries();
|
|
6424
|
+
}
|
|
6425
|
+
return ref;
|
|
6379
6426
|
};
|
|
6380
6427
|
ApolloClient.prototype.writeFragment = function (options) {
|
|
6381
|
-
this.cache.writeFragment(options);
|
|
6382
|
-
|
|
6428
|
+
var ref = this.cache.writeFragment(options);
|
|
6429
|
+
if (options.broadcast !== false) {
|
|
6430
|
+
this.queryManager.broadcastQueries();
|
|
6431
|
+
}
|
|
6432
|
+
return ref;
|
|
6383
6433
|
};
|
|
6384
6434
|
ApolloClient.prototype.__actionHookForDevTools = function (cb) {
|
|
6385
6435
|
this.devToolsHookCb = cb;
|
|
@@ -6675,8 +6725,6 @@ var InternalState = (function () {
|
|
|
6675
6725
|
function InternalState(client, query, previous) {
|
|
6676
6726
|
this.client = client;
|
|
6677
6727
|
this.query = query;
|
|
6678
|
-
this.asyncResolveFns = new Set();
|
|
6679
|
-
this.optionsToIgnoreOnce = new (canUseWeakSet ? WeakSet : Set)();
|
|
6680
6728
|
this.ssrDisabledResult = maybeDeepFreeze({
|
|
6681
6729
|
loading: true,
|
|
6682
6730
|
data: void 0,
|
|
@@ -6700,20 +6748,30 @@ var InternalState = (function () {
|
|
|
6700
6748
|
InternalState.prototype.forceUpdate = function () {
|
|
6701
6749
|
__DEV__ && tsInvariant.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
|
|
6702
6750
|
};
|
|
6703
|
-
InternalState.prototype.
|
|
6751
|
+
InternalState.prototype.executeQuery = function (options) {
|
|
6704
6752
|
var _this = this;
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
6753
|
+
var _a;
|
|
6754
|
+
if (options.query) {
|
|
6755
|
+
Object.assign(this, { query: options.query });
|
|
6756
|
+
}
|
|
6757
|
+
this.watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
|
|
6758
|
+
var concast = this.observable.reobserveAsConcast(this.getObsQueryOptions());
|
|
6759
|
+
this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
|
|
6760
|
+
this.result = void 0;
|
|
6761
|
+
this.forceUpdate();
|
|
6762
|
+
return new Promise(function (resolve) {
|
|
6763
|
+
var result;
|
|
6764
|
+
concast.subscribe({
|
|
6765
|
+
next: function (value) {
|
|
6766
|
+
result = value;
|
|
6767
|
+
},
|
|
6768
|
+
error: function () {
|
|
6769
|
+
resolve(_this.toQueryResult(_this.observable.getCurrentResult()));
|
|
6770
|
+
},
|
|
6771
|
+
complete: function () {
|
|
6772
|
+
resolve(_this.toQueryResult(result));
|
|
6773
|
+
}
|
|
6774
|
+
});
|
|
6717
6775
|
});
|
|
6718
6776
|
};
|
|
6719
6777
|
InternalState.prototype.useQuery = function (options) {
|
|
@@ -6762,29 +6820,22 @@ var InternalState = (function () {
|
|
|
6762
6820
|
}
|
|
6763
6821
|
};
|
|
6764
6822
|
var subscription = obsQuery.subscribe(onNext, onError);
|
|
6765
|
-
return function () { return subscription.unsubscribe(); };
|
|
6823
|
+
return function () { return setTimeout(function () { return subscription.unsubscribe(); }); };
|
|
6766
6824
|
}, [
|
|
6767
6825
|
obsQuery,
|
|
6768
6826
|
this.renderPromises,
|
|
6769
6827
|
this.client.disableNetworkFetches,
|
|
6770
6828
|
]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
|
|
6771
6829
|
this.unsafeHandlePartialRefetch(result);
|
|
6772
|
-
|
|
6773
|
-
if (!queryResult.loading && this.asyncResolveFns.size) {
|
|
6774
|
-
this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
|
|
6775
|
-
this.asyncResolveFns.clear();
|
|
6776
|
-
}
|
|
6777
|
-
return queryResult;
|
|
6830
|
+
return this.toQueryResult(result);
|
|
6778
6831
|
};
|
|
6779
6832
|
InternalState.prototype.useOptions = function (options) {
|
|
6780
6833
|
var _a;
|
|
6781
6834
|
var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
|
|
6782
6835
|
var currentWatchQueryOptions = this.watchQueryOptions;
|
|
6783
|
-
if (
|
|
6784
|
-
!equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
|
|
6836
|
+
if (!equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
|
|
6785
6837
|
this.watchQueryOptions = watchQueryOptions;
|
|
6786
6838
|
if (currentWatchQueryOptions && this.observable) {
|
|
6787
|
-
this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
|
|
6788
6839
|
this.observable.reobserve(this.getObsQueryOptions());
|
|
6789
6840
|
this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
|
|
6790
6841
|
this.result = void 0;
|
|
@@ -6950,10 +7001,14 @@ var EAGER_METHODS = [
|
|
|
6950
7001
|
];
|
|
6951
7002
|
function useLazyQuery(query, options) {
|
|
6952
7003
|
var _a;
|
|
6953
|
-
var abortControllersRef = React.useRef(new Set());
|
|
6954
7004
|
var execOptionsRef = React.useRef();
|
|
7005
|
+
var optionsRef = React.useRef();
|
|
7006
|
+
var queryRef = React.useRef();
|
|
6955
7007
|
var merged = execOptionsRef.current ? mergeOptions(options, execOptionsRef.current) : options;
|
|
6956
|
-
var
|
|
7008
|
+
var document = (_a = merged === null || merged === void 0 ? void 0 : merged.query) !== null && _a !== void 0 ? _a : query;
|
|
7009
|
+
optionsRef.current = merged;
|
|
7010
|
+
queryRef.current = document;
|
|
7011
|
+
var internalState = useInternalState(useApolloClient(options && options.client), document);
|
|
6957
7012
|
var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
|
|
6958
7013
|
var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
|
|
6959
7014
|
internalState.getDefaultFetchPolicy();
|
|
@@ -6979,28 +7034,15 @@ function useLazyQuery(query, options) {
|
|
|
6979
7034
|
return eagerMethods;
|
|
6980
7035
|
}, []);
|
|
6981
7036
|
Object.assign(result, eagerMethods);
|
|
6982
|
-
React.useEffect(function () {
|
|
6983
|
-
return function () {
|
|
6984
|
-
abortControllersRef.current.forEach(function (controller) {
|
|
6985
|
-
controller.abort();
|
|
6986
|
-
});
|
|
6987
|
-
};
|
|
6988
|
-
}, []);
|
|
6989
7037
|
var execute = React.useCallback(function (executeOptions) {
|
|
6990
|
-
var controller = new AbortController();
|
|
6991
|
-
abortControllersRef.current.add(controller);
|
|
6992
7038
|
execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
|
|
6993
7039
|
fetchPolicy: initialFetchPolicy,
|
|
6994
7040
|
};
|
|
7041
|
+
var options = mergeOptions(optionsRef.current, tslib.__assign({ query: queryRef.current }, execOptionsRef.current));
|
|
6995
7042
|
var promise = internalState
|
|
6996
|
-
.
|
|
6997
|
-
.then(function (queryResult) {
|
|
6998
|
-
|
|
6999
|
-
return Object.assign(queryResult, eagerMethods);
|
|
7000
|
-
});
|
|
7001
|
-
promise.catch(function () {
|
|
7002
|
-
abortControllersRef.current.delete(controller);
|
|
7003
|
-
});
|
|
7043
|
+
.executeQuery(tslib.__assign(tslib.__assign({}, options), { skip: false }))
|
|
7044
|
+
.then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
|
|
7045
|
+
promise.catch(function () { });
|
|
7004
7046
|
return promise;
|
|
7005
7047
|
}, []);
|
|
7006
7048
|
return [execute, result];
|
|
@@ -7027,8 +7069,9 @@ function useMutation(mutation, options) {
|
|
|
7027
7069
|
}
|
|
7028
7070
|
var execute = React.useCallback(function (executeOptions) {
|
|
7029
7071
|
if (executeOptions === void 0) { executeOptions = {}; }
|
|
7030
|
-
var _a = ref.current,
|
|
7072
|
+
var _a = ref.current, options = _a.options, mutation = _a.mutation;
|
|
7031
7073
|
var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
|
|
7074
|
+
var client = executeOptions.client || ref.current.client;
|
|
7032
7075
|
if (!ref.current.result.loading && !baseOptions.ignoreResults && ref.current.isMounted) {
|
|
7033
7076
|
setResult(ref.current.result = {
|
|
7034
7077
|
loading: true,
|