@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
|
@@ -19,6 +19,7 @@ export type KeyFieldsContext = {
|
|
|
19
19
|
selectionSet?: SelectionSetNode;
|
|
20
20
|
fragmentMap?: FragmentMap;
|
|
21
21
|
keyObject?: Record<string, any>;
|
|
22
|
+
serializeKeyField?: (typename: string, fieldName: string, value: unknown) => unknown;
|
|
22
23
|
};
|
|
23
24
|
export type KeyFieldsFunction = (object: Readonly<StoreObject>, context: KeyFieldsContext) => KeySpecifier | false | ReturnType<IdGetter>;
|
|
24
25
|
export type TypePolicy = {
|
|
@@ -118,6 +119,7 @@ export declare class Policies {
|
|
|
118
119
|
hasKeyArgs(typename: string | undefined, fieldName: string): boolean;
|
|
119
120
|
getStoreFieldName(fieldSpec: FieldSpecifier): string;
|
|
120
121
|
getScalarTypeForField(typename: string, fieldName: string): ScalarType | undefined;
|
|
122
|
+
private serializeScalarValue;
|
|
121
123
|
readField<V = StoreValue>(options: ReadFieldOptions, context: ReadMergeModifyContext): SafeReadonly<V> | undefined;
|
|
122
124
|
getReadFunction(typename: string | undefined, fieldName: string): FieldReadFunction | undefined;
|
|
123
125
|
getMergeFunction(parentTypename: string | undefined, fieldName: string, childTypename: string | undefined): FieldMergeFunction | undefined;
|
|
@@ -76,7 +76,7 @@ class StoreReader {
|
|
|
76
76
|
20000 /* defaultCacheSizes["inMemoryCache.prunePartialBoundaries"] */,
|
|
77
77
|
makeCacheKey: ({ boundaries, context, selectionSet }) => {
|
|
78
78
|
if ((0, entityStore_js_1.supportsResultCaching)(context.store)) {
|
|
79
|
-
return this.keyMaker.lookup(selectionSet, boundaries, context.streamInfo, context.
|
|
79
|
+
return this.keyMaker.lookup(selectionSet, boundaries, context.streamInfo, context.isDeferPending);
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
});
|
|
@@ -91,7 +91,7 @@ class StoreReader {
|
|
|
91
91
|
20000 /* defaultCacheSizes["inMemoryCache.prunePartialStreamArray"] */,
|
|
92
92
|
makeCacheKey: ({ field, context, boundaries }) => {
|
|
93
93
|
if ((0, entityStore_js_1.supportsResultCaching)(context.store)) {
|
|
94
|
-
return this.keyMaker.lookup(field, boundaries, context.streamInfo, context.
|
|
94
|
+
return this.keyMaker.lookup(field, boundaries, context.streamInfo, context.isDeferPending);
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
});
|
|
@@ -289,7 +289,7 @@ class StoreReader {
|
|
|
289
289
|
if (typename) {
|
|
290
290
|
const policy = policies["getFieldPolicy"](typename, fieldName);
|
|
291
291
|
if (policy?.scalar) {
|
|
292
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
292
|
+
__DEV__ && invariant_1.invariant.warn(120, `${typename}.${fieldName}`, policy.scalar);
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
}
|
|
@@ -326,7 +326,7 @@ class StoreReader {
|
|
|
326
326
|
else {
|
|
327
327
|
const fragment = (0, internal_1.getFragmentFromSelection)(selection, context.lookupFragment);
|
|
328
328
|
if (!fragment && selection.kind === graphql_1.Kind.FRAGMENT_SPREAD) {
|
|
329
|
-
throw (0, invariant_1.newInvariantError)(
|
|
329
|
+
throw (0, invariant_1.newInvariantError)(121, selection.name.value);
|
|
330
330
|
}
|
|
331
331
|
if (fragment && policies.fragmentMatches(fragment, typename)) {
|
|
332
332
|
const isDeferBoundary = (0, internal_1.isDeferredFragment)(selection, context.variables);
|
|
@@ -457,7 +457,10 @@ class StoreReader {
|
|
|
457
457
|
if (data == null || !boundaries) {
|
|
458
458
|
return { result: data, dataState: "complete" };
|
|
459
459
|
}
|
|
460
|
-
|
|
460
|
+
// `truncate` is only necessary for the Defer20220824 protocol. the
|
|
461
|
+
// `arrayMerge` option can be removed when we stop supporting the old
|
|
462
|
+
// protocol. See the comment below on array merging for more info.
|
|
463
|
+
const merger = new internal_1.DeepMerger({ arrayMerge: "truncate" });
|
|
461
464
|
let changed = false;
|
|
462
465
|
let dataState = "complete";
|
|
463
466
|
const result = {};
|
|
@@ -486,7 +489,22 @@ class StoreReader {
|
|
|
486
489
|
path: path.concat(resultName),
|
|
487
490
|
});
|
|
488
491
|
changed ||= pruned.result !== fieldValue;
|
|
489
|
-
result[resultName]
|
|
492
|
+
const previous = result[resultName];
|
|
493
|
+
let merged = merger.merge(previous, pruned.result);
|
|
494
|
+
// The Defer20220824 protocol allows more than one selection of a
|
|
495
|
+
// list field with `@stream` when the `@stream` arguments are the
|
|
496
|
+
// same. Each selection can prune the list to a different length, so
|
|
497
|
+
// we keep the shortest length. The `truncate` option of the merger
|
|
498
|
+
// handles a shorter later visit, and this check handles a shorter
|
|
499
|
+
// earlier visit. GraphQL 17 rejects any overlapping `@stream` field,
|
|
500
|
+
// so all visits give the same length. When we no longer support the
|
|
501
|
+
// older protocol, we can remove this check and the `truncate` option,
|
|
502
|
+
// and simplify to:
|
|
503
|
+
// result[resultName] = merger.merge(result[resultName], pruned.result);
|
|
504
|
+
if (previous && previous.length < merged.length) {
|
|
505
|
+
merged = merged.slice(0, previous.length);
|
|
506
|
+
}
|
|
507
|
+
result[resultName] = merged;
|
|
490
508
|
dataState = mergeDataState(dataState, pruned.dataState);
|
|
491
509
|
}
|
|
492
510
|
else if (!selection.selectionSet) {
|
|
@@ -520,10 +538,10 @@ class StoreReader {
|
|
|
520
538
|
// dropped or not.
|
|
521
539
|
const fragment = (0, internal_1.getFragmentFromSelection)(selection, lookupFragment);
|
|
522
540
|
let prune = false;
|
|
523
|
-
if (context.
|
|
541
|
+
if (context.isDeferPending && (0, internal_1.isDeferredFragment)(selection, variables)) {
|
|
524
542
|
const directive = selection.directives?.find((d) => d.name.value === "defer");
|
|
525
543
|
const label = directive && (0, internal_1.getDirectiveArgValue)(directive, "label", graphql_1.Kind.STRING);
|
|
526
|
-
prune =
|
|
544
|
+
prune = context.isDeferPending(path, label);
|
|
527
545
|
}
|
|
528
546
|
if (fragment && policies.fragmentMatches(fragment, data.__typename)) {
|
|
529
547
|
if (boundaries.has(selection) || prune) {
|
|
@@ -624,7 +642,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
|
|
|
624
642
|
if ((0, internal_1.isNonNullObject)(value)) {
|
|
625
643
|
(0, invariant_1.invariant)(
|
|
626
644
|
!(0, utilities_1.isReference)(value),
|
|
627
|
-
|
|
645
|
+
122,
|
|
628
646
|
(0, helpers_js_1.getTypenameFromStoreObject)(store, value),
|
|
629
647
|
field.name.value
|
|
630
648
|
);
|
|
@@ -688,7 +706,7 @@ function shouldPrune({ dataState }, context) {
|
|
|
688
706
|
(context.streamInfo ||
|
|
689
707
|
// The network hasn't delivered these @defer boundaries yet, so prune
|
|
690
708
|
// the (possibly complete) cached data sitting at them.
|
|
691
|
-
context.
|
|
709
|
+
context.isDeferPending));
|
|
692
710
|
}
|
|
693
711
|
return false;
|
|
694
712
|
}
|