@apollo/client 3.8.0-alpha.11 → 3.8.0-alpha.13
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 +594 -397
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/core/ApolloClient.d.ts.map +1 -1
- 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 +30 -19
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.d.ts +2 -0
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +60 -48
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +175 -82
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +175 -82
- package/core/equalByQuery.d.ts +4 -0
- package/core/equalByQuery.d.ts.map +1 -0
- package/{react/hooks/compareResults.js → core/equalByQuery.js} +14 -10
- package/core/equalByQuery.js.map +1 -0
- package/core/index.d.ts +1 -1
- package/core/index.d.ts.map +1 -1
- package/core/index.js +1 -1
- package/core/index.js.map +1 -1
- 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 +29 -34
- package/link/batch-http/batch-http.cjs +23 -2
- package/link/batch-http/batch-http.cjs.map +1 -1
- package/link/batch-http/batch-http.cjs.native.js +23 -2
- package/link/batch-http/batchHttpLink.d.ts.map +1 -1
- package/link/batch-http/batchHttpLink.js +7 -2
- package/link/batch-http/batchHttpLink.js.map +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 +21 -20
- package/link/http/createHttpLink.js.map +1 -1
- package/link/http/http.cjs +59 -30
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +59 -30
- package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
- package/link/http/parseAndCheckHttpResponse.js +34 -14
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js +2 -1
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/persisted-queries/index.d.ts.map +1 -1
- package/link/persisted-queries/index.js +12 -13
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs +12 -13
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +12 -13
- package/link/subscriptions/index.d.ts.map +1 -1
- package/link/subscriptions/index.js +10 -5
- package/link/subscriptions/index.js.map +1 -1
- package/link/subscriptions/subscriptions.cjs +9 -4
- package/link/subscriptions/subscriptions.cjs.map +1 -1
- package/link/subscriptions/subscriptions.cjs.native.js +9 -4
- package/link/utils/filterOperationVariables.d.ts +5 -0
- package/link/utils/filterOperationVariables.d.ts.map +1 -0
- package/link/utils/filterOperationVariables.js +18 -0
- package/link/utils/filterOperationVariables.js.map +1 -0
- package/link/utils/index.d.ts +1 -0
- package/link/utils/index.d.ts.map +1 -1
- package/link/utils/index.js +1 -0
- package/link/utils/index.js.map +1 -1
- package/link/utils/throwServerError.d.ts +1 -1
- package/link/utils/throwServerError.d.ts.map +1 -1
- package/link/utils/throwServerError.js.map +1 -1
- package/link/utils/utils.cjs +18 -0
- package/link/utils/utils.cjs.map +1 -1
- package/link/utils/utils.cjs.native.js +18 -0
- package/package.json +24 -23
- package/react/cache/QuerySubscription.d.ts +11 -4
- package/react/cache/QuerySubscription.d.ts.map +1 -1
- package/react/cache/QuerySubscription.js +53 -35
- package/react/cache/QuerySubscription.js.map +1 -1
- package/react/cache/SuspenseCache.d.ts +3 -2
- package/react/cache/SuspenseCache.d.ts.map +1 -1
- package/react/cache/SuspenseCache.js +6 -7
- package/react/cache/SuspenseCache.js.map +1 -1
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/context/context.cjs +2 -2
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +2 -2
- package/react/hoc/hoc-utils.js +1 -1
- package/react/hoc/hoc.cjs +2 -2
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +2 -2
- package/react/hoc/withApollo.js +1 -1
- package/react/hooks/hooks.cjs +118 -146
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +118 -146
- package/react/hooks/internal/__use.d.ts +3 -1
- package/react/hooks/internal/__use.d.ts.map +1 -1
- package/react/hooks/internal/__use.js +16 -12
- package/react/hooks/internal/__use.js.map +1 -1
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useFragment.d.ts +2 -1
- package/react/hooks/useFragment.d.ts.map +1 -1
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +13 -22
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useQuery.d.ts +3 -3
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +26 -25
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts.map +1 -1
- package/react/hooks/useSubscription.js +25 -13
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseCache.js +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +15 -3
- package/react/hooks/useSuspenseQuery.d.ts.map +1 -1
- package/react/hooks/useSuspenseQuery.js +39 -53
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/index.d.ts +1 -1
- package/react/index.d.ts.map +1 -1
- package/react/index.js +1 -1
- package/react/index.js.map +1 -1
- package/react/parser/index.js +5 -5
- package/react/parser/parser.cjs +5 -5
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +5 -5
- package/react/react.cjs +58 -54
- package/react/react.cjs.map +1 -1
- package/react/react.cjs.native.js +58 -54
- package/react/types/types.d.ts +2 -3
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/core.cjs +1 -1
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +1 -1
- package/testing/core/mocking/mockLink.js +1 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
- package/testing/react/MockedProvider.d.ts +1 -1
- package/testing/react/MockedProvider.d.ts.map +1 -1
- package/testing/react/MockedProvider.js +7 -6
- package/testing/react/MockedProvider.js.map +1 -1
- package/testing/testing.cjs +8 -124
- package/testing/testing.cjs.map +1 -1
- package/testing/testing.cjs.native.js +8 -124
- 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/common/mergeOptions.d.ts +1 -1
- package/utilities/common/mergeOptions.d.ts.map +1 -1
- package/utilities/common/mergeOptions.js.map +1 -1
- package/utilities/common/objects.d.ts +1 -0
- package/utilities/common/objects.d.ts.map +1 -1
- package/utilities/common/objects.js +6 -0
- package/utilities/common/objects.js.map +1 -1
- package/utilities/common/omitDeep.d.ts +3 -0
- package/utilities/common/omitDeep.d.ts.map +1 -0
- package/utilities/common/omitDeep.js +42 -0
- package/utilities/common/omitDeep.js.map +1 -0
- package/utilities/common/stripTypename.d.ts +2 -0
- package/utilities/common/stripTypename.d.ts.map +1 -0
- package/utilities/common/stripTypename.js +5 -0
- package/utilities/common/stripTypename.js.map +1 -0
- package/utilities/graphql/directives.js +4 -4
- package/utilities/graphql/fragments.js +3 -3
- package/utilities/graphql/getFromAST.js +8 -8
- package/utilities/graphql/storeUtils.d.ts.map +1 -1
- package/utilities/graphql/storeUtils.js +2 -1
- package/utilities/graphql/storeUtils.js.map +1 -1
- package/utilities/graphql/transform.d.ts.map +1 -1
- package/utilities/graphql/transform.js +26 -16
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +5 -0
- package/utilities/index.d.ts.map +1 -1
- package/utilities/index.js +3 -0
- package/utilities/index.js.map +1 -1
- package/utilities/promises/decoration.d.ts +2 -0
- package/utilities/promises/decoration.d.ts.map +1 -1
- package/utilities/promises/decoration.js +12 -0
- package/utilities/promises/decoration.js.map +1 -1
- package/utilities/types/DeepOmit.d.ts +10 -0
- package/utilities/types/DeepOmit.d.ts.map +1 -0
- package/utilities/types/DeepOmit.js +2 -0
- package/utilities/types/DeepOmit.js.map +1 -0
- package/utilities/types/DeepPartial.d.ts +12 -0
- package/utilities/types/DeepPartial.d.ts.map +1 -0
- package/utilities/types/DeepPartial.js +2 -0
- package/utilities/types/DeepPartial.js.map +1 -0
- package/utilities/types/Primitive.d.ts +2 -0
- package/utilities/types/Primitive.d.ts.map +1 -0
- package/utilities/types/Primitive.js +2 -0
- package/utilities/types/Primitive.js.map +1 -0
- package/utilities/utilities.cjs +141 -31
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +141 -31
- package/version.js +1 -1
- package/react/hooks/compareResults.d.ts +0 -3
- package/react/hooks/compareResults.d.ts.map +0 -1
- package/react/hooks/compareResults.js.map +0 -1
package/core/core.cjs
CHANGED
|
@@ -6,7 +6,7 @@ var globals = require('../utilities/globals');
|
|
|
6
6
|
var tslib = require('tslib');
|
|
7
7
|
var core = require('../link/core');
|
|
8
8
|
var http = require('../link/http');
|
|
9
|
-
var
|
|
9
|
+
var equal = require('@wry/equality');
|
|
10
10
|
var utilities = require('../utilities');
|
|
11
11
|
var cache = require('../cache');
|
|
12
12
|
var errors = require('../errors');
|
|
@@ -15,16 +15,20 @@ var utils = require('../link/utils');
|
|
|
15
15
|
var tsInvariant = require('ts-invariant');
|
|
16
16
|
var graphqlTag = require('graphql-tag');
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
|
|
21
|
+
|
|
22
|
+
var version = '3.8.0-alpha.13';
|
|
23
23
|
|
|
24
24
|
function isNonNullObject(obj) {
|
|
25
25
|
return obj !== null && typeof obj === 'object';
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
function isNonEmptyArray(value) {
|
|
29
|
+
return Array.isArray(value) && value.length > 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
28
32
|
var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
|
29
33
|
var defaultReconciler = function (target, source, property) {
|
|
30
34
|
return this.merge(target[property], source[property]);
|
|
@@ -116,6 +120,73 @@ exports.NetworkStatus = void 0;
|
|
|
116
120
|
function isNetworkRequestInFlight(networkStatus) {
|
|
117
121
|
return networkStatus ? networkStatus < 7 : false;
|
|
118
122
|
}
|
|
123
|
+
function isNetworkRequestSettled(networkStatus) {
|
|
124
|
+
return networkStatus === 7 || networkStatus === 8;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function equalByQuery(query, _a, _b, variables) {
|
|
128
|
+
var aData = _a.data, aRest = tslib.__rest(_a, ["data"]);
|
|
129
|
+
var bData = _b.data, bRest = tslib.__rest(_b, ["data"]);
|
|
130
|
+
return equal__default(aRest, bRest) && equalBySelectionSet(utilities.getMainDefinition(query).selectionSet, aData, bData, {
|
|
131
|
+
fragmentMap: utilities.createFragmentMap(utilities.getFragmentDefinitions(query)),
|
|
132
|
+
variables: variables,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function equalBySelectionSet(selectionSet, aResult, bResult, context) {
|
|
136
|
+
if (aResult === bResult) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
var seenSelections = new Set();
|
|
140
|
+
return selectionSet.selections.every(function (selection) {
|
|
141
|
+
if (seenSelections.has(selection))
|
|
142
|
+
return true;
|
|
143
|
+
seenSelections.add(selection);
|
|
144
|
+
if (!utilities.shouldInclude(selection, context.variables))
|
|
145
|
+
return true;
|
|
146
|
+
if (selectionHasNonreactiveDirective(selection))
|
|
147
|
+
return true;
|
|
148
|
+
if (utilities.isField(selection)) {
|
|
149
|
+
var resultKey = utilities.resultKeyNameFromField(selection);
|
|
150
|
+
var aResultChild = aResult && aResult[resultKey];
|
|
151
|
+
var bResultChild = bResult && bResult[resultKey];
|
|
152
|
+
var childSelectionSet = selection.selectionSet;
|
|
153
|
+
if (!childSelectionSet) {
|
|
154
|
+
return equal__default(aResultChild, bResultChild);
|
|
155
|
+
}
|
|
156
|
+
var aChildIsArray = Array.isArray(aResultChild);
|
|
157
|
+
var bChildIsArray = Array.isArray(bResultChild);
|
|
158
|
+
if (aChildIsArray !== bChildIsArray)
|
|
159
|
+
return false;
|
|
160
|
+
if (aChildIsArray && bChildIsArray) {
|
|
161
|
+
var length_1 = aResultChild.length;
|
|
162
|
+
if (bResultChild.length !== length_1) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
for (var i = 0; i < length_1; ++i) {
|
|
166
|
+
if (!equalBySelectionSet(childSelectionSet, aResultChild[i], bResultChild[i], context)) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
return equalBySelectionSet(childSelectionSet, aResultChild, bResultChild, context);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
var fragment = utilities.getFragmentFromSelection(selection, context.fragmentMap);
|
|
176
|
+
if (fragment) {
|
|
177
|
+
if (selectionHasNonreactiveDirective(fragment))
|
|
178
|
+
return true;
|
|
179
|
+
return equalBySelectionSet(fragment.selectionSet, aResult, bResult, context);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function selectionHasNonreactiveDirective(selection) {
|
|
185
|
+
return !!selection.directives && selection.directives.some(directiveIsNonreactive);
|
|
186
|
+
}
|
|
187
|
+
function directiveIsNonreactive(dir) {
|
|
188
|
+
return dir.name.value === "nonreactive";
|
|
189
|
+
}
|
|
119
190
|
|
|
120
191
|
var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
|
|
121
192
|
var ObservableQuery = (function (_super) {
|
|
@@ -211,7 +282,7 @@ var ObservableQuery = (function (_super) {
|
|
|
211
282
|
if (diff.complete || this.options.returnPartialData) {
|
|
212
283
|
result.data = diff.result;
|
|
213
284
|
}
|
|
214
|
-
if (
|
|
285
|
+
if (equal.equal(result.data, {})) {
|
|
215
286
|
result.data = void 0;
|
|
216
287
|
}
|
|
217
288
|
if (diff.complete) {
|
|
@@ -242,15 +313,21 @@ var ObservableQuery = (function (_super) {
|
|
|
242
313
|
return result;
|
|
243
314
|
};
|
|
244
315
|
ObservableQuery.prototype.isDifferentFromLastResult = function (newResult, variables) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
316
|
+
if (!this.last) {
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
var query = this.options.query;
|
|
320
|
+
var resultIsDifferent = this.queryManager.transform(query).hasNonreactiveDirective
|
|
321
|
+
? !equalByQuery(query, this.last.result, newResult, this.variables)
|
|
322
|
+
: !equal.equal(this.last.result, newResult);
|
|
323
|
+
return (resultIsDifferent ||
|
|
324
|
+
(variables && !equal.equal(this.last.variables, variables)));
|
|
248
325
|
};
|
|
249
326
|
ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
|
|
250
327
|
var last = this.last;
|
|
251
328
|
if (last &&
|
|
252
329
|
last[key] &&
|
|
253
|
-
(!variablesMustMatch ||
|
|
330
|
+
(!variablesMustMatch || equal.equal(last.variables, this.variables))) {
|
|
254
331
|
return last[key];
|
|
255
332
|
}
|
|
256
333
|
};
|
|
@@ -289,7 +366,7 @@ var ObservableQuery = (function (_super) {
|
|
|
289
366
|
globals.__DEV__ && globals.invariant.warn("Called refetch(".concat(JSON.stringify(variables), ") for query ").concat(((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || JSON.stringify(queryDef), ", which does not declare a $variables variable.\nDid you mean to call refetch(variables) instead of refetch({ variables })?"));
|
|
290
367
|
}
|
|
291
368
|
}
|
|
292
|
-
if (variables && !
|
|
369
|
+
if (variables && !equal.equal(this.options.variables, variables)) {
|
|
293
370
|
reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
|
|
294
371
|
}
|
|
295
372
|
this.queryInfo.resetLastWrite();
|
|
@@ -384,7 +461,7 @@ var ObservableQuery = (function (_super) {
|
|
|
384
461
|
return this.reobserve(newOptions);
|
|
385
462
|
};
|
|
386
463
|
ObservableQuery.prototype.setVariables = function (variables) {
|
|
387
|
-
if (
|
|
464
|
+
if (equal.equal(this.variables, variables)) {
|
|
388
465
|
return this.observers.size
|
|
389
466
|
? this.result()
|
|
390
467
|
: Promise.resolve();
|
|
@@ -449,7 +526,7 @@ var ObservableQuery = (function (_super) {
|
|
|
449
526
|
};
|
|
450
527
|
ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
|
|
451
528
|
this.queryManager.setObservableQuery(this);
|
|
452
|
-
return this.queryManager
|
|
529
|
+
return this.queryManager['fetchConcastWithInfo'](this.queryId, options, newNetworkStatus);
|
|
453
530
|
};
|
|
454
531
|
ObservableQuery.prototype.updatePolling = function () {
|
|
455
532
|
var _this = this;
|
|
@@ -494,15 +571,15 @@ var ObservableQuery = (function (_super) {
|
|
|
494
571
|
};
|
|
495
572
|
ObservableQuery.prototype.updateLastResult = function (newResult, variables) {
|
|
496
573
|
if (variables === void 0) { variables = this.variables; }
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
if (!utilities.isNonEmptyArray(newResult.errors)) {
|
|
501
|
-
delete this.last.error;
|
|
574
|
+
var error = this.getLastError();
|
|
575
|
+
if (error && this.last && !equal.equal(variables, this.last.variables)) {
|
|
576
|
+
error = void 0;
|
|
502
577
|
}
|
|
503
|
-
return this.last
|
|
578
|
+
return this.last = tslib.__assign({ result: this.queryManager.assumeImmutableResults
|
|
579
|
+
? newResult
|
|
580
|
+
: utilities.cloneDeep(newResult), variables: variables }, (error ? { error: error } : null));
|
|
504
581
|
};
|
|
505
|
-
ObservableQuery.prototype.
|
|
582
|
+
ObservableQuery.prototype.reobserveAsConcast = function (newOptions, newNetworkStatus) {
|
|
506
583
|
var _this = this;
|
|
507
584
|
this.isTornDown = false;
|
|
508
585
|
var useDisposableConcast = newNetworkStatus === exports.NetworkStatus.refetch ||
|
|
@@ -518,7 +595,7 @@ var ObservableQuery = (function (_super) {
|
|
|
518
595
|
this.updatePolling();
|
|
519
596
|
if (newOptions &&
|
|
520
597
|
newOptions.variables &&
|
|
521
|
-
!
|
|
598
|
+
!equal.equal(newOptions.variables, oldVariables) &&
|
|
522
599
|
options.fetchPolicy !== "standby" &&
|
|
523
600
|
options.fetchPolicy === oldFetchPolicy) {
|
|
524
601
|
this.applyNextFetchPolicy("variables-changed", options);
|
|
@@ -528,7 +605,7 @@ var ObservableQuery = (function (_super) {
|
|
|
528
605
|
}
|
|
529
606
|
}
|
|
530
607
|
var variables = options.variables && tslib.__assign({}, options.variables);
|
|
531
|
-
var
|
|
608
|
+
var _a = this.fetch(options, newNetworkStatus), concast = _a.concast, fromLink = _a.fromLink;
|
|
532
609
|
var observer = {
|
|
533
610
|
next: function (result) {
|
|
534
611
|
_this.reportResult(result, variables);
|
|
@@ -537,7 +614,7 @@ var ObservableQuery = (function (_super) {
|
|
|
537
614
|
_this.reportError(error, variables);
|
|
538
615
|
},
|
|
539
616
|
};
|
|
540
|
-
if (!useDisposableConcast) {
|
|
617
|
+
if (!useDisposableConcast && (fromLink || !this.concast)) {
|
|
541
618
|
if (this.concast && this.observer) {
|
|
542
619
|
this.concast.removeObserver(this.observer);
|
|
543
620
|
}
|
|
@@ -545,18 +622,22 @@ var ObservableQuery = (function (_super) {
|
|
|
545
622
|
this.observer = observer;
|
|
546
623
|
}
|
|
547
624
|
concast.addObserver(observer);
|
|
548
|
-
return concast
|
|
625
|
+
return concast;
|
|
626
|
+
};
|
|
627
|
+
ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
|
|
628
|
+
return this.reobserveAsConcast(newOptions, newNetworkStatus).promise;
|
|
549
629
|
};
|
|
550
630
|
ObservableQuery.prototype.observe = function () {
|
|
551
631
|
this.reportResult(this.getCurrentResult(false), this.variables);
|
|
552
632
|
};
|
|
553
633
|
ObservableQuery.prototype.reportResult = function (result, variables) {
|
|
554
634
|
var lastError = this.getLastError();
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
635
|
+
var isDifferent = this.isDifferentFromLastResult(result, variables);
|
|
636
|
+
if (lastError || !result.partial || this.options.returnPartialData) {
|
|
637
|
+
this.updateLastResult(result, variables);
|
|
638
|
+
}
|
|
639
|
+
if (lastError || isDifferent) {
|
|
640
|
+
utilities.iterateObserversSafely(this.observers, "next", result);
|
|
560
641
|
}
|
|
561
642
|
};
|
|
562
643
|
ObservableQuery.prototype.reportError = function (error, variables) {
|
|
@@ -965,10 +1046,10 @@ var QueryInfo = (function () {
|
|
|
965
1046
|
var networkStatus = query.networkStatus || exports.NetworkStatus.loading;
|
|
966
1047
|
if (this.variables &&
|
|
967
1048
|
this.networkStatus !== exports.NetworkStatus.loading &&
|
|
968
|
-
!
|
|
1049
|
+
!equal.equal(this.variables, query.variables)) {
|
|
969
1050
|
networkStatus = exports.NetworkStatus.setVariables;
|
|
970
1051
|
}
|
|
971
|
-
if (!
|
|
1052
|
+
if (!equal.equal(query.variables, this.variables)) {
|
|
972
1053
|
this.lastDiff = void 0;
|
|
973
1054
|
}
|
|
974
1055
|
Object.assign(this, {
|
|
@@ -993,7 +1074,7 @@ var QueryInfo = (function () {
|
|
|
993
1074
|
QueryInfo.prototype.getDiff = function (variables) {
|
|
994
1075
|
if (variables === void 0) { variables = this.variables; }
|
|
995
1076
|
var options = this.getDiffOptions(variables);
|
|
996
|
-
if (this.lastDiff &&
|
|
1077
|
+
if (this.lastDiff && equal.equal(options, this.lastDiff.options)) {
|
|
997
1078
|
return this.lastDiff.diff;
|
|
998
1079
|
}
|
|
999
1080
|
this.updateWatch(this.variables = variables);
|
|
@@ -1027,7 +1108,7 @@ var QueryInfo = (function () {
|
|
|
1027
1108
|
var oldDiff = this.lastDiff && this.lastDiff.diff;
|
|
1028
1109
|
this.updateLastDiff(diff);
|
|
1029
1110
|
if (!this.dirty &&
|
|
1030
|
-
!
|
|
1111
|
+
!equal.equal(oldDiff && oldDiff.result, diff && diff.result)) {
|
|
1031
1112
|
this.dirty = true;
|
|
1032
1113
|
if (!this.notifyTimeout) {
|
|
1033
1114
|
this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
|
|
@@ -1102,7 +1183,7 @@ var QueryInfo = (function () {
|
|
|
1102
1183
|
}
|
|
1103
1184
|
var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
|
|
1104
1185
|
if (!this.lastWatch ||
|
|
1105
|
-
!
|
|
1186
|
+
!equal.equal(watchOptions, this.lastWatch)) {
|
|
1106
1187
|
this.cancel();
|
|
1107
1188
|
this.cancel = this.cache.watch(this.lastWatch = watchOptions);
|
|
1108
1189
|
}
|
|
@@ -1114,8 +1195,8 @@ var QueryInfo = (function () {
|
|
|
1114
1195
|
var lastWrite = this.lastWrite;
|
|
1115
1196
|
return !(lastWrite &&
|
|
1116
1197
|
lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
|
|
1117
|
-
|
|
1118
|
-
|
|
1198
|
+
equal.equal(variables, lastWrite.variables) &&
|
|
1199
|
+
equal.equal(result.data, lastWrite.result.data));
|
|
1119
1200
|
};
|
|
1120
1201
|
QueryInfo.prototype.markResult = function (result, document, options, cacheWriteBehavior) {
|
|
1121
1202
|
var _this = this;
|
|
@@ -1517,14 +1598,17 @@ var QueryManager = (function () {
|
|
|
1517
1598
|
var _a = (this.defaultOptions.transformQuery || Object.create(null)).removeClientFields, removeClientFields = _a === void 0 ? true : _a;
|
|
1518
1599
|
if (!transformCache.has(document)) {
|
|
1519
1600
|
var transformed = this.cache.transformDocument(document);
|
|
1520
|
-
var
|
|
1601
|
+
var serverQuery = utilities.removeDirectivesFromDocument([
|
|
1602
|
+
removeClientFields ? { name: 'client', remove: true } : {},
|
|
1603
|
+
{ name: 'connection' },
|
|
1604
|
+
{ name: 'nonreactive' },
|
|
1605
|
+
], transformed);
|
|
1521
1606
|
var clientQuery = this.localState.clientQuery(transformed);
|
|
1522
|
-
var serverQuery = noConnection &&
|
|
1523
|
-
this.localState.serverQuery(noConnection, { removeClientFields: removeClientFields });
|
|
1524
1607
|
var cacheEntry_1 = {
|
|
1525
1608
|
document: transformed,
|
|
1526
1609
|
hasClientExports: utilities.hasClientExports(transformed),
|
|
1527
1610
|
hasForcedResolvers: this.localState.shouldForceResolvers(transformed),
|
|
1611
|
+
hasNonreactiveDirective: utilities.hasDirectives(['nonreactive'], transformed),
|
|
1528
1612
|
clientQuery: clientQuery,
|
|
1529
1613
|
serverQuery: serverQuery,
|
|
1530
1614
|
defaultVars: utilities.getDefaultValues(utilities.getOperationDefinition(transformed)),
|
|
@@ -1722,10 +1806,17 @@ var QueryManager = (function () {
|
|
|
1722
1806
|
}
|
|
1723
1807
|
_this.broadcastQueries();
|
|
1724
1808
|
}
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
}
|
|
1809
|
+
var hasErrors = utilities.graphQLResultHasError(result);
|
|
1810
|
+
var hasProtocolErrors = errors.graphQLResultHasProtocolErrors(result);
|
|
1811
|
+
if (hasErrors || hasProtocolErrors) {
|
|
1812
|
+
var errors$1 = {};
|
|
1813
|
+
if (hasErrors) {
|
|
1814
|
+
errors$1.graphQLErrors = result.errors;
|
|
1815
|
+
}
|
|
1816
|
+
if (hasProtocolErrors) {
|
|
1817
|
+
errors$1.protocolErrors = result.extensions[errors.PROTOCOL_ERRORS_SYMBOL];
|
|
1818
|
+
}
|
|
1819
|
+
throw new errors.ApolloError(errors$1);
|
|
1729
1820
|
}
|
|
1730
1821
|
return result;
|
|
1731
1822
|
});
|
|
@@ -1857,6 +1948,9 @@ var QueryManager = (function () {
|
|
|
1857
1948
|
});
|
|
1858
1949
|
};
|
|
1859
1950
|
QueryManager.prototype.fetchQueryObservable = function (queryId, options, networkStatus) {
|
|
1951
|
+
return this.fetchConcastWithInfo(queryId, options, networkStatus).concast;
|
|
1952
|
+
};
|
|
1953
|
+
QueryManager.prototype.fetchConcastWithInfo = function (queryId, options, networkStatus) {
|
|
1860
1954
|
var _this = this;
|
|
1861
1955
|
if (networkStatus === void 0) { networkStatus = exports.NetworkStatus.loading; }
|
|
1862
1956
|
var query = this.transform(options.query).document;
|
|
@@ -1875,24 +1969,36 @@ var QueryManager = (function () {
|
|
|
1875
1969
|
});
|
|
1876
1970
|
var fromVariables = function (variables) {
|
|
1877
1971
|
normalized.variables = variables;
|
|
1878
|
-
var
|
|
1972
|
+
var sourcesWithInfo = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
|
|
1879
1973
|
if (normalized.fetchPolicy !== "standby" &&
|
|
1880
|
-
|
|
1974
|
+
sourcesWithInfo.sources.length > 0 &&
|
|
1881
1975
|
queryInfo.observableQuery) {
|
|
1882
1976
|
queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
|
|
1883
1977
|
}
|
|
1884
|
-
return
|
|
1978
|
+
return sourcesWithInfo;
|
|
1885
1979
|
};
|
|
1886
1980
|
var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
|
|
1887
1981
|
this.fetchCancelFns.set(queryId, function (reason) {
|
|
1888
1982
|
cleanupCancelFn();
|
|
1889
1983
|
setTimeout(function () { return concast.cancel(reason); });
|
|
1890
1984
|
});
|
|
1891
|
-
var concast
|
|
1892
|
-
|
|
1893
|
-
|
|
1985
|
+
var concast, containsDataFromLink;
|
|
1986
|
+
if (this.transform(normalized.query).hasClientExports) {
|
|
1987
|
+
concast = new utilities.Concast(this.localState
|
|
1988
|
+
.addExportedVariables(normalized.query, normalized.variables, normalized.context)
|
|
1989
|
+
.then(fromVariables).then(function (sourcesWithInfo) { return sourcesWithInfo.sources; }));
|
|
1990
|
+
containsDataFromLink = true;
|
|
1991
|
+
}
|
|
1992
|
+
else {
|
|
1993
|
+
var sourcesWithInfo = fromVariables(normalized.variables);
|
|
1994
|
+
containsDataFromLink = sourcesWithInfo.fromLink;
|
|
1995
|
+
concast = new utilities.Concast(sourcesWithInfo.sources);
|
|
1996
|
+
}
|
|
1894
1997
|
concast.promise.then(cleanupCancelFn, cleanupCancelFn);
|
|
1895
|
-
return
|
|
1998
|
+
return {
|
|
1999
|
+
concast: concast,
|
|
2000
|
+
fromLink: containsDataFromLink,
|
|
2001
|
+
};
|
|
1896
2002
|
};
|
|
1897
2003
|
QueryManager.prototype.refetchQueries = function (_a) {
|
|
1898
2004
|
var _this = this;
|
|
@@ -1977,7 +2083,7 @@ var QueryManager = (function () {
|
|
|
1977
2083
|
var data = diff.result;
|
|
1978
2084
|
if (globals.__DEV__ &&
|
|
1979
2085
|
!returnPartialData &&
|
|
1980
|
-
!
|
|
2086
|
+
!equal.equal(data, {})) {
|
|
1981
2087
|
logMissingFieldErrors(diff.missing);
|
|
1982
2088
|
}
|
|
1983
2089
|
var fromData = function (data) { return utilities.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
|
|
@@ -2016,54 +2122,40 @@ var QueryManager = (function () {
|
|
|
2016
2122
|
case "cache-first": {
|
|
2017
2123
|
var diff = readCache();
|
|
2018
2124
|
if (diff.complete) {
|
|
2019
|
-
return [
|
|
2020
|
-
resultsFromCache(diff, queryInfo.markReady()),
|
|
2021
|
-
];
|
|
2125
|
+
return { fromLink: false, sources: [resultsFromCache(diff, queryInfo.markReady())] };
|
|
2022
2126
|
}
|
|
2023
2127
|
if (returnPartialData || shouldNotify) {
|
|
2024
|
-
return [
|
|
2025
|
-
resultsFromCache(diff),
|
|
2026
|
-
resultsFromLink(),
|
|
2027
|
-
];
|
|
2128
|
+
return { fromLink: true, sources: [resultsFromCache(diff), resultsFromLink()] };
|
|
2028
2129
|
}
|
|
2029
|
-
return [
|
|
2030
|
-
resultsFromLink(),
|
|
2031
|
-
];
|
|
2130
|
+
return { fromLink: true, sources: [resultsFromLink()] };
|
|
2032
2131
|
}
|
|
2033
2132
|
case "cache-and-network": {
|
|
2034
2133
|
var diff = readCache();
|
|
2035
2134
|
if (diff.complete || returnPartialData || shouldNotify) {
|
|
2036
|
-
return [
|
|
2037
|
-
resultsFromCache(diff),
|
|
2038
|
-
resultsFromLink(),
|
|
2039
|
-
];
|
|
2135
|
+
return { fromLink: true, sources: [resultsFromCache(diff), resultsFromLink()] };
|
|
2040
2136
|
}
|
|
2041
|
-
return [
|
|
2042
|
-
resultsFromLink(),
|
|
2043
|
-
];
|
|
2137
|
+
return { fromLink: true, sources: [resultsFromLink()] };
|
|
2044
2138
|
}
|
|
2045
2139
|
case "cache-only":
|
|
2046
|
-
return [
|
|
2047
|
-
resultsFromCache(readCache(), queryInfo.markReady()),
|
|
2048
|
-
];
|
|
2140
|
+
return { fromLink: false, sources: [resultsFromCache(readCache(), queryInfo.markReady())] };
|
|
2049
2141
|
case "network-only":
|
|
2050
2142
|
if (shouldNotify) {
|
|
2051
|
-
return [
|
|
2052
|
-
resultsFromCache(readCache()),
|
|
2053
|
-
resultsFromLink(),
|
|
2054
|
-
];
|
|
2143
|
+
return { fromLink: true, sources: [resultsFromCache(readCache()), resultsFromLink()] };
|
|
2055
2144
|
}
|
|
2056
|
-
return [resultsFromLink()];
|
|
2145
|
+
return { fromLink: true, sources: [resultsFromLink()] };
|
|
2057
2146
|
case "no-cache":
|
|
2058
2147
|
if (shouldNotify) {
|
|
2059
|
-
return
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2148
|
+
return {
|
|
2149
|
+
fromLink: true,
|
|
2150
|
+
sources: [
|
|
2151
|
+
resultsFromCache(queryInfo.getDiff()),
|
|
2152
|
+
resultsFromLink(),
|
|
2153
|
+
],
|
|
2154
|
+
};
|
|
2063
2155
|
}
|
|
2064
|
-
return [resultsFromLink()];
|
|
2156
|
+
return { fromLink: true, sources: [resultsFromLink()] };
|
|
2065
2157
|
case "standby":
|
|
2066
|
-
return [];
|
|
2158
|
+
return { fromLink: false, sources: [] };
|
|
2067
2159
|
}
|
|
2068
2160
|
};
|
|
2069
2161
|
QueryManager.prototype.getQuery = function (queryId) {
|
|
@@ -2342,6 +2434,7 @@ exports.gql = graphqlTag.gql;
|
|
|
2342
2434
|
exports.resetCaches = graphqlTag.resetCaches;
|
|
2343
2435
|
exports.ApolloClient = ApolloClient;
|
|
2344
2436
|
exports.ObservableQuery = ObservableQuery;
|
|
2437
|
+
exports.isNetworkRequestSettled = isNetworkRequestSettled;
|
|
2345
2438
|
for (var k in core) {
|
|
2346
2439
|
if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = core[k];
|
|
2347
2440
|
}
|