@apollo/client 4.3.3 → 4.3.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 +20 -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/inMemoryCache.cjs +15 -5
- 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 +1 -1
- package/__cjs/cache/inmemory/policies.cjs +5 -5
- 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 +29 -14
- 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 +13 -32
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryManager.cjs +12 -12
- 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/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/inMemoryCache.d.ts +3 -1
- package/cache/inmemory/inMemoryCache.js +15 -5
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.js +5 -5
- 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 +30 -15
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.js +14 -14
- package/core/ObservableQuery.js +8 -8
- package/core/QueryInfo.js +14 -33
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.js +12 -12
- 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/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,
|
|
@@ -329,7 +335,7 @@ class StoreWriter {
|
|
|
329
335
|
}
|
|
330
336
|
// Implements https://spec.graphql.org/draft/#sec-Field-Collection, but with
|
|
331
337
|
// some additions for tracking @client and @defer directives.
|
|
332
|
-
flattenFields(selectionSet, result, context, typename = getTypenameFromResult(result, selectionSet, context.fragmentMap)) {
|
|
338
|
+
flattenFields(selectionSet, result, context, path, typename = getTypenameFromResult(result, selectionSet, context.fragmentMap)) {
|
|
333
339
|
const fieldMap = new Map();
|
|
334
340
|
const { policies } = this.cache;
|
|
335
341
|
const limitingTrie = new trie_1.Trie(false); // No need for WeakMap, since limitingTrie does not escape.
|
|
@@ -364,10 +370,19 @@ class StoreWriter {
|
|
|
364
370
|
// @defer(if: false) does not make context.deferred false, but
|
|
365
371
|
// instead behaves as if there was no @defer directive.
|
|
366
372
|
if (!args || args.if !== false) {
|
|
367
|
-
|
|
373
|
+
// If we know (via context.isDeferPending) that this specific
|
|
374
|
+
// boundary has already been delivered, we don't need to mark
|
|
375
|
+
// it deferred, which allows fields under it to be validated
|
|
376
|
+
// normally instead of being silently exempted from the
|
|
377
|
+
// "Missing field" check below. When we can't determine
|
|
378
|
+
// whether the boundary is still pending (no callback, or the
|
|
379
|
+
// handler can't identify individual boundaries),
|
|
380
|
+
// conservatively assume it's still pending (`?? true`).
|
|
381
|
+
// `||=` (rather than `=`) preserves `deferred` if it was
|
|
382
|
+
// already true from an ancestor boundary.
|
|
383
|
+
deferred ||=
|
|
384
|
+
context.isDeferPending?.(path, args?.label) ?? true;
|
|
368
385
|
}
|
|
369
|
-
// TODO In the future, we may want to record args.label using
|
|
370
|
-
// context.deferred, if a label is specified.
|
|
371
386
|
}
|
|
372
387
|
});
|
|
373
388
|
}
|
|
@@ -385,7 +400,7 @@ class StoreWriter {
|
|
|
385
400
|
else {
|
|
386
401
|
const fragment = (0, internal_1.getFragmentFromSelection)(selection, context.lookupFragment);
|
|
387
402
|
if (!fragment && selection.kind === graphql_1.Kind.FRAGMENT_SPREAD) {
|
|
388
|
-
throw (0, invariant_1.newInvariantError)(
|
|
403
|
+
throw (0, invariant_1.newInvariantError)(125, selection.name.value);
|
|
389
404
|
}
|
|
390
405
|
if (fragment &&
|
|
391
406
|
policies.fragmentMatches(fragment, typename, result, context.variables)) {
|
|
@@ -558,7 +573,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
558
573
|
}
|
|
559
574
|
});
|
|
560
575
|
}
|
|
561
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
576
|
+
__DEV__ && invariant_1.invariant.warn(126, fieldName, parentType, childTypenames.length ?
|
|
562
577
|
"either ensure all objects of type " +
|
|
563
578
|
childTypenames.join(" and ") +
|
|
564
579
|
" have an ID or a custom merge function, or "
|