@apollo/client 3.5.10 → 3.6.4
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/apollo-client.cjs +509 -341
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs.native.js +2289 -0
- 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 +97 -45
- 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 +29 -23
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +138 -85
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +2141 -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 +47 -37
- package/link/batch/batch.cjs.map +1 -1
- package/link/batch/batch.cjs.native.js +161 -0
- package/link/batch/batching.d.ts +2 -6
- package/link/batch/batching.d.ts.map +1 -1
- package/link/batch/batching.js +47 -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 +28 -26
- 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 +351 -247
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +604 -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 +22 -21
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts.map +1 -1
- package/react/hooks/useMutation.js +6 -3
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +36 -2
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +238 -204
- 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/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.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 +29 -12
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +1284 -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.4';
|
|
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,26 @@ 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 (typeof options.nextFetchPolicy === "function") {
|
|
345
|
+
options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
|
|
346
|
+
reason: reason,
|
|
347
|
+
options: options,
|
|
348
|
+
observable: this,
|
|
349
|
+
initialFetchPolicy: initialFetchPolicy,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
else if (reason === "variables-changed") {
|
|
353
|
+
options.fetchPolicy = initialFetchPolicy;
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
options.fetchPolicy = options.nextFetchPolicy;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return options.fetchPolicy;
|
|
360
|
+
};
|
|
320
361
|
ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
|
|
321
362
|
this.queryManager.setObservableQuery(this);
|
|
322
363
|
return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
|
|
@@ -379,16 +420,18 @@ var ObservableQuery = (function (_super) {
|
|
|
379
420
|
newNetworkStatus === exports.NetworkStatus.fetchMore ||
|
|
380
421
|
newNetworkStatus === exports.NetworkStatus.poll;
|
|
381
422
|
var oldVariables = this.options.variables;
|
|
423
|
+
var oldFetchPolicy = this.options.fetchPolicy;
|
|
424
|
+
var mergedOptions = utilities.mergeOptions(this.options, newOptions || {});
|
|
382
425
|
var options = useDisposableConcast
|
|
383
|
-
?
|
|
384
|
-
: assign(this.options,
|
|
426
|
+
? mergedOptions
|
|
427
|
+
: assign(this.options, mergedOptions);
|
|
385
428
|
if (!useDisposableConcast) {
|
|
386
429
|
this.updatePolling();
|
|
387
430
|
if (newOptions &&
|
|
388
431
|
newOptions.variables &&
|
|
389
|
-
!newOptions.
|
|
390
|
-
!
|
|
391
|
-
|
|
432
|
+
!equality.equal(newOptions.variables, oldVariables) &&
|
|
433
|
+
(!newOptions.fetchPolicy || newOptions.fetchPolicy === oldFetchPolicy)) {
|
|
434
|
+
this.applyNextFetchPolicy("variables-changed", options);
|
|
392
435
|
if (newNetworkStatus === void 0) {
|
|
393
436
|
newNetworkStatus = exports.NetworkStatus.setVariables;
|
|
394
437
|
}
|
|
@@ -452,6 +495,23 @@ var ObservableQuery = (function (_super) {
|
|
|
452
495
|
return ObservableQuery;
|
|
453
496
|
}(utilities.Observable));
|
|
454
497
|
utilities.fixObservableSubclass(ObservableQuery);
|
|
498
|
+
function reobserveCacheFirst(obsQuery) {
|
|
499
|
+
var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
|
|
500
|
+
if (fetchPolicy === "cache-and-network" ||
|
|
501
|
+
fetchPolicy === "network-only") {
|
|
502
|
+
return obsQuery.reobserve({
|
|
503
|
+
fetchPolicy: "cache-first",
|
|
504
|
+
nextFetchPolicy: function () {
|
|
505
|
+
this.nextFetchPolicy = nextFetchPolicy;
|
|
506
|
+
if (typeof nextFetchPolicy === "function") {
|
|
507
|
+
return nextFetchPolicy.apply(this, arguments);
|
|
508
|
+
}
|
|
509
|
+
return fetchPolicy;
|
|
510
|
+
},
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
return obsQuery.reobserve();
|
|
514
|
+
}
|
|
455
515
|
function defaultSubscriptionObserverErrorCallback(error) {
|
|
456
516
|
__DEV__ && globals.invariant.error('Unhandled error', error.message, error.stack);
|
|
457
517
|
}
|
|
@@ -460,14 +520,6 @@ function logMissingFieldErrors(missing) {
|
|
|
460
520
|
__DEV__ && globals.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
|
|
461
521
|
}
|
|
462
522
|
}
|
|
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
523
|
|
|
472
524
|
var LocalState = (function () {
|
|
473
525
|
function LocalState(_a) {
|
|
@@ -850,11 +902,12 @@ var QueryInfo = (function () {
|
|
|
850
902
|
if (oq) {
|
|
851
903
|
oq["queryInfo"] = this;
|
|
852
904
|
this.listeners.add(this.oqListener = function () {
|
|
853
|
-
|
|
905
|
+
var diff = _this.getDiff();
|
|
906
|
+
if (diff.fromOptimisticTransaction) {
|
|
854
907
|
oq["observe"]();
|
|
855
908
|
}
|
|
856
909
|
else {
|
|
857
|
-
oq
|
|
910
|
+
reobserveCacheFirst(oq);
|
|
858
911
|
}
|
|
859
912
|
});
|
|
860
913
|
}
|
|
@@ -999,7 +1052,7 @@ function shouldWriteResult(result, errorPolicy) {
|
|
|
999
1052
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1000
1053
|
var QueryManager = (function () {
|
|
1001
1054
|
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;
|
|
1055
|
+
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
1056
|
this.clientAwareness = {};
|
|
1004
1057
|
this.queries = new Map();
|
|
1005
1058
|
this.fetchCancelFns = new Map();
|
|
@@ -1010,6 +1063,7 @@ var QueryManager = (function () {
|
|
|
1010
1063
|
this.inFlightLinkObservables = new Map();
|
|
1011
1064
|
this.cache = cache;
|
|
1012
1065
|
this.link = link;
|
|
1066
|
+
this.defaultOptions = defaultOptions || Object.create(null);
|
|
1013
1067
|
this.queryDeduplication = queryDeduplication;
|
|
1014
1068
|
this.clientAwareness = clientAwareness;
|
|
1015
1069
|
this.localState = localState || new LocalState({ cache: cache });
|
|
@@ -1031,11 +1085,12 @@ var QueryManager = (function () {
|
|
|
1031
1085
|
this.fetchCancelFns.clear();
|
|
1032
1086
|
};
|
|
1033
1087
|
QueryManager.prototype.mutate = function (_a) {
|
|
1034
|
-
var
|
|
1088
|
+
var _b, _c;
|
|
1089
|
+
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
1090
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1036
1091
|
var mutationId, mutationStoreValue, self;
|
|
1037
|
-
return tslib.__generator(this, function (
|
|
1038
|
-
switch (
|
|
1092
|
+
return tslib.__generator(this, function (_h) {
|
|
1093
|
+
switch (_h.label) {
|
|
1039
1094
|
case 0:
|
|
1040
1095
|
__DEV__ ? globals.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : globals.invariant(mutation, 12);
|
|
1041
1096
|
__DEV__ ? globals.invariant(fetchPolicy === 'network-only' ||
|
|
@@ -1047,8 +1102,8 @@ var QueryManager = (function () {
|
|
|
1047
1102
|
if (!this.transform(mutation).hasClientExports) return [3, 2];
|
|
1048
1103
|
return [4, this.localState.addExportedVariables(mutation, variables, context)];
|
|
1049
1104
|
case 1:
|
|
1050
|
-
variables = (
|
|
1051
|
-
|
|
1105
|
+
variables = (_h.sent());
|
|
1106
|
+
_h.label = 2;
|
|
1052
1107
|
case 2:
|
|
1053
1108
|
mutationStoreValue = this.mutationStore &&
|
|
1054
1109
|
(this.mutationStore[mutationId] = {
|
|
@@ -1315,9 +1370,9 @@ var QueryManager = (function () {
|
|
|
1315
1370
|
});
|
|
1316
1371
|
this.queries.set(observable.queryId, queryInfo);
|
|
1317
1372
|
queryInfo.init({
|
|
1318
|
-
document:
|
|
1373
|
+
document: observable.query,
|
|
1319
1374
|
observableQuery: observable,
|
|
1320
|
-
variables:
|
|
1375
|
+
variables: observable.variables,
|
|
1321
1376
|
});
|
|
1322
1377
|
return observable;
|
|
1323
1378
|
};
|
|
@@ -1501,8 +1556,10 @@ var QueryManager = (function () {
|
|
|
1501
1556
|
};
|
|
1502
1557
|
QueryManager.prototype.removeQuery = function (queryId) {
|
|
1503
1558
|
this.fetchCancelFns.delete(queryId);
|
|
1504
|
-
this.
|
|
1505
|
-
|
|
1559
|
+
if (this.queries.has(queryId)) {
|
|
1560
|
+
this.getQuery(queryId).stop();
|
|
1561
|
+
this.queries.delete(queryId);
|
|
1562
|
+
}
|
|
1506
1563
|
};
|
|
1507
1564
|
QueryManager.prototype.broadcastQueries = function () {
|
|
1508
1565
|
if (this.onBroadcast)
|
|
@@ -1586,10 +1643,11 @@ var QueryManager = (function () {
|
|
|
1586
1643
|
var aqr = {
|
|
1587
1644
|
data: result.data,
|
|
1588
1645
|
loading: false,
|
|
1589
|
-
networkStatus:
|
|
1646
|
+
networkStatus: exports.NetworkStatus.ready,
|
|
1590
1647
|
};
|
|
1591
1648
|
if (hasErrors && options.errorPolicy !== "ignore") {
|
|
1592
1649
|
aqr.errors = result.errors;
|
|
1650
|
+
aqr.networkStatus = exports.NetworkStatus.error;
|
|
1593
1651
|
}
|
|
1594
1652
|
return aqr;
|
|
1595
1653
|
}, function (networkError) {
|
|
@@ -1608,7 +1666,8 @@ var QueryManager = (function () {
|
|
|
1608
1666
|
var query = this.transform(options.query).document;
|
|
1609
1667
|
var variables = this.getVariables(query, options.variables);
|
|
1610
1668
|
var queryInfo = this.getQuery(queryId);
|
|
1611
|
-
var
|
|
1669
|
+
var defaults = this.defaultOptions.watchQuery;
|
|
1670
|
+
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
1671
|
var normalized = Object.assign({}, options, {
|
|
1613
1672
|
query: query,
|
|
1614
1673
|
variables: variables,
|
|
@@ -1630,7 +1689,9 @@ var QueryManager = (function () {
|
|
|
1630
1689
|
: fromVariables(normalized.variables));
|
|
1631
1690
|
concast.cleanup(function () {
|
|
1632
1691
|
_this.fetchCancelFns.delete(queryId);
|
|
1633
|
-
|
|
1692
|
+
if (queryInfo.observableQuery) {
|
|
1693
|
+
queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
|
|
1694
|
+
}
|
|
1634
1695
|
});
|
|
1635
1696
|
return concast;
|
|
1636
1697
|
};
|
|
@@ -1707,7 +1768,7 @@ var QueryManager = (function () {
|
|
|
1707
1768
|
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
1769
|
var oldNetworkStatus = queryInfo.networkStatus;
|
|
1709
1770
|
queryInfo.init({
|
|
1710
|
-
document: query,
|
|
1771
|
+
document: this.transform(query).document,
|
|
1711
1772
|
variables: variables,
|
|
1712
1773
|
networkStatus: networkStatus,
|
|
1713
1774
|
});
|
|
@@ -1736,14 +1797,12 @@ var QueryManager = (function () {
|
|
|
1736
1797
|
(networkStatus === exports.NetworkStatus.refetch &&
|
|
1737
1798
|
refetchWritePolicy !== "merge") ? 1
|
|
1738
1799
|
: 2;
|
|
1739
|
-
var resultsFromLink = function () {
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
});
|
|
1746
|
-
};
|
|
1800
|
+
var resultsFromLink = function () { return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
|
|
1801
|
+
variables: variables,
|
|
1802
|
+
context: context,
|
|
1803
|
+
fetchPolicy: fetchPolicy,
|
|
1804
|
+
errorPolicy: errorPolicy,
|
|
1805
|
+
}); };
|
|
1747
1806
|
var shouldNotify = notifyOnNetworkStatusChange &&
|
|
1748
1807
|
typeof oldNetworkStatus === "number" &&
|
|
1749
1808
|
oldNetworkStatus !== networkStatus &&
|
|
@@ -1818,15 +1877,9 @@ var QueryManager = (function () {
|
|
|
1818
1877
|
}());
|
|
1819
1878
|
|
|
1820
1879
|
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
1880
|
var ApolloClient = (function () {
|
|
1827
1881
|
function ApolloClient(options) {
|
|
1828
1882
|
var _this = this;
|
|
1829
|
-
this.defaultOptions = {};
|
|
1830
1883
|
this.resetStoreCallbacks = [];
|
|
1831
1884
|
this.clearStoreCallbacks = [];
|
|
1832
1885
|
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 +1900,7 @@ var ApolloClient = (function () {
|
|
|
1847
1900
|
this.cache = cache;
|
|
1848
1901
|
this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
|
|
1849
1902
|
this.queryDeduplication = queryDeduplication;
|
|
1850
|
-
this.defaultOptions = defaultOptions ||
|
|
1903
|
+
this.defaultOptions = defaultOptions || Object.create(null);
|
|
1851
1904
|
this.typeDefs = typeDefs;
|
|
1852
1905
|
if (ssrForceFetchDelay) {
|
|
1853
1906
|
setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
|
|
@@ -1894,6 +1947,7 @@ var ApolloClient = (function () {
|
|
|
1894
1947
|
this.queryManager = new QueryManager({
|
|
1895
1948
|
cache: this.cache,
|
|
1896
1949
|
link: this.link,
|
|
1950
|
+
defaultOptions: this.defaultOptions,
|
|
1897
1951
|
queryDeduplication: queryDeduplication,
|
|
1898
1952
|
ssrMode: ssrMode,
|
|
1899
1953
|
clientAwareness: {
|
|
@@ -1921,7 +1975,7 @@ var ApolloClient = (function () {
|
|
|
1921
1975
|
};
|
|
1922
1976
|
ApolloClient.prototype.watchQuery = function (options) {
|
|
1923
1977
|
if (this.defaultOptions.watchQuery) {
|
|
1924
|
-
options = mergeOptions(this.defaultOptions.watchQuery, options);
|
|
1978
|
+
options = utilities.mergeOptions(this.defaultOptions.watchQuery, options);
|
|
1925
1979
|
}
|
|
1926
1980
|
if (this.disableNetworkFetches &&
|
|
1927
1981
|
(options.fetchPolicy === 'network-only' ||
|
|
@@ -1932,7 +1986,7 @@ var ApolloClient = (function () {
|
|
|
1932
1986
|
};
|
|
1933
1987
|
ApolloClient.prototype.query = function (options) {
|
|
1934
1988
|
if (this.defaultOptions.query) {
|
|
1935
|
-
options = mergeOptions(this.defaultOptions.query, options);
|
|
1989
|
+
options = utilities.mergeOptions(this.defaultOptions.query, options);
|
|
1936
1990
|
}
|
|
1937
1991
|
__DEV__ ? globals.invariant(options.fetchPolicy !== 'cache-and-network', 'The cache-and-network fetchPolicy does not work with client.query, because ' +
|
|
1938
1992
|
'client.query can only return a single result. Please use client.watchQuery ' +
|
|
@@ -1945,7 +1999,7 @@ var ApolloClient = (function () {
|
|
|
1945
1999
|
};
|
|
1946
2000
|
ApolloClient.prototype.mutate = function (options) {
|
|
1947
2001
|
if (this.defaultOptions.mutate) {
|
|
1948
|
-
options = mergeOptions(this.defaultOptions.mutate, options);
|
|
2002
|
+
options = utilities.mergeOptions(this.defaultOptions.mutate, options);
|
|
1949
2003
|
}
|
|
1950
2004
|
return this.queryManager.mutate(options);
|
|
1951
2005
|
};
|
|
@@ -2054,15 +2108,16 @@ var ApolloClient = (function () {
|
|
|
2054
2108
|
|
|
2055
2109
|
tsInvariant.setVerbosity(globals.DEV ? "log" : "silent");
|
|
2056
2110
|
|
|
2057
|
-
exports.Observable = utilities.Observable;
|
|
2058
|
-
exports.isReference = utilities.isReference;
|
|
2059
|
-
exports.makeReference = utilities.makeReference;
|
|
2060
2111
|
exports.ApolloCache = cache.ApolloCache;
|
|
2061
2112
|
exports.Cache = cache.Cache;
|
|
2062
2113
|
exports.InMemoryCache = cache.InMemoryCache;
|
|
2063
2114
|
exports.MissingFieldError = cache.MissingFieldError;
|
|
2064
2115
|
exports.defaultDataIdFromObject = cache.defaultDataIdFromObject;
|
|
2065
2116
|
exports.makeVar = cache.makeVar;
|
|
2117
|
+
exports.Observable = utilities.Observable;
|
|
2118
|
+
exports.isReference = utilities.isReference;
|
|
2119
|
+
exports.makeReference = utilities.makeReference;
|
|
2120
|
+
exports.mergeOptions = utilities.mergeOptions;
|
|
2066
2121
|
exports.ApolloError = errors.ApolloError;
|
|
2067
2122
|
exports.isApolloError = errors.isApolloError;
|
|
2068
2123
|
exports.fromError = utils.fromError;
|
|
@@ -2077,8 +2132,6 @@ exports.gql = graphqlTag.gql;
|
|
|
2077
2132
|
exports.resetCaches = graphqlTag.resetCaches;
|
|
2078
2133
|
exports.ApolloClient = ApolloClient;
|
|
2079
2134
|
exports.ObservableQuery = ObservableQuery;
|
|
2080
|
-
exports.applyNextFetchPolicy = applyNextFetchPolicy;
|
|
2081
|
-
exports.mergeOptions = mergeOptions;
|
|
2082
2135
|
for (var k in core) {
|
|
2083
2136
|
if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = core[k];
|
|
2084
2137
|
}
|