@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.
Files changed (99) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/__cjs/cache/core/cache.cjs +1 -1
  3. package/__cjs/cache/core/cache.cjs.map +1 -1
  4. package/__cjs/cache/core/cache.d.cts +4 -1
  5. package/__cjs/cache/core/types/Cache.d.cts +5 -0
  6. package/__cjs/cache/inmemory/entityStore.cjs +4 -4
  7. package/__cjs/cache/inmemory/helpers.cjs +5 -0
  8. package/__cjs/cache/inmemory/helpers.cjs.map +1 -1
  9. package/__cjs/cache/inmemory/inMemoryCache.cjs +17 -6
  10. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  11. package/__cjs/cache/inmemory/inMemoryCache.d.cts +3 -1
  12. package/__cjs/cache/inmemory/key-extractor.cjs +15 -3
  13. package/__cjs/cache/inmemory/key-extractor.cjs.map +1 -1
  14. package/__cjs/cache/inmemory/policies.cjs +21 -5
  15. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  16. package/__cjs/cache/inmemory/policies.d.cts +2 -0
  17. package/__cjs/cache/inmemory/readFromStore.cjs +28 -10
  18. package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
  19. package/__cjs/cache/inmemory/types.d.cts +7 -2
  20. package/__cjs/cache/inmemory/writeToStore.cjs +32 -16
  21. package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
  22. package/__cjs/cache/inmemory/writeToStore.d.cts +5 -2
  23. package/__cjs/core/ApolloClient.cjs +14 -14
  24. package/__cjs/core/ObservableQuery.cjs +8 -8
  25. package/__cjs/core/QueryInfo.cjs +22 -33
  26. package/__cjs/core/QueryInfo.cjs.map +1 -1
  27. package/__cjs/core/QueryInfo.d.cts +1 -1
  28. package/__cjs/core/QueryManager.cjs +22 -15
  29. package/__cjs/core/QueryManager.cjs.map +1 -1
  30. package/__cjs/core/RefetchEventManager.cjs +3 -3
  31. package/__cjs/incremental/handlers/defer20220824.cjs +15 -2
  32. package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
  33. package/__cjs/incremental/handlers/defer20220824.d.cts +5 -1
  34. package/__cjs/incremental/handlers/graphql17Alpha9.cjs +58 -14
  35. package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
  36. package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +23 -12
  37. package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
  38. package/__cjs/incremental/types.d.cts +19 -1
  39. package/__cjs/invariantErrorCodes.cjs +64 -58
  40. package/__cjs/react/hooks/useFragment.cjs.map +1 -1
  41. package/__cjs/react/hooks/useFragment.d.cts +42 -43
  42. package/__cjs/utilities/internal/index.cjs.map +1 -1
  43. package/__cjs/utilities/internal/index.d.cts +0 -1
  44. package/__cjs/version.cjs +1 -1
  45. package/cache/core/cache.d.ts +4 -1
  46. package/cache/core/cache.js +1 -1
  47. package/cache/core/cache.js.map +1 -1
  48. package/cache/core/types/Cache.d.ts +5 -0
  49. package/cache/core/types/Cache.js.map +1 -1
  50. package/cache/inmemory/entityStore.js +4 -4
  51. package/cache/inmemory/helpers.js +5 -0
  52. package/cache/inmemory/helpers.js.map +1 -1
  53. package/cache/inmemory/inMemoryCache.d.ts +3 -1
  54. package/cache/inmemory/inMemoryCache.js +17 -6
  55. package/cache/inmemory/inMemoryCache.js.map +1 -1
  56. package/cache/inmemory/key-extractor.js +15 -3
  57. package/cache/inmemory/key-extractor.js.map +1 -1
  58. package/cache/inmemory/policies.d.ts +2 -0
  59. package/cache/inmemory/policies.js +22 -6
  60. package/cache/inmemory/policies.js.map +1 -1
  61. package/cache/inmemory/readFromStore.js +28 -10
  62. package/cache/inmemory/readFromStore.js.map +1 -1
  63. package/cache/inmemory/types.d.ts +7 -2
  64. package/cache/inmemory/types.js.map +1 -1
  65. package/cache/inmemory/writeToStore.d.ts +5 -2
  66. package/cache/inmemory/writeToStore.js +33 -17
  67. package/cache/inmemory/writeToStore.js.map +1 -1
  68. package/core/ApolloClient.js +14 -14
  69. package/core/ObservableQuery.js +8 -8
  70. package/core/QueryInfo.d.ts +1 -1
  71. package/core/QueryInfo.js +23 -34
  72. package/core/QueryInfo.js.map +1 -1
  73. package/core/QueryManager.js +22 -15
  74. package/core/QueryManager.js.map +1 -1
  75. package/core/RefetchEventManager.js +3 -3
  76. package/incremental/handlers/defer20220824.d.ts +5 -1
  77. package/incremental/handlers/defer20220824.js +15 -2
  78. package/incremental/handlers/defer20220824.js.map +1 -1
  79. package/incremental/handlers/graphql17Alpha9.d.ts +23 -12
  80. package/incremental/handlers/graphql17Alpha9.js +58 -14
  81. package/incremental/handlers/graphql17Alpha9.js.map +1 -1
  82. package/incremental/handlers/notImplemented.js +1 -1
  83. package/incremental/types.d.ts +19 -1
  84. package/incremental/types.js.map +1 -1
  85. package/invariantErrorCodes.js +64 -58
  86. package/package.json +1 -1
  87. package/react/hooks/useFragment.d.ts +42 -43
  88. package/react/hooks/useFragment.js.map +1 -1
  89. package/react/hooks-compiled/useFragment.d.ts +42 -43
  90. package/react/hooks-compiled/useFragment.js.map +1 -1
  91. package/utilities/internal/index.d.ts +0 -1
  92. package/utilities/internal/index.js.map +1 -1
  93. package/version.js +1 -1
  94. package/__cjs/utilities/internal/types/DeferInfo.cjs +0 -3
  95. package/__cjs/utilities/internal/types/DeferInfo.cjs.map +0 -1
  96. package/__cjs/utilities/internal/types/DeferInfo.d.cts +0 -10
  97. package/utilities/internal/types/DeferInfo.d.ts +0 -10
  98. package/utilities/internal/types/DeferInfo.js +0 -2
  99. package/utilities/internal/types/DeferInfo.js.map +0 -1
@@ -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.deferInfo);
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.deferInfo);
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(119, `${typename}.${fieldName}`, policy.scalar);
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(120, selection.name.value);
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
- const merger = new DeepMerger();
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] = pruned.result;
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.deferInfo && isDeferredFragment(selection, variables)) {
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 = !!context.deferInfo.peekArray(path.concat(label || []));
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
- 121,
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.deferInfo));
701
+ context.isDeferPending));
684
702
  }
685
703
  return false;
686
704
  }