@apollo/client 3.5.10 → 3.6.9
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/LICENSE +1 -1
- package/README.md +5 -5
- package/apollo-client.cjs +563 -375
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +10 -11
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +2288 -0
- package/cache/inmemory/policies.js +1 -1
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts.map +1 -1
- package/cache/inmemory/readFromStore.js +10 -11
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/core/ApolloClient.d.ts +2 -3
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js +4 -8
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +10 -4
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +101 -46
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js +4 -2
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +5 -2
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +36 -27
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +148 -90
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +2146 -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/core/watchQueryOptions.d.ts +9 -1
- package/core/watchQueryOptions.d.ts.map +1 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/errors/errors.cjs.native.js +48 -0
- package/invariantErrorCodes.js +1 -1
- package/link/batch/batch.cjs +46 -37
- package/link/batch/batch.cjs.map +1 -1
- package/link/batch/batch.cjs.native.js +160 -0
- package/link/batch/batching.d.ts +2 -6
- package/link/batch/batching.d.ts.map +1 -1
- package/link/batch/batching.js +46 -37
- package/link/batch/batching.js.map +1 -1
- package/link/batch-http/batch-http.cjs.native.js +127 -0
- package/link/context/context.cjs.native.js +38 -0
- package/link/core/core.cjs.native.js +121 -0
- package/link/error/error.cjs.native.js +90 -0
- package/link/http/http.cjs.native.js +320 -0
- package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/persisted-queries/index.d.ts +2 -1
- package/link/persisted-queries/index.d.ts.map +1 -1
- package/link/persisted-queries/index.js +26 -13
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs +25 -12
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
- package/link/retry/retry.cjs.native.js +170 -0
- package/link/schema/schema.cjs.native.js +56 -0
- package/link/subscriptions/subscriptions.cjs.native.js +45 -0
- package/link/utils/utils.cjs.native.js +115 -0
- package/link/ws/ws.cjs.native.js +28 -0
- package/main.cjs.native.js +16 -0
- package/package.json +30 -27
- package/react/components/components.cjs.native.js +79 -0
- package/react/context/ApolloConsumer.js +2 -2
- package/react/context/ApolloProvider.js +2 -2
- package/react/context/context.cjs +4 -4
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +67 -0
- package/react/hoc/hoc.cjs.native.js +325 -0
- package/react/hooks/hooks.cjs +376 -253
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +623 -0
- package/react/hooks/index.d.ts +1 -1
- package/react/hooks/index.d.ts.map +1 -1
- package/react/hooks/index.js +1 -1
- package/react/hooks/index.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +2 -2
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +26 -21
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts.map +1 -1
- package/react/hooks/useMutation.js +13 -10
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +37 -2
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +256 -206
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts.map +1 -1
- package/react/hooks/useSubscription.js +17 -7
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSyncExternalStore.d.ts +4 -0
- package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
- package/react/hooks/useSyncExternalStore.js +48 -0
- package/react/hooks/useSyncExternalStore.js.map +1 -0
- package/react/parser/index.d.ts.map +1 -1
- package/react/parser/index.js +24 -10
- package/react/parser/index.js.map +1 -1
- package/react/parser/parser.cjs +24 -10
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +103 -0
- package/react/react.cjs.native.js +22 -0
- package/react/ssr/RenderPromises.d.ts +3 -2
- package/react/ssr/RenderPromises.d.ts.map +1 -1
- package/react/ssr/RenderPromises.js +25 -3
- package/react/ssr/RenderPromises.js.map +1 -1
- package/react/ssr/ssr.cjs +25 -3
- package/react/ssr/ssr.cjs.map +1 -1
- package/react/ssr/ssr.cjs.native.js +150 -0
- package/react/types/types.d.ts +10 -11
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/core.cjs.native.js +288 -0
- package/testing/core/mocking/mockFetch.js +1 -1
- package/testing/core/mocking/mockFetch.js.map +1 -1
- package/testing/core/mocking/mockQueryManager.js +1 -1
- package/testing/core/mocking/mockWatchQuery.js +1 -1
- package/testing/core/wrap.js +1 -1
- package/testing/testing.cjs.native.js +58 -0
- package/utilities/common/canUse.d.ts +2 -0
- package/utilities/common/canUse.d.ts.map +1 -1
- package/utilities/common/canUse.js +6 -2
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/mergeDeep.d.ts.map +1 -1
- package/utilities/common/mergeDeep.js +8 -11
- package/utilities/common/mergeDeep.js.map +1 -1
- package/utilities/common/mergeOptions.d.ts +5 -0
- package/utilities/common/mergeOptions.d.ts.map +1 -0
- package/utilities/common/mergeOptions.js +8 -0
- package/utilities/common/mergeOptions.js.map +1 -0
- package/utilities/globals/global.js +1 -2
- package/utilities/globals/globals.cjs.native.js +56 -0
- package/utilities/graphql/transform.d.ts +2 -2
- package/utilities/graphql/transform.d.ts.map +1 -1
- package/utilities/graphql/transform.js +1 -1
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +1 -0
- package/utilities/index.d.ts.map +1 -1
- package/utilities/index.js +1 -0
- package/utilities/index.js.map +1 -1
- package/utilities/observables/Concast.d.ts +1 -0
- package/utilities/observables/Concast.d.ts.map +1 -1
- package/utilities/observables/Concast.js +5 -2
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/policies/pagination.d.ts.map +1 -1
- package/utilities/policies/pagination.js +9 -7
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/utilities.cjs +37 -23
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +1281 -0
- package/version.js +1 -1
package/core/core.cjs
CHANGED
|
@@ -5,17 +5,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var globals = require('../utilities/globals');
|
|
6
6
|
var tslib = require('tslib');
|
|
7
7
|
var core = require('../link/core');
|
|
8
|
-
var utilities = require('../utilities');
|
|
9
8
|
var http = require('../link/http');
|
|
10
9
|
var equality = require('@wry/equality');
|
|
11
10
|
var cache = require('../cache');
|
|
11
|
+
var utilities = require('../utilities');
|
|
12
12
|
var errors = require('../errors');
|
|
13
13
|
var graphql = require('graphql');
|
|
14
14
|
var utils = require('../link/utils');
|
|
15
15
|
var tsInvariant = require('ts-invariant');
|
|
16
16
|
var graphqlTag = require('graphql-tag');
|
|
17
17
|
|
|
18
|
-
var version = '3.
|
|
18
|
+
var version = '3.6.9';
|
|
19
19
|
|
|
20
20
|
exports.NetworkStatus = void 0;
|
|
21
21
|
(function (NetworkStatus) {
|
|
@@ -32,7 +32,6 @@ function isNetworkRequestInFlight(networkStatus) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
|
|
35
|
-
var warnedAboutUpdateQuery = false;
|
|
36
35
|
var ObservableQuery = (function (_super) {
|
|
37
36
|
tslib.__extends(ObservableQuery, _super);
|
|
38
37
|
function ObservableQuery(_a) {
|
|
@@ -65,16 +64,24 @@ var ObservableQuery = (function (_super) {
|
|
|
65
64
|
}) || this;
|
|
66
65
|
_this.observers = new Set();
|
|
67
66
|
_this.subscriptions = new Set();
|
|
67
|
+
_this.queryInfo = queryInfo;
|
|
68
|
+
_this.queryManager = queryManager;
|
|
68
69
|
_this.isTornDown = false;
|
|
69
|
-
|
|
70
|
+
var _b = queryManager.defaultOptions.watchQuery, _c = _b === void 0 ? {} : _b, _d = _c.fetchPolicy, defaultFetchPolicy = _d === void 0 ? "cache-first" : _d;
|
|
71
|
+
var _e = options.fetchPolicy, fetchPolicy = _e === void 0 ? defaultFetchPolicy : _e, _f = options.initialFetchPolicy, initialFetchPolicy = _f === void 0 ? (fetchPolicy === "standby" ? defaultFetchPolicy : fetchPolicy) : _f;
|
|
72
|
+
_this.options = tslib.__assign(tslib.__assign({}, options), { initialFetchPolicy: initialFetchPolicy, fetchPolicy: fetchPolicy });
|
|
70
73
|
_this.queryId = queryInfo.queryId || queryManager.generateQueryId();
|
|
71
|
-
var opDef = utilities.getOperationDefinition(
|
|
74
|
+
var opDef = utilities.getOperationDefinition(_this.query);
|
|
72
75
|
_this.queryName = opDef && opDef.name && opDef.name.value;
|
|
73
|
-
_this.initialFetchPolicy = options.fetchPolicy || "cache-first";
|
|
74
|
-
_this.queryManager = queryManager;
|
|
75
|
-
_this.queryInfo = queryInfo;
|
|
76
76
|
return _this;
|
|
77
77
|
}
|
|
78
|
+
Object.defineProperty(ObservableQuery.prototype, "query", {
|
|
79
|
+
get: function () {
|
|
80
|
+
return this.queryManager.transform(this.options.query).document;
|
|
81
|
+
},
|
|
82
|
+
enumerable: false,
|
|
83
|
+
configurable: true
|
|
84
|
+
});
|
|
78
85
|
Object.defineProperty(ObservableQuery.prototype, "variables", {
|
|
79
86
|
get: function () {
|
|
80
87
|
return this.options.variables;
|
|
@@ -188,7 +195,7 @@ var ObservableQuery = (function (_super) {
|
|
|
188
195
|
reobserveOptions.fetchPolicy = 'network-only';
|
|
189
196
|
}
|
|
190
197
|
if (__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
|
|
191
|
-
var queryDef = utilities.getQueryDefinition(this.
|
|
198
|
+
var queryDef = utilities.getQueryDefinition(this.query);
|
|
192
199
|
var vars = queryDef.variableDefinitions;
|
|
193
200
|
if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
|
|
194
201
|
__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 })?"));
|
|
@@ -202,37 +209,51 @@ var ObservableQuery = (function (_super) {
|
|
|
202
209
|
};
|
|
203
210
|
ObservableQuery.prototype.fetchMore = function (fetchMoreOptions) {
|
|
204
211
|
var _this = this;
|
|
205
|
-
var combinedOptions = tslib.__assign(tslib.__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : tslib.__assign(tslib.__assign(tslib.__assign({}, this.options), fetchMoreOptions), { variables: tslib.__assign(tslib.__assign({}, this.options.variables), fetchMoreOptions.variables) }))), { fetchPolicy: "no-cache" });
|
|
212
|
+
var combinedOptions = tslib.__assign(tslib.__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : tslib.__assign(tslib.__assign(tslib.__assign(tslib.__assign({}, this.options), { query: this.query }), fetchMoreOptions), { variables: tslib.__assign(tslib.__assign({}, this.options.variables), fetchMoreOptions.variables) }))), { fetchPolicy: "no-cache" });
|
|
206
213
|
var qid = this.queryManager.generateQueryId();
|
|
214
|
+
var queryInfo = this.queryInfo;
|
|
215
|
+
var originalNetworkStatus = queryInfo.networkStatus;
|
|
216
|
+
queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
|
|
207
217
|
if (combinedOptions.notifyOnNetworkStatusChange) {
|
|
208
|
-
this.queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
|
|
209
218
|
this.observe();
|
|
210
219
|
}
|
|
220
|
+
var updatedQuerySet = new Set();
|
|
211
221
|
return this.queryManager.fetchQuery(qid, combinedOptions, exports.NetworkStatus.fetchMore).then(function (fetchMoreResult) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (__DEV__ &&
|
|
216
|
-
!warnedAboutUpdateQuery) {
|
|
217
|
-
__DEV__ && globals.invariant.warn("The updateQuery callback for fetchMore is deprecated, and will be removed\nin the next major version of Apollo Client.\n\nPlease convert updateQuery functions to field policies with appropriate\nread and merge functions, or use/adapt a helper function (such as\nconcatPagination, offsetLimitPagination, or relayStylePagination) from\n@apollo/client/utilities.\n\nThe field policy system handles pagination more effectively than a\nhand-written updateQuery function, and you only need to define the policy\nonce, rather than every time you call fetchMore.");
|
|
218
|
-
warnedAboutUpdateQuery = true;
|
|
219
|
-
}
|
|
220
|
-
_this.updateQuery(function (previous) { return updateQuery(previous, {
|
|
221
|
-
fetchMoreResult: data,
|
|
222
|
-
variables: combinedOptions.variables,
|
|
223
|
-
}); });
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
_this.queryManager.cache.writeQuery({
|
|
227
|
-
query: combinedOptions.query,
|
|
228
|
-
variables: combinedOptions.variables,
|
|
229
|
-
data: data,
|
|
230
|
-
});
|
|
222
|
+
_this.queryManager.removeQuery(qid);
|
|
223
|
+
if (queryInfo.networkStatus === exports.NetworkStatus.fetchMore) {
|
|
224
|
+
queryInfo.networkStatus = originalNetworkStatus;
|
|
231
225
|
}
|
|
226
|
+
_this.queryManager.cache.batch({
|
|
227
|
+
update: function (cache) {
|
|
228
|
+
var updateQuery = fetchMoreOptions.updateQuery;
|
|
229
|
+
if (updateQuery) {
|
|
230
|
+
cache.updateQuery({
|
|
231
|
+
query: _this.query,
|
|
232
|
+
variables: _this.variables,
|
|
233
|
+
returnPartialData: true,
|
|
234
|
+
optimistic: false,
|
|
235
|
+
}, function (previous) { return updateQuery(previous, {
|
|
236
|
+
fetchMoreResult: fetchMoreResult.data,
|
|
237
|
+
variables: combinedOptions.variables,
|
|
238
|
+
}); });
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
cache.writeQuery({
|
|
242
|
+
query: combinedOptions.query,
|
|
243
|
+
variables: combinedOptions.variables,
|
|
244
|
+
data: fetchMoreResult.data,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
onWatchUpdated: function (watch) {
|
|
249
|
+
updatedQuerySet.add(watch.query);
|
|
250
|
+
},
|
|
251
|
+
});
|
|
232
252
|
return fetchMoreResult;
|
|
233
253
|
}).finally(function () {
|
|
234
|
-
_this.
|
|
235
|
-
|
|
254
|
+
if (!updatedQuerySet.has(_this.query)) {
|
|
255
|
+
reobserveCacheFirst(_this);
|
|
256
|
+
}
|
|
236
257
|
});
|
|
237
258
|
};
|
|
238
259
|
ObservableQuery.prototype.subscribeToMore = function (options) {
|
|
@@ -285,7 +306,7 @@ var ObservableQuery = (function (_super) {
|
|
|
285
306
|
return Promise.resolve();
|
|
286
307
|
}
|
|
287
308
|
return this.reobserve({
|
|
288
|
-
fetchPolicy: this.initialFetchPolicy,
|
|
309
|
+
fetchPolicy: this.options.initialFetchPolicy,
|
|
289
310
|
variables: variables,
|
|
290
311
|
}, exports.NetworkStatus.setVariables);
|
|
291
312
|
};
|
|
@@ -317,6 +338,27 @@ var ObservableQuery = (function (_super) {
|
|
|
317
338
|
this.options.pollInterval = 0;
|
|
318
339
|
this.updatePolling();
|
|
319
340
|
};
|
|
341
|
+
ObservableQuery.prototype.applyNextFetchPolicy = function (reason, options) {
|
|
342
|
+
if (options.nextFetchPolicy) {
|
|
343
|
+
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? fetchPolicy : _b;
|
|
344
|
+
if (fetchPolicy === "standby") ;
|
|
345
|
+
else if (typeof options.nextFetchPolicy === "function") {
|
|
346
|
+
options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
|
|
347
|
+
reason: reason,
|
|
348
|
+
options: options,
|
|
349
|
+
observable: this,
|
|
350
|
+
initialFetchPolicy: initialFetchPolicy,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
else if (reason === "variables-changed") {
|
|
354
|
+
options.fetchPolicy = initialFetchPolicy;
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
options.fetchPolicy = options.nextFetchPolicy;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return options.fetchPolicy;
|
|
361
|
+
};
|
|
320
362
|
ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
|
|
321
363
|
this.queryManager.setObservableQuery(this);
|
|
322
364
|
return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
|
|
@@ -379,16 +421,19 @@ var ObservableQuery = (function (_super) {
|
|
|
379
421
|
newNetworkStatus === exports.NetworkStatus.fetchMore ||
|
|
380
422
|
newNetworkStatus === exports.NetworkStatus.poll;
|
|
381
423
|
var oldVariables = this.options.variables;
|
|
424
|
+
var oldFetchPolicy = this.options.fetchPolicy;
|
|
425
|
+
var mergedOptions = utilities.compact(this.options, newOptions || {});
|
|
382
426
|
var options = useDisposableConcast
|
|
383
|
-
?
|
|
384
|
-
: assign(this.options,
|
|
427
|
+
? mergedOptions
|
|
428
|
+
: assign(this.options, mergedOptions);
|
|
385
429
|
if (!useDisposableConcast) {
|
|
386
430
|
this.updatePolling();
|
|
387
431
|
if (newOptions &&
|
|
388
432
|
newOptions.variables &&
|
|
389
|
-
!newOptions.
|
|
390
|
-
|
|
391
|
-
options.fetchPolicy
|
|
433
|
+
!equality.equal(newOptions.variables, oldVariables) &&
|
|
434
|
+
options.fetchPolicy !== "standby" &&
|
|
435
|
+
options.fetchPolicy === oldFetchPolicy) {
|
|
436
|
+
this.applyNextFetchPolicy("variables-changed", options);
|
|
392
437
|
if (newNetworkStatus === void 0) {
|
|
393
438
|
newNetworkStatus = exports.NetworkStatus.setVariables;
|
|
394
439
|
}
|
|
@@ -406,7 +451,7 @@ var ObservableQuery = (function (_super) {
|
|
|
406
451
|
};
|
|
407
452
|
if (!useDisposableConcast) {
|
|
408
453
|
if (this.concast && this.observer) {
|
|
409
|
-
this.concast.removeObserver(this.observer
|
|
454
|
+
this.concast.removeObserver(this.observer);
|
|
410
455
|
}
|
|
411
456
|
this.concast = concast;
|
|
412
457
|
this.observer = observer;
|
|
@@ -452,6 +497,23 @@ var ObservableQuery = (function (_super) {
|
|
|
452
497
|
return ObservableQuery;
|
|
453
498
|
}(utilities.Observable));
|
|
454
499
|
utilities.fixObservableSubclass(ObservableQuery);
|
|
500
|
+
function reobserveCacheFirst(obsQuery) {
|
|
501
|
+
var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
|
|
502
|
+
if (fetchPolicy === "cache-and-network" ||
|
|
503
|
+
fetchPolicy === "network-only") {
|
|
504
|
+
return obsQuery.reobserve({
|
|
505
|
+
fetchPolicy: "cache-first",
|
|
506
|
+
nextFetchPolicy: function () {
|
|
507
|
+
this.nextFetchPolicy = nextFetchPolicy;
|
|
508
|
+
if (typeof nextFetchPolicy === "function") {
|
|
509
|
+
return nextFetchPolicy.apply(this, arguments);
|
|
510
|
+
}
|
|
511
|
+
return fetchPolicy;
|
|
512
|
+
},
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
return obsQuery.reobserve();
|
|
516
|
+
}
|
|
455
517
|
function defaultSubscriptionObserverErrorCallback(error) {
|
|
456
518
|
__DEV__ && globals.invariant.error('Unhandled error', error.message, error.stack);
|
|
457
519
|
}
|
|
@@ -460,14 +522,6 @@ function logMissingFieldErrors(missing) {
|
|
|
460
522
|
__DEV__ && globals.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
|
|
461
523
|
}
|
|
462
524
|
}
|
|
463
|
-
function applyNextFetchPolicy(options) {
|
|
464
|
-
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, nextFetchPolicy = options.nextFetchPolicy;
|
|
465
|
-
if (nextFetchPolicy) {
|
|
466
|
-
options.fetchPolicy = typeof nextFetchPolicy === "function"
|
|
467
|
-
? nextFetchPolicy.call(options, fetchPolicy)
|
|
468
|
-
: nextFetchPolicy;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
525
|
|
|
472
526
|
var LocalState = (function () {
|
|
473
527
|
function LocalState(_a) {
|
|
@@ -850,11 +904,12 @@ var QueryInfo = (function () {
|
|
|
850
904
|
if (oq) {
|
|
851
905
|
oq["queryInfo"] = this;
|
|
852
906
|
this.listeners.add(this.oqListener = function () {
|
|
853
|
-
|
|
907
|
+
var diff = _this.getDiff();
|
|
908
|
+
if (diff.fromOptimisticTransaction) {
|
|
854
909
|
oq["observe"]();
|
|
855
910
|
}
|
|
856
911
|
else {
|
|
857
|
-
oq
|
|
912
|
+
reobserveCacheFirst(oq);
|
|
858
913
|
}
|
|
859
914
|
});
|
|
860
915
|
}
|
|
@@ -999,7 +1054,7 @@ function shouldWriteResult(result, errorPolicy) {
|
|
|
999
1054
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1000
1055
|
var QueryManager = (function () {
|
|
1001
1056
|
function QueryManager(_a) {
|
|
1002
|
-
var cache = _a.cache, link = _a.link, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, assumeImmutableResults = _a.assumeImmutableResults;
|
|
1057
|
+
var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, assumeImmutableResults = _a.assumeImmutableResults;
|
|
1003
1058
|
this.clientAwareness = {};
|
|
1004
1059
|
this.queries = new Map();
|
|
1005
1060
|
this.fetchCancelFns = new Map();
|
|
@@ -1010,6 +1065,7 @@ var QueryManager = (function () {
|
|
|
1010
1065
|
this.inFlightLinkObservables = new Map();
|
|
1011
1066
|
this.cache = cache;
|
|
1012
1067
|
this.link = link;
|
|
1068
|
+
this.defaultOptions = defaultOptions || Object.create(null);
|
|
1013
1069
|
this.queryDeduplication = queryDeduplication;
|
|
1014
1070
|
this.clientAwareness = clientAwareness;
|
|
1015
1071
|
this.localState = localState || new LocalState({ cache: cache });
|
|
@@ -1031,11 +1087,12 @@ var QueryManager = (function () {
|
|
|
1031
1087
|
this.fetchCancelFns.clear();
|
|
1032
1088
|
};
|
|
1033
1089
|
QueryManager.prototype.mutate = function (_a) {
|
|
1034
|
-
var
|
|
1090
|
+
var _b, _c;
|
|
1091
|
+
var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _d = _a.refetchQueries, refetchQueries = _d === void 0 ? [] : _d, _e = _a.awaitRefetchQueries, awaitRefetchQueries = _e === void 0 ? false : _e, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _f = _a.fetchPolicy, fetchPolicy = _f === void 0 ? ((_b = this.defaultOptions.mutate) === null || _b === void 0 ? void 0 : _b.fetchPolicy) || "network-only" : _f, _g = _a.errorPolicy, errorPolicy = _g === void 0 ? ((_c = this.defaultOptions.mutate) === null || _c === void 0 ? void 0 : _c.errorPolicy) || "none" : _g, keepRootFields = _a.keepRootFields, context = _a.context;
|
|
1035
1092
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1036
1093
|
var mutationId, mutationStoreValue, self;
|
|
1037
|
-
return tslib.__generator(this, function (
|
|
1038
|
-
switch (
|
|
1094
|
+
return tslib.__generator(this, function (_h) {
|
|
1095
|
+
switch (_h.label) {
|
|
1039
1096
|
case 0:
|
|
1040
1097
|
__DEV__ ? globals.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : globals.invariant(mutation, 12);
|
|
1041
1098
|
__DEV__ ? globals.invariant(fetchPolicy === 'network-only' ||
|
|
@@ -1047,8 +1104,8 @@ var QueryManager = (function () {
|
|
|
1047
1104
|
if (!this.transform(mutation).hasClientExports) return [3, 2];
|
|
1048
1105
|
return [4, this.localState.addExportedVariables(mutation, variables, context)];
|
|
1049
1106
|
case 1:
|
|
1050
|
-
variables = (
|
|
1051
|
-
|
|
1107
|
+
variables = (_h.sent());
|
|
1108
|
+
_h.label = 2;
|
|
1052
1109
|
case 2:
|
|
1053
1110
|
mutationStoreValue = this.mutationStore &&
|
|
1054
1111
|
(this.mutationStore[mutationId] = {
|
|
@@ -1315,9 +1372,9 @@ var QueryManager = (function () {
|
|
|
1315
1372
|
});
|
|
1316
1373
|
this.queries.set(observable.queryId, queryInfo);
|
|
1317
1374
|
queryInfo.init({
|
|
1318
|
-
document:
|
|
1375
|
+
document: observable.query,
|
|
1319
1376
|
observableQuery: observable,
|
|
1320
|
-
variables:
|
|
1377
|
+
variables: observable.variables,
|
|
1321
1378
|
});
|
|
1322
1379
|
return observable;
|
|
1323
1380
|
};
|
|
@@ -1501,8 +1558,10 @@ var QueryManager = (function () {
|
|
|
1501
1558
|
};
|
|
1502
1559
|
QueryManager.prototype.removeQuery = function (queryId) {
|
|
1503
1560
|
this.fetchCancelFns.delete(queryId);
|
|
1504
|
-
this.
|
|
1505
|
-
|
|
1561
|
+
if (this.queries.has(queryId)) {
|
|
1562
|
+
this.getQuery(queryId).stop();
|
|
1563
|
+
this.queries.delete(queryId);
|
|
1564
|
+
}
|
|
1506
1565
|
};
|
|
1507
1566
|
QueryManager.prototype.broadcastQueries = function () {
|
|
1508
1567
|
if (this.onBroadcast)
|
|
@@ -1586,10 +1645,11 @@ var QueryManager = (function () {
|
|
|
1586
1645
|
var aqr = {
|
|
1587
1646
|
data: result.data,
|
|
1588
1647
|
loading: false,
|
|
1589
|
-
networkStatus:
|
|
1648
|
+
networkStatus: exports.NetworkStatus.ready,
|
|
1590
1649
|
};
|
|
1591
1650
|
if (hasErrors && options.errorPolicy !== "ignore") {
|
|
1592
1651
|
aqr.errors = result.errors;
|
|
1652
|
+
aqr.networkStatus = exports.NetworkStatus.error;
|
|
1593
1653
|
}
|
|
1594
1654
|
return aqr;
|
|
1595
1655
|
}, function (networkError) {
|
|
@@ -1608,7 +1668,8 @@ var QueryManager = (function () {
|
|
|
1608
1668
|
var query = this.transform(options.query).document;
|
|
1609
1669
|
var variables = this.getVariables(query, options.variables);
|
|
1610
1670
|
var queryInfo = this.getQuery(queryId);
|
|
1611
|
-
var
|
|
1671
|
+
var defaults = this.defaultOptions.watchQuery;
|
|
1672
|
+
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? defaults && defaults.fetchPolicy || "cache-first" : _a, _b = options.errorPolicy, errorPolicy = _b === void 0 ? defaults && defaults.errorPolicy || "none" : _b, _c = options.returnPartialData, returnPartialData = _c === void 0 ? false : _c, _d = options.notifyOnNetworkStatusChange, notifyOnNetworkStatusChange = _d === void 0 ? false : _d, _e = options.context, context = _e === void 0 ? {} : _e;
|
|
1612
1673
|
var normalized = Object.assign({}, options, {
|
|
1613
1674
|
query: query,
|
|
1614
1675
|
variables: variables,
|
|
@@ -1620,18 +1681,23 @@ var QueryManager = (function () {
|
|
|
1620
1681
|
});
|
|
1621
1682
|
var fromVariables = function (variables) {
|
|
1622
1683
|
normalized.variables = variables;
|
|
1623
|
-
|
|
1684
|
+
var concastSources = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
|
|
1685
|
+
if (normalized.fetchPolicy !== "standby" &&
|
|
1686
|
+
concastSources.length > 0 &&
|
|
1687
|
+
queryInfo.observableQuery) {
|
|
1688
|
+
queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
|
|
1689
|
+
}
|
|
1690
|
+
return concastSources;
|
|
1624
1691
|
};
|
|
1692
|
+
var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
|
|
1625
1693
|
this.fetchCancelFns.set(queryId, function (reason) {
|
|
1694
|
+
cleanupCancelFn();
|
|
1626
1695
|
setTimeout(function () { return concast.cancel(reason); });
|
|
1627
1696
|
});
|
|
1628
1697
|
var concast = new utilities.Concast(this.transform(normalized.query).hasClientExports
|
|
1629
1698
|
? this.localState.addExportedVariables(normalized.query, normalized.variables, normalized.context).then(fromVariables)
|
|
1630
1699
|
: fromVariables(normalized.variables));
|
|
1631
|
-
concast.
|
|
1632
|
-
_this.fetchCancelFns.delete(queryId);
|
|
1633
|
-
applyNextFetchPolicy(options);
|
|
1634
|
-
});
|
|
1700
|
+
concast.promise.then(cleanupCancelFn, cleanupCancelFn);
|
|
1635
1701
|
return concast;
|
|
1636
1702
|
};
|
|
1637
1703
|
QueryManager.prototype.refetchQueries = function (_a) {
|
|
@@ -1707,7 +1773,7 @@ var QueryManager = (function () {
|
|
|
1707
1773
|
var query = _a.query, variables = _a.variables, fetchPolicy = _a.fetchPolicy, refetchWritePolicy = _a.refetchWritePolicy, errorPolicy = _a.errorPolicy, returnPartialData = _a.returnPartialData, context = _a.context, notifyOnNetworkStatusChange = _a.notifyOnNetworkStatusChange;
|
|
1708
1774
|
var oldNetworkStatus = queryInfo.networkStatus;
|
|
1709
1775
|
queryInfo.init({
|
|
1710
|
-
document: query,
|
|
1776
|
+
document: this.transform(query).document,
|
|
1711
1777
|
variables: variables,
|
|
1712
1778
|
networkStatus: networkStatus,
|
|
1713
1779
|
});
|
|
@@ -1736,14 +1802,12 @@ var QueryManager = (function () {
|
|
|
1736
1802
|
(networkStatus === exports.NetworkStatus.refetch &&
|
|
1737
1803
|
refetchWritePolicy !== "merge") ? 1
|
|
1738
1804
|
: 2;
|
|
1739
|
-
var resultsFromLink = function () {
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
});
|
|
1746
|
-
};
|
|
1805
|
+
var resultsFromLink = function () { return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
|
|
1806
|
+
variables: variables,
|
|
1807
|
+
context: context,
|
|
1808
|
+
fetchPolicy: fetchPolicy,
|
|
1809
|
+
errorPolicy: errorPolicy,
|
|
1810
|
+
}); };
|
|
1747
1811
|
var shouldNotify = notifyOnNetworkStatusChange &&
|
|
1748
1812
|
typeof oldNetworkStatus === "number" &&
|
|
1749
1813
|
oldNetworkStatus !== networkStatus &&
|
|
@@ -1818,15 +1882,9 @@ var QueryManager = (function () {
|
|
|
1818
1882
|
}());
|
|
1819
1883
|
|
|
1820
1884
|
var hasSuggestedDevtools = false;
|
|
1821
|
-
function mergeOptions(defaults, options) {
|
|
1822
|
-
return utilities.compact(defaults, options, options.variables && {
|
|
1823
|
-
variables: tslib.__assign(tslib.__assign({}, defaults.variables), options.variables),
|
|
1824
|
-
});
|
|
1825
|
-
}
|
|
1826
1885
|
var ApolloClient = (function () {
|
|
1827
1886
|
function ApolloClient(options) {
|
|
1828
1887
|
var _this = this;
|
|
1829
|
-
this.defaultOptions = {};
|
|
1830
1888
|
this.resetStoreCallbacks = [];
|
|
1831
1889
|
this.clearStoreCallbacks = [];
|
|
1832
1890
|
var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b, _c = options.connectToDevTools, connectToDevTools = _c === void 0 ? typeof window === 'object' &&
|
|
@@ -1847,7 +1905,7 @@ var ApolloClient = (function () {
|
|
|
1847
1905
|
this.cache = cache;
|
|
1848
1906
|
this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
|
|
1849
1907
|
this.queryDeduplication = queryDeduplication;
|
|
1850
|
-
this.defaultOptions = defaultOptions ||
|
|
1908
|
+
this.defaultOptions = defaultOptions || Object.create(null);
|
|
1851
1909
|
this.typeDefs = typeDefs;
|
|
1852
1910
|
if (ssrForceFetchDelay) {
|
|
1853
1911
|
setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
|
|
@@ -1894,6 +1952,7 @@ var ApolloClient = (function () {
|
|
|
1894
1952
|
this.queryManager = new QueryManager({
|
|
1895
1953
|
cache: this.cache,
|
|
1896
1954
|
link: this.link,
|
|
1955
|
+
defaultOptions: this.defaultOptions,
|
|
1897
1956
|
queryDeduplication: queryDeduplication,
|
|
1898
1957
|
ssrMode: ssrMode,
|
|
1899
1958
|
clientAwareness: {
|
|
@@ -1921,7 +1980,7 @@ var ApolloClient = (function () {
|
|
|
1921
1980
|
};
|
|
1922
1981
|
ApolloClient.prototype.watchQuery = function (options) {
|
|
1923
1982
|
if (this.defaultOptions.watchQuery) {
|
|
1924
|
-
options = mergeOptions(this.defaultOptions.watchQuery, options);
|
|
1983
|
+
options = utilities.mergeOptions(this.defaultOptions.watchQuery, options);
|
|
1925
1984
|
}
|
|
1926
1985
|
if (this.disableNetworkFetches &&
|
|
1927
1986
|
(options.fetchPolicy === 'network-only' ||
|
|
@@ -1932,7 +1991,7 @@ var ApolloClient = (function () {
|
|
|
1932
1991
|
};
|
|
1933
1992
|
ApolloClient.prototype.query = function (options) {
|
|
1934
1993
|
if (this.defaultOptions.query) {
|
|
1935
|
-
options = mergeOptions(this.defaultOptions.query, options);
|
|
1994
|
+
options = utilities.mergeOptions(this.defaultOptions.query, options);
|
|
1936
1995
|
}
|
|
1937
1996
|
__DEV__ ? globals.invariant(options.fetchPolicy !== 'cache-and-network', 'The cache-and-network fetchPolicy does not work with client.query, because ' +
|
|
1938
1997
|
'client.query can only return a single result. Please use client.watchQuery ' +
|
|
@@ -1945,7 +2004,7 @@ var ApolloClient = (function () {
|
|
|
1945
2004
|
};
|
|
1946
2005
|
ApolloClient.prototype.mutate = function (options) {
|
|
1947
2006
|
if (this.defaultOptions.mutate) {
|
|
1948
|
-
options = mergeOptions(this.defaultOptions.mutate, options);
|
|
2007
|
+
options = utilities.mergeOptions(this.defaultOptions.mutate, options);
|
|
1949
2008
|
}
|
|
1950
2009
|
return this.queryManager.mutate(options);
|
|
1951
2010
|
};
|
|
@@ -2054,15 +2113,16 @@ var ApolloClient = (function () {
|
|
|
2054
2113
|
|
|
2055
2114
|
tsInvariant.setVerbosity(globals.DEV ? "log" : "silent");
|
|
2056
2115
|
|
|
2057
|
-
exports.Observable = utilities.Observable;
|
|
2058
|
-
exports.isReference = utilities.isReference;
|
|
2059
|
-
exports.makeReference = utilities.makeReference;
|
|
2060
2116
|
exports.ApolloCache = cache.ApolloCache;
|
|
2061
2117
|
exports.Cache = cache.Cache;
|
|
2062
2118
|
exports.InMemoryCache = cache.InMemoryCache;
|
|
2063
2119
|
exports.MissingFieldError = cache.MissingFieldError;
|
|
2064
2120
|
exports.defaultDataIdFromObject = cache.defaultDataIdFromObject;
|
|
2065
2121
|
exports.makeVar = cache.makeVar;
|
|
2122
|
+
exports.Observable = utilities.Observable;
|
|
2123
|
+
exports.isReference = utilities.isReference;
|
|
2124
|
+
exports.makeReference = utilities.makeReference;
|
|
2125
|
+
exports.mergeOptions = utilities.mergeOptions;
|
|
2066
2126
|
exports.ApolloError = errors.ApolloError;
|
|
2067
2127
|
exports.isApolloError = errors.isApolloError;
|
|
2068
2128
|
exports.fromError = utils.fromError;
|
|
@@ -2077,8 +2137,6 @@ exports.gql = graphqlTag.gql;
|
|
|
2077
2137
|
exports.resetCaches = graphqlTag.resetCaches;
|
|
2078
2138
|
exports.ApolloClient = ApolloClient;
|
|
2079
2139
|
exports.ObservableQuery = ObservableQuery;
|
|
2080
|
-
exports.applyNextFetchPolicy = applyNextFetchPolicy;
|
|
2081
|
-
exports.mergeOptions = mergeOptions;
|
|
2082
2140
|
for (var k in core) {
|
|
2083
2141
|
if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = core[k];
|
|
2084
2142
|
}
|