@apollo/client 4.2.0-alpha.3 → 4.2.0-alpha.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/CHANGELOG.md +179 -0
- package/__cjs/cache/core/cache.cjs +1 -1
- package/__cjs/cache/inmemory/entityStore.cjs +3 -3
- package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/policies.cjs +4 -4
- package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
- package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
- package/__cjs/core/ApolloClient.cjs +43 -11
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +28 -1
- package/__cjs/core/ObservableQuery.cjs +7 -7
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +20 -1
- package/__cjs/core/QueryManager.cjs +12 -12
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/RefetchEventManager.cjs +134 -0
- package/__cjs/core/RefetchEventManager.cjs.map +1 -0
- package/__cjs/core/RefetchEventManager.d.cts +130 -0
- package/__cjs/core/index.cjs +7 -1
- package/__cjs/core/index.cjs.map +1 -1
- package/__cjs/core/index.d.cts +4 -1
- package/__cjs/core/refetchSources/onlineSource.cjs +10 -0
- package/__cjs/core/refetchSources/onlineSource.cjs.map +1 -0
- package/__cjs/core/refetchSources/onlineSource.d.cts +3 -0
- package/__cjs/core/refetchSources/windowFocusSource.cjs +13 -0
- package/__cjs/core/refetchSources/windowFocusSource.cjs.map +1 -0
- package/__cjs/core/refetchSources/windowFocusSource.d.cts +3 -0
- package/__cjs/core/types.d.cts +20 -0
- package/__cjs/invariantErrorCodes.cjs +69 -44
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +20 -1
- package/__cjs/react/hooks/useLazyQuery.cjs +1 -0
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +20 -1
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +20 -1
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +20 -1
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +20 -1
- package/__cjs/react/internal/cache/QueryReference.cjs +1 -0
- package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/QueryReference.d.cts +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.d.cts +20 -1
- package/__cjs/react/types/types.documentation.d.cts +19 -0
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.js +1 -1
- package/cache/inmemory/entityStore.js +3 -3
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.js +4 -4
- package/cache/inmemory/readFromStore.js +2 -2
- package/cache/inmemory/writeToStore.js +4 -4
- package/core/ApolloClient.d.ts +28 -1
- package/core/ApolloClient.js +44 -12
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +20 -1
- package/core/ObservableQuery.js +7 -7
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.js +12 -12
- package/core/QueryManager.js.map +1 -1
- package/core/RefetchEventManager.d.ts +130 -0
- package/core/RefetchEventManager.js +126 -0
- package/core/RefetchEventManager.js.map +1 -0
- package/core/index.d.ts +4 -1
- package/core/index.js +3 -0
- package/core/index.js.map +1 -1
- package/core/refetchSources/onlineSource.d.ts +3 -0
- package/core/refetchSources/onlineSource.js +6 -0
- package/core/refetchSources/onlineSource.js.map +1 -0
- package/core/refetchSources/windowFocusSource.d.ts +3 -0
- package/core/refetchSources/windowFocusSource.js +9 -0
- package/core/refetchSources/windowFocusSource.js.map +1 -0
- package/core/types.d.ts +20 -0
- package/core/types.js.map +1 -1
- package/invariantErrorCodes.js +69 -44
- package/package.json +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +20 -1
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +20 -1
- package/react/hooks/useLazyQuery.js +1 -0
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +20 -1
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useQuery.d.ts +20 -1
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +20 -1
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +20 -1
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +20 -1
- package/react/hooks-compiled/useLazyQuery.js +1 -0
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +20 -1
- package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +20 -1
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useSuspenseQuery.d.ts +20 -1
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/internal/cache/QueryReference.d.ts +1 -1
- package/react/internal/cache/QueryReference.js +1 -0
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/query-preloader/createQueryPreloader.d.ts +20 -1
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/types/types.documentation.d.ts +19 -0
- package/react/types/types.documentation.js.map +1 -1
- package/version.js +1 -1
|
@@ -41,7 +41,7 @@ function keyFieldsFnFromSpecifier(specifier) {
|
|
|
41
41
|
// context.readField for this extraction.
|
|
42
42
|
extracted = extractKeyPath(object, schemaKeyPath, extractKey);
|
|
43
43
|
}
|
|
44
|
-
(0, invariant_1.invariant)(extracted !== void 0,
|
|
44
|
+
(0, invariant_1.invariant)(extracted !== void 0, 107, schemaKeyPath.join("."), object);
|
|
45
45
|
return extracted;
|
|
46
46
|
}));
|
|
47
47
|
return `${context.typename}:${JSON.stringify(keyObject)}`;
|
|
@@ -229,7 +229,7 @@ class Policies {
|
|
|
229
229
|
const rootId = "ROOT_" + which.toUpperCase();
|
|
230
230
|
const old = this.rootTypenamesById[rootId];
|
|
231
231
|
if (typename !== old) {
|
|
232
|
-
(0, invariant_1.invariant)(!old || old === which,
|
|
232
|
+
(0, invariant_1.invariant)(!old || old === which, 108, which);
|
|
233
233
|
// First, delete any old __typename associated with this rootId from
|
|
234
234
|
// rootIdsByTypename.
|
|
235
235
|
if (old)
|
|
@@ -372,7 +372,7 @@ class Policies {
|
|
|
372
372
|
if (supertypeSet.has(supertype)) {
|
|
373
373
|
if (!typenameSupertypeSet.has(supertype)) {
|
|
374
374
|
if (checkingFuzzySubtypes) {
|
|
375
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
375
|
+
__DEV__ && invariant_1.invariant.warn(109, typename, supertype);
|
|
376
376
|
}
|
|
377
377
|
// Record positive results for faster future lookup.
|
|
378
378
|
// Unfortunately, we cannot safely cache negative results,
|
|
@@ -625,7 +625,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
|
|
|
625
625
|
}
|
|
626
626
|
}
|
|
627
627
|
if (environment_1.__DEV__ && options.from === void 0) {
|
|
628
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
628
|
+
__DEV__ && invariant_1.invariant.warn(110, (0, internal_2.stringifyForDisplay)(Array.from(readFieldArgs)));
|
|
629
629
|
}
|
|
630
630
|
if (void 0 === options.variables) {
|
|
631
631
|
options.variables = variables;
|
|
@@ -635,7 +635,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
|
|
|
635
635
|
function makeMergeObjectsFunction(store) {
|
|
636
636
|
return function mergeObjects(existing, incoming) {
|
|
637
637
|
if ((0, internal_2.isArray)(existing) || (0, internal_2.isArray)(incoming)) {
|
|
638
|
-
throw (0, invariant_1.newInvariantError)(
|
|
638
|
+
throw (0, invariant_1.newInvariantError)(111);
|
|
639
639
|
}
|
|
640
640
|
// These dynamic checks are necessary because the parameters of a
|
|
641
641
|
// custom merge function can easily have the any type, so the type
|
|
@@ -197,7 +197,7 @@ class StoreReader {
|
|
|
197
197
|
else {
|
|
198
198
|
const fragment = (0, internal_1.getFragmentFromSelection)(selection, context.lookupFragment);
|
|
199
199
|
if (!fragment && selection.kind === graphql_1.Kind.FRAGMENT_SPREAD) {
|
|
200
|
-
throw (0, invariant_1.newInvariantError)(
|
|
200
|
+
throw (0, invariant_1.newInvariantError)(112, selection.name.value);
|
|
201
201
|
}
|
|
202
202
|
if (fragment && policies.fragmentMatches(fragment, typename)) {
|
|
203
203
|
fragment.selectionSet.selections.forEach(workSet.add, workSet);
|
|
@@ -281,7 +281,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
|
|
|
281
281
|
if ((0, internal_1.isNonNullObject)(value)) {
|
|
282
282
|
(0, invariant_1.invariant)(
|
|
283
283
|
!(0, utilities_1.isReference)(value),
|
|
284
|
-
|
|
284
|
+
113,
|
|
285
285
|
(0, helpers_js_1.getTypenameFromStoreObject)(store, value),
|
|
286
286
|
field.name.value
|
|
287
287
|
);
|
|
@@ -75,7 +75,7 @@ class StoreWriter {
|
|
|
75
75
|
path: [],
|
|
76
76
|
});
|
|
77
77
|
if (!(0, utilities_1.isReference)(ref)) {
|
|
78
|
-
throw (0, invariant_1.newInvariantError)(
|
|
78
|
+
throw (0, invariant_1.newInvariantError)(114, result);
|
|
79
79
|
}
|
|
80
80
|
// So far, the store has not been modified, so now it's time to process
|
|
81
81
|
// context.incomingById and merge those incoming fields into context.store.
|
|
@@ -237,7 +237,7 @@ class StoreWriter {
|
|
|
237
237
|
// provide a default value, so its absence from the written data should
|
|
238
238
|
// not be cause for alarm.
|
|
239
239
|
!policies.getReadFunction(typename, field.name.value)) {
|
|
240
|
-
invariant_1.invariant.error(
|
|
240
|
+
invariant_1.invariant.error(115, (0, internal_1.resultKeyNameFromField)(field), result);
|
|
241
241
|
}
|
|
242
242
|
});
|
|
243
243
|
// Identify the result object, even if dataId was already provided,
|
|
@@ -385,7 +385,7 @@ class StoreWriter {
|
|
|
385
385
|
else {
|
|
386
386
|
const fragment = (0, internal_1.getFragmentFromSelection)(selection, context.lookupFragment);
|
|
387
387
|
if (!fragment && selection.kind === graphql_1.Kind.FRAGMENT_SPREAD) {
|
|
388
|
-
throw (0, invariant_1.newInvariantError)(
|
|
388
|
+
throw (0, invariant_1.newInvariantError)(116, selection.name.value);
|
|
389
389
|
}
|
|
390
390
|
if (fragment &&
|
|
391
391
|
policies.fragmentMatches(fragment, typename, result, context.variables)) {
|
|
@@ -558,7 +558,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
558
558
|
}
|
|
559
559
|
});
|
|
560
560
|
}
|
|
561
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
561
|
+
__DEV__ && invariant_1.invariant.warn(117, fieldName, parentType, childTypenames.length ?
|
|
562
562
|
"either ensure all objects of type " +
|
|
563
563
|
childTypenames.join(" and ") +
|
|
564
564
|
" have an ID or a custom merge function, or "
|
|
@@ -46,6 +46,7 @@ class ApolloClient {
|
|
|
46
46
|
queryDeduplication;
|
|
47
47
|
defaultOptions;
|
|
48
48
|
devtoolsConfig;
|
|
49
|
+
refetchEventManager;
|
|
49
50
|
queryManager;
|
|
50
51
|
devToolsHookCb;
|
|
51
52
|
resetStoreCallbacks = [];
|
|
@@ -80,7 +81,7 @@ class ApolloClient {
|
|
|
80
81
|
(0, invariant_1.invariant)(options.cache, 68);
|
|
81
82
|
(0, invariant_1.invariant)(options.link, 69);
|
|
82
83
|
}
|
|
83
|
-
const { cache, documentTransform, ssrMode = false, ssrForceFetchDelay = 0, queryDeduplication = true, defaultOptions, defaultContext, assumeImmutableResults = cache.assumeImmutableResults, localState, devtools, dataMasking, link, incrementalHandler = new incremental_1.NotImplementedHandler(), experiments = [], } = options;
|
|
84
|
+
const { cache, documentTransform, ssrMode = false, ssrForceFetchDelay = 0, queryDeduplication = true, defaultOptions, defaultContext, assumeImmutableResults = cache.assumeImmutableResults, localState, devtools, dataMasking, link, incrementalHandler = new incremental_1.NotImplementedHandler(), experiments = [], refetchEventManager, } = options;
|
|
84
85
|
this.link = link;
|
|
85
86
|
this.cache = cache;
|
|
86
87
|
this.queryDeduplication = queryDeduplication;
|
|
@@ -130,6 +131,8 @@ class ApolloClient {
|
|
|
130
131
|
if (this.devtoolsConfig.enabled)
|
|
131
132
|
this.connectToDevTools();
|
|
132
133
|
experiments.forEach((experiment) => experiment.call(this, options));
|
|
134
|
+
this.refetchEventManager = refetchEventManager;
|
|
135
|
+
this.refetchEventManager?.connect(this);
|
|
133
136
|
}
|
|
134
137
|
connectToDevTools() {
|
|
135
138
|
if (typeof window === "undefined") {
|
|
@@ -200,9 +203,11 @@ class ApolloClient {
|
|
|
200
203
|
* - Unsubscribes all active `ObservableQuery` instances by emitting a `completed` event
|
|
201
204
|
* - Rejects all currently running queries with "QueryManager stopped while query was in flight"
|
|
202
205
|
* - Removes all queryRefs from the suspense cache
|
|
206
|
+
* - Disconnects the `RefetchEventManager` if configured.
|
|
203
207
|
*/
|
|
204
208
|
stop() {
|
|
205
209
|
this.queryManager.stop();
|
|
210
|
+
this.refetchEventManager?.disconnect(this);
|
|
206
211
|
}
|
|
207
212
|
/**
|
|
208
213
|
* This watches the cache store of the query according to the options specified and
|
|
@@ -225,7 +230,34 @@ class ApolloClient {
|
|
|
225
230
|
*/
|
|
226
231
|
watchQuery(options) {
|
|
227
232
|
if (this.defaultOptions.watchQuery) {
|
|
233
|
+
const defaultRefetchOn = this.defaultOptions.watchQuery.refetchOn;
|
|
234
|
+
const mergedRefetchOn = (options.refetchOn &&
|
|
235
|
+
typeof options.refetchOn === "object" &&
|
|
236
|
+
defaultRefetchOn &&
|
|
237
|
+
typeof defaultRefetchOn === "object") ?
|
|
238
|
+
{ ...defaultRefetchOn, ...options.refetchOn }
|
|
239
|
+
: undefined;
|
|
228
240
|
options = (0, internal_1.mergeOptions)(this.defaultOptions.watchQuery, options);
|
|
241
|
+
if (mergedRefetchOn) {
|
|
242
|
+
options.refetchOn = mergedRefetchOn;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (environment_1.__DEV__) {
|
|
246
|
+
const { refetchOn, query } = options;
|
|
247
|
+
const { refetchEventManager } = this;
|
|
248
|
+
if (refetchOn) {
|
|
249
|
+
const operationName = (0, internal_1.getOperationName)(query, "(anonymous)");
|
|
250
|
+
if (!refetchEventManager) {
|
|
251
|
+
__DEV__ && invariant_1.invariant.warn(70, operationName);
|
|
252
|
+
}
|
|
253
|
+
else if (typeof refetchOn === "object") {
|
|
254
|
+
Object.keys(refetchOn).forEach((source) => {
|
|
255
|
+
if (!refetchEventManager.hasSource(source)) {
|
|
256
|
+
__DEV__ && invariant_1.invariant.warn(71, source, operationName);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
229
261
|
}
|
|
230
262
|
return this.queryManager.watchQuery(options);
|
|
231
263
|
}
|
|
@@ -243,13 +275,13 @@ class ApolloClient {
|
|
|
243
275
|
options = (0, internal_1.mergeOptions)(this.defaultOptions.query, options);
|
|
244
276
|
}
|
|
245
277
|
if (environment_1.__DEV__) {
|
|
246
|
-
(0, invariant_1.invariant)(options.fetchPolicy !== "cache-and-network",
|
|
247
|
-
(0, invariant_1.invariant)(options.fetchPolicy !== "standby",
|
|
248
|
-
(0, invariant_1.invariant)(options.query,
|
|
249
|
-
(0, invariant_1.invariant)(options.query.kind === "Document",
|
|
250
|
-
(0, invariant_1.invariant)(!options.returnPartialData,
|
|
251
|
-
(0, invariant_1.invariant)(!options.pollInterval,
|
|
252
|
-
(0, invariant_1.invariant)(!options.notifyOnNetworkStatusChange,
|
|
278
|
+
(0, invariant_1.invariant)(options.fetchPolicy !== "cache-and-network", 72);
|
|
279
|
+
(0, invariant_1.invariant)(options.fetchPolicy !== "standby", 73);
|
|
280
|
+
(0, invariant_1.invariant)(options.query, 74);
|
|
281
|
+
(0, invariant_1.invariant)(options.query.kind === "Document", 75);
|
|
282
|
+
(0, invariant_1.invariant)(!options.returnPartialData, 76);
|
|
283
|
+
(0, invariant_1.invariant)(!options.pollInterval, 77);
|
|
284
|
+
(0, invariant_1.invariant)(!options.notifyOnNetworkStatusChange, 78);
|
|
253
285
|
}
|
|
254
286
|
return this.queryManager.query(options);
|
|
255
287
|
};
|
|
@@ -267,9 +299,9 @@ class ApolloClient {
|
|
|
267
299
|
errorPolicy: "none",
|
|
268
300
|
}, this.defaultOptions.mutate), options);
|
|
269
301
|
if (environment_1.__DEV__) {
|
|
270
|
-
(0, invariant_1.invariant)(optionsWithDefaults.mutation,
|
|
302
|
+
(0, invariant_1.invariant)(optionsWithDefaults.mutation, 79);
|
|
271
303
|
(0, invariant_1.invariant)(optionsWithDefaults.fetchPolicy === "network-only" ||
|
|
272
|
-
optionsWithDefaults.fetchPolicy === "no-cache",
|
|
304
|
+
optionsWithDefaults.fetchPolicy === "no-cache", 80);
|
|
273
305
|
}
|
|
274
306
|
(0, internal_1.checkDocument)(optionsWithDefaults.mutation, graphql_1.OperationTypeNode.MUTATION);
|
|
275
307
|
return this.queryManager.mutate(optionsWithDefaults);
|
|
@@ -475,7 +507,7 @@ class ApolloClient {
|
|
|
475
507
|
// result.queries and result.results instead, you shouldn't have to worry
|
|
476
508
|
// about preventing uncaught rejections for the Promise.all result.
|
|
477
509
|
result.catch((error) => {
|
|
478
|
-
__DEV__ && invariant_1.invariant.debug(
|
|
510
|
+
__DEV__ && invariant_1.invariant.debug(81, error);
|
|
479
511
|
});
|
|
480
512
|
return result;
|
|
481
513
|
}
|