@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
|
@@ -242,7 +242,7 @@ export class Policies {
|
|
|
242
242
|
const rootId = "ROOT_" + which.toUpperCase();
|
|
243
243
|
const old = this.rootTypenamesById[rootId];
|
|
244
244
|
if (typename !== old) {
|
|
245
|
-
invariant(!old || old === which,
|
|
245
|
+
invariant(!old || old === which, 115, which);
|
|
246
246
|
// First, delete any old __typename associated with this rootId from
|
|
247
247
|
// rootIdsByTypename.
|
|
248
248
|
if (old)
|
|
@@ -385,7 +385,7 @@ export class Policies {
|
|
|
385
385
|
if (supertypeSet.has(supertype)) {
|
|
386
386
|
if (!typenameSupertypeSet.has(supertype)) {
|
|
387
387
|
if (checkingFuzzySubtypes) {
|
|
388
|
-
__DEV__ && invariant.warn(
|
|
388
|
+
__DEV__ && invariant.warn(116, typename, supertype);
|
|
389
389
|
}
|
|
390
390
|
// Record positive results for faster future lookup.
|
|
391
391
|
// Unfortunately, we cannot safely cache negative results,
|
|
@@ -640,7 +640,7 @@ export function normalizeReadFieldOptions(readFieldArgs, objectOrReference, vari
|
|
|
640
640
|
}
|
|
641
641
|
}
|
|
642
642
|
if (__DEV__ && options.from === void 0) {
|
|
643
|
-
__DEV__ && invariant.warn(
|
|
643
|
+
__DEV__ && invariant.warn(117, stringifyForDisplay(Array.from(readFieldArgs)));
|
|
644
644
|
}
|
|
645
645
|
if (void 0 === options.variables) {
|
|
646
646
|
options.variables = variables;
|
|
@@ -650,7 +650,7 @@ export function normalizeReadFieldOptions(readFieldArgs, objectOrReference, vari
|
|
|
650
650
|
function makeMergeObjectsFunction(store) {
|
|
651
651
|
return function mergeObjects(existing, incoming) {
|
|
652
652
|
if (isArray(existing) || isArray(incoming)) {
|
|
653
|
-
throw newInvariantError(
|
|
653
|
+
throw newInvariantError(118);
|
|
654
654
|
}
|
|
655
655
|
// These dynamic checks are necessary because the parameters of a
|
|
656
656
|
// custom merge function can easily have the any type, so the type
|
|
@@ -687,6 +687,6 @@ function makeMergeObjectsFunction(store) {
|
|
|
687
687
|
};
|
|
688
688
|
}
|
|
689
689
|
function warnAboutScalarConfig(typename, fieldName, scalar, kind) {
|
|
690
|
-
__DEV__ && invariant.warn(
|
|
690
|
+
__DEV__ && invariant.warn(119, `${typename}.${fieldName}`, scalar, kind);
|
|
691
691
|
}
|
|
692
692
|
//# sourceMappingURL=policies.js.map
|
|
@@ -69,7 +69,7 @@ export class StoreReader {
|
|
|
69
69
|
20000 /* defaultCacheSizes["inMemoryCache.prunePartialBoundaries"] */,
|
|
70
70
|
makeCacheKey: ({ boundaries, context, selectionSet }) => {
|
|
71
71
|
if (supportsResultCaching(context.store)) {
|
|
72
|
-
return this.keyMaker.lookup(selectionSet, boundaries, context.streamInfo, context.
|
|
72
|
+
return this.keyMaker.lookup(selectionSet, boundaries, context.streamInfo, context.isDeferPending);
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
75
|
});
|
|
@@ -84,7 +84,7 @@ export class StoreReader {
|
|
|
84
84
|
20000 /* defaultCacheSizes["inMemoryCache.prunePartialStreamArray"] */,
|
|
85
85
|
makeCacheKey: ({ field, context, boundaries }) => {
|
|
86
86
|
if (supportsResultCaching(context.store)) {
|
|
87
|
-
return this.keyMaker.lookup(field, boundaries, context.streamInfo, context.
|
|
87
|
+
return this.keyMaker.lookup(field, boundaries, context.streamInfo, context.isDeferPending);
|
|
88
88
|
}
|
|
89
89
|
},
|
|
90
90
|
});
|
|
@@ -282,7 +282,7 @@ export class StoreReader {
|
|
|
282
282
|
if (typename) {
|
|
283
283
|
const policy = policies["getFieldPolicy"](typename, fieldName);
|
|
284
284
|
if (policy?.scalar) {
|
|
285
|
-
__DEV__ && invariant.warn(
|
|
285
|
+
__DEV__ && invariant.warn(120, `${typename}.${fieldName}`, policy.scalar);
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
288
|
}
|
|
@@ -319,7 +319,7 @@ export class StoreReader {
|
|
|
319
319
|
else {
|
|
320
320
|
const fragment = getFragmentFromSelection(selection, context.lookupFragment);
|
|
321
321
|
if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {
|
|
322
|
-
throw newInvariantError(
|
|
322
|
+
throw newInvariantError(121, selection.name.value);
|
|
323
323
|
}
|
|
324
324
|
if (fragment && policies.fragmentMatches(fragment, typename)) {
|
|
325
325
|
const isDeferBoundary = isDeferredFragment(selection, context.variables);
|
|
@@ -450,7 +450,10 @@ export class StoreReader {
|
|
|
450
450
|
if (data == null || !boundaries) {
|
|
451
451
|
return { result: data, dataState: "complete" };
|
|
452
452
|
}
|
|
453
|
-
|
|
453
|
+
// `truncate` is only necessary for the Defer20220824 protocol. the
|
|
454
|
+
// `arrayMerge` option can be removed when we stop supporting the old
|
|
455
|
+
// protocol. See the comment below on array merging for more info.
|
|
456
|
+
const merger = new DeepMerger({ arrayMerge: "truncate" });
|
|
454
457
|
let changed = false;
|
|
455
458
|
let dataState = "complete";
|
|
456
459
|
const result = {};
|
|
@@ -479,7 +482,22 @@ export class StoreReader {
|
|
|
479
482
|
path: path.concat(resultName),
|
|
480
483
|
});
|
|
481
484
|
changed ||= pruned.result !== fieldValue;
|
|
482
|
-
result[resultName]
|
|
485
|
+
const previous = result[resultName];
|
|
486
|
+
let merged = merger.merge(previous, pruned.result);
|
|
487
|
+
// The Defer20220824 protocol allows more than one selection of a
|
|
488
|
+
// list field with `@stream` when the `@stream` arguments are the
|
|
489
|
+
// same. Each selection can prune the list to a different length, so
|
|
490
|
+
// we keep the shortest length. The `truncate` option of the merger
|
|
491
|
+
// handles a shorter later visit, and this check handles a shorter
|
|
492
|
+
// earlier visit. GraphQL 17 rejects any overlapping `@stream` field,
|
|
493
|
+
// so all visits give the same length. When we no longer support the
|
|
494
|
+
// older protocol, we can remove this check and the `truncate` option,
|
|
495
|
+
// and simplify to:
|
|
496
|
+
// result[resultName] = merger.merge(result[resultName], pruned.result);
|
|
497
|
+
if (previous && previous.length < merged.length) {
|
|
498
|
+
merged = merged.slice(0, previous.length);
|
|
499
|
+
}
|
|
500
|
+
result[resultName] = merged;
|
|
483
501
|
dataState = mergeDataState(dataState, pruned.dataState);
|
|
484
502
|
}
|
|
485
503
|
else if (!selection.selectionSet) {
|
|
@@ -513,10 +531,10 @@ export class StoreReader {
|
|
|
513
531
|
// dropped or not.
|
|
514
532
|
const fragment = getFragmentFromSelection(selection, lookupFragment);
|
|
515
533
|
let prune = false;
|
|
516
|
-
if (context.
|
|
534
|
+
if (context.isDeferPending && isDeferredFragment(selection, variables)) {
|
|
517
535
|
const directive = selection.directives?.find((d) => d.name.value === "defer");
|
|
518
536
|
const label = directive && getDirectiveArgValue(directive, "label", Kind.STRING);
|
|
519
|
-
prune =
|
|
537
|
+
prune = context.isDeferPending(path, label);
|
|
520
538
|
}
|
|
521
539
|
if (fragment && policies.fragmentMatches(fragment, data.__typename)) {
|
|
522
540
|
if (boundaries.has(selection) || prune) {
|
|
@@ -616,7 +634,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
|
|
|
616
634
|
if (isNonNullObject(value)) {
|
|
617
635
|
invariant(
|
|
618
636
|
!isReference(value),
|
|
619
|
-
|
|
637
|
+
122,
|
|
620
638
|
getTypenameFromStoreObject(store, value),
|
|
621
639
|
field.name.value
|
|
622
640
|
);
|
|
@@ -680,7 +698,7 @@ function shouldPrune({ dataState }, context) {
|
|
|
680
698
|
(context.streamInfo ||
|
|
681
699
|
// The network hasn't delivered these @defer boundaries yet, so prune
|
|
682
700
|
// the (possibly complete) cached data sitting at them.
|
|
683
|
-
context.
|
|
701
|
+
context.isDeferPending));
|
|
684
702
|
}
|
|
685
703
|
return false;
|
|
686
704
|
}
|