@apollo/client 4.3.3 → 4.3.5
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 +30 -0
- package/__cjs/cache/core/cache.cjs +1 -1
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +4 -1
- package/__cjs/cache/core/types/Cache.d.cts +5 -0
- package/__cjs/cache/inmemory/entityStore.cjs +4 -4
- package/__cjs/cache/inmemory/helpers.cjs +5 -0
- package/__cjs/cache/inmemory/helpers.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.cjs +17 -6
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.d.cts +3 -1
- package/__cjs/cache/inmemory/key-extractor.cjs +15 -3
- package/__cjs/cache/inmemory/key-extractor.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.cjs +21 -5
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.d.cts +2 -0
- package/__cjs/cache/inmemory/readFromStore.cjs +28 -10
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/types.d.cts +7 -2
- package/__cjs/cache/inmemory/writeToStore.cjs +32 -16
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/writeToStore.d.cts +5 -2
- package/__cjs/core/ApolloClient.cjs +14 -14
- package/__cjs/core/ObservableQuery.cjs +8 -8
- package/__cjs/core/QueryInfo.cjs +22 -33
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +1 -1
- package/__cjs/core/QueryManager.cjs +22 -15
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/RefetchEventManager.cjs +3 -3
- package/__cjs/incremental/handlers/defer20220824.cjs +15 -2
- package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
- package/__cjs/incremental/handlers/defer20220824.d.cts +5 -1
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs +58 -14
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
- package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +23 -12
- package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
- package/__cjs/incremental/types.d.cts +19 -1
- package/__cjs/invariantErrorCodes.cjs +64 -58
- package/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useFragment.d.cts +42 -43
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +0 -1
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.d.ts +4 -1
- package/cache/core/cache.js +1 -1
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +5 -0
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/inmemory/entityStore.js +4 -4
- package/cache/inmemory/helpers.js +5 -0
- package/cache/inmemory/helpers.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +3 -1
- package/cache/inmemory/inMemoryCache.js +17 -6
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +15 -3
- package/cache/inmemory/key-extractor.js.map +1 -1
- package/cache/inmemory/policies.d.ts +2 -0
- package/cache/inmemory/policies.js +22 -6
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.js +28 -10
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +7 -2
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.d.ts +5 -2
- package/cache/inmemory/writeToStore.js +33 -17
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.js +14 -14
- package/core/ObservableQuery.js +8 -8
- package/core/QueryInfo.d.ts +1 -1
- package/core/QueryInfo.js +23 -34
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.js +22 -15
- package/core/QueryManager.js.map +1 -1
- package/core/RefetchEventManager.js +3 -3
- package/incremental/handlers/defer20220824.d.ts +5 -1
- package/incremental/handlers/defer20220824.js +15 -2
- package/incremental/handlers/defer20220824.js.map +1 -1
- package/incremental/handlers/graphql17Alpha9.d.ts +23 -12
- package/incremental/handlers/graphql17Alpha9.js +58 -14
- package/incremental/handlers/graphql17Alpha9.js.map +1 -1
- package/incremental/handlers/notImplemented.js +1 -1
- package/incremental/types.d.ts +19 -1
- package/incremental/types.js.map +1 -1
- package/invariantErrorCodes.js +64 -58
- package/package.json +1 -1
- package/react/hooks/useFragment.d.ts +42 -43
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks-compiled/useFragment.d.ts +42 -43
- package/react/hooks-compiled/useFragment.js.map +1 -1
- package/utilities/internal/index.d.ts +0 -1
- package/utilities/internal/index.js.map +1 -1
- package/version.js +1 -1
- package/__cjs/utilities/internal/types/DeferInfo.cjs +0 -3
- package/__cjs/utilities/internal/types/DeferInfo.cjs.map +0 -1
- package/__cjs/utilities/internal/types/DeferInfo.d.cts +0 -10
- package/utilities/internal/types/DeferInfo.d.ts +0 -10
- package/utilities/internal/types/DeferInfo.js +0 -2
- package/utilities/internal/types/DeferInfo.js.map +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { DocumentNode, FieldNode } from "graphql";
|
|
2
2
|
import type { OperationVariables } from "@apollo/client";
|
|
3
|
+
import type { Incremental } from "@apollo/client/incremental";
|
|
3
4
|
import type { Reference, StoreObject, StoreValue } from "@apollo/client/utilities";
|
|
4
|
-
import type {
|
|
5
|
+
import type { ExtensionsWithStreamInfo, handleIncrementalSymbol, RemoveIndexSignature, StreamInfoTrie } from "@apollo/client/utilities/internal";
|
|
5
6
|
import type { ApolloCache, Transaction } from "../core/cache.cjs";
|
|
6
7
|
import type { AllFieldsModifier, CanReadFunction, Modifiers, ToReferenceFunction } from "../core/types/common.cjs";
|
|
7
8
|
import type { FieldValueGetter } from "./entityStore.cjs";
|
|
@@ -86,7 +87,10 @@ export type ReadQueryOptions = {
|
|
|
86
87
|
*/
|
|
87
88
|
export interface DiffIncrementalInfo {
|
|
88
89
|
streamInfo?: StreamInfoTrie;
|
|
89
|
-
|
|
90
|
+
isDeferPending?: (path: Incremental.Path, label: string | undefined) => boolean;
|
|
91
|
+
}
|
|
92
|
+
export interface WithHandleIncremental {
|
|
93
|
+
[handleIncrementalSymbol]?: DiffIncrementalInfo | undefined;
|
|
90
94
|
}
|
|
91
95
|
export type DiffQueryAgainstStoreOptions = ReadQueryOptions & {
|
|
92
96
|
returnPartialData?: boolean;
|
|
@@ -128,6 +132,7 @@ export interface ReadMergeModifyContext {
|
|
|
128
132
|
variables?: OperationVariables;
|
|
129
133
|
varString?: string;
|
|
130
134
|
extensions?: ExtensionsWithStreamInfo;
|
|
135
|
+
isDeferPending?: (path: Incremental.Path, label: string | undefined) => boolean;
|
|
131
136
|
}
|
|
132
137
|
type ListOf<T extends string> = `[${T}]`;
|
|
133
138
|
type NestedScalarName<T extends string> = T | ListOf<T> | ListOf<ListOf<T>> | ListOf<ListOf<ListOf<T>>> | ListOf<ListOf<ListOf<ListOf<T>>>>;
|
|
@@ -43,7 +43,7 @@ class StoreWriter {
|
|
|
43
43
|
this.reader = reader;
|
|
44
44
|
this.fragments = fragments;
|
|
45
45
|
}
|
|
46
|
-
writeToStore(store, { query, result, dataId, variables, overwrite, extensions, }) {
|
|
46
|
+
writeToStore(store, { query, result, dataId, variables, overwrite, extensions, [internal_1.handleIncrementalSymbol]: incrementalInfo, }) {
|
|
47
47
|
const operationDefinition = (0, internal_1.getOperationDefinition)(query);
|
|
48
48
|
const merger = (0, helpers_js_1.makeProcessedFieldsMerger)();
|
|
49
49
|
variables = {
|
|
@@ -65,6 +65,7 @@ class StoreWriter {
|
|
|
65
65
|
deferred: false,
|
|
66
66
|
flavors: new Map(),
|
|
67
67
|
extensions,
|
|
68
|
+
isDeferPending: incrementalInfo?.isDeferPending,
|
|
68
69
|
};
|
|
69
70
|
const ref = this.processSelectionSet({
|
|
70
71
|
result: result || {},
|
|
@@ -75,7 +76,7 @@ class StoreWriter {
|
|
|
75
76
|
path: [],
|
|
76
77
|
});
|
|
77
78
|
if (!(0, utilities_1.isReference)(ref)) {
|
|
78
|
-
throw (0, invariant_1.newInvariantError)(
|
|
79
|
+
throw (0, invariant_1.newInvariantError)(123, result);
|
|
79
80
|
}
|
|
80
81
|
// So far, the store has not been modified, so now it's time to process
|
|
81
82
|
// context.incomingById and merge those incoming fields into context.store.
|
|
@@ -173,10 +174,10 @@ class StoreWriter {
|
|
|
173
174
|
// This WriteContext will be the default context value for fields returned
|
|
174
175
|
// by the flattenFields method, but some fields may be assigned a modified
|
|
175
176
|
// context, depending on the presence of @client and other directives.
|
|
176
|
-
context, typename).forEach((context, field) => {
|
|
177
|
+
context, currentPath, typename).forEach((context, field) => {
|
|
177
178
|
const resultFieldKey = (0, internal_1.resultKeyNameFromField)(field);
|
|
178
179
|
const value = result[resultFieldKey];
|
|
179
|
-
const path = [...currentPath,
|
|
180
|
+
const path = [...currentPath, resultFieldKey];
|
|
180
181
|
fieldNodeSet.add(field);
|
|
181
182
|
if (value !== void 0) {
|
|
182
183
|
const storeFieldName = policies.getStoreFieldName({
|
|
@@ -187,10 +188,15 @@ class StoreWriter {
|
|
|
187
188
|
});
|
|
188
189
|
const childTree = getChildMergeTree(mergeTree, storeFieldName);
|
|
189
190
|
let incomingValue = this.processFieldValue(value, field,
|
|
190
|
-
// Reset context.clientOnly
|
|
191
|
-
//
|
|
191
|
+
// Reset context.clientOnly to its default value before processing
|
|
192
|
+
// nested selection sets, but inherit context.deferred: a resolved
|
|
193
|
+
// parent field must not erase the fact that an ancestor @defer
|
|
194
|
+
// boundary is still pending, or nested fields reached only through
|
|
195
|
+
// that ancestor will incorrectly be treated as complete and report
|
|
196
|
+
// spurious "Missing field" errors when their own boundary hasn't
|
|
197
|
+
// arrived yet.
|
|
192
198
|
field.selectionSet ?
|
|
193
|
-
getContextFlavor(context, false,
|
|
199
|
+
getContextFlavor(context, false, context.deferred)
|
|
194
200
|
: context, childTree, path);
|
|
195
201
|
// To determine if this field holds a child object with a merge function
|
|
196
202
|
// defined in its type policy (see PR #7070), we need to figure out the
|
|
@@ -237,7 +243,7 @@ class StoreWriter {
|
|
|
237
243
|
// provide a default value, so its absence from the written data should
|
|
238
244
|
// not be cause for alarm.
|
|
239
245
|
!policies.getReadFunction(typename, field.name.value)) {
|
|
240
|
-
invariant_1.invariant.error(
|
|
246
|
+
invariant_1.invariant.error(124, (0, internal_1.resultKeyNameFromField)(field), result);
|
|
241
247
|
}
|
|
242
248
|
});
|
|
243
249
|
// Identify the result object, even if dataId was already provided,
|
|
@@ -256,8 +262,9 @@ class StoreWriter {
|
|
|
256
262
|
// Write any key fields that were used during identification, even if
|
|
257
263
|
// they were not mentioned in the original query.
|
|
258
264
|
if (keyObject) {
|
|
259
|
-
//
|
|
260
|
-
|
|
265
|
+
// Values in incoming take precedence over keyObject, which may contain
|
|
266
|
+
// serialized values used to compute the ID.
|
|
267
|
+
incoming = context.merge(keyObject, incoming);
|
|
261
268
|
}
|
|
262
269
|
}
|
|
263
270
|
catch (e) {
|
|
@@ -329,7 +336,7 @@ class StoreWriter {
|
|
|
329
336
|
}
|
|
330
337
|
// Implements https://spec.graphql.org/draft/#sec-Field-Collection, but with
|
|
331
338
|
// some additions for tracking @client and @defer directives.
|
|
332
|
-
flattenFields(selectionSet, result, context, typename = getTypenameFromResult(result, selectionSet, context.fragmentMap)) {
|
|
339
|
+
flattenFields(selectionSet, result, context, path, typename = getTypenameFromResult(result, selectionSet, context.fragmentMap)) {
|
|
333
340
|
const fieldMap = new Map();
|
|
334
341
|
const { policies } = this.cache;
|
|
335
342
|
const limitingTrie = new trie_1.Trie(false); // No need for WeakMap, since limitingTrie does not escape.
|
|
@@ -364,10 +371,19 @@ class StoreWriter {
|
|
|
364
371
|
// @defer(if: false) does not make context.deferred false, but
|
|
365
372
|
// instead behaves as if there was no @defer directive.
|
|
366
373
|
if (!args || args.if !== false) {
|
|
367
|
-
|
|
374
|
+
// If we know (via context.isDeferPending) that this specific
|
|
375
|
+
// boundary has already been delivered, we don't need to mark
|
|
376
|
+
// it deferred, which allows fields under it to be validated
|
|
377
|
+
// normally instead of being silently exempted from the
|
|
378
|
+
// "Missing field" check below. When we can't determine
|
|
379
|
+
// whether the boundary is still pending (no callback, or the
|
|
380
|
+
// handler can't identify individual boundaries),
|
|
381
|
+
// conservatively assume it's still pending (`?? true`).
|
|
382
|
+
// `||=` (rather than `=`) preserves `deferred` if it was
|
|
383
|
+
// already true from an ancestor boundary.
|
|
384
|
+
deferred ||=
|
|
385
|
+
context.isDeferPending?.(path, args?.label) ?? true;
|
|
368
386
|
}
|
|
369
|
-
// TODO In the future, we may want to record args.label using
|
|
370
|
-
// context.deferred, if a label is specified.
|
|
371
387
|
}
|
|
372
388
|
});
|
|
373
389
|
}
|
|
@@ -385,7 +401,7 @@ class StoreWriter {
|
|
|
385
401
|
else {
|
|
386
402
|
const fragment = (0, internal_1.getFragmentFromSelection)(selection, context.lookupFragment);
|
|
387
403
|
if (!fragment && selection.kind === graphql_1.Kind.FRAGMENT_SPREAD) {
|
|
388
|
-
throw (0, invariant_1.newInvariantError)(
|
|
404
|
+
throw (0, invariant_1.newInvariantError)(125, selection.name.value);
|
|
389
405
|
}
|
|
390
406
|
if (fragment &&
|
|
391
407
|
policies.fragmentMatches(fragment, typename, result, context.variables)) {
|
|
@@ -558,7 +574,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
558
574
|
}
|
|
559
575
|
});
|
|
560
576
|
}
|
|
561
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
577
|
+
__DEV__ && invariant_1.invariant.warn(126, fieldName, parentType, childTypenames.length ?
|
|
562
578
|
"either ensure all objects of type " +
|
|
563
579
|
childTypenames.join(" and ") +
|
|
564
580
|
" have an ID or a custom merge function, or "
|