@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
@@ -2,9 +2,10 @@ import type { FieldNode, SelectionSetNode } from "graphql";
2
2
  import type { Cache, OperationVariables } from "@apollo/client";
3
3
  import type { Reference, StoreObject } from "@apollo/client/utilities";
4
4
  import type { FragmentMap, FragmentMapFunction } from "@apollo/client/utilities/internal";
5
+ import { handleIncrementalSymbol } from "@apollo/client/utilities/internal";
5
6
  import type { InMemoryCache } from "./inMemoryCache.cjs";
6
7
  import type { StoreReader } from "./readFromStore.cjs";
7
- import type { InMemoryCacheConfig, MergeTree, NormalizedCache, ReadMergeModifyContext } from "./types.cjs";
8
+ import type { DiffIncrementalInfo, InMemoryCacheConfig, MergeTree, NormalizedCache, ReadMergeModifyContext } from "./types.cjs";
8
9
  export interface WriteContext extends ReadMergeModifyContext {
9
10
  readonly written: {
10
11
  [dataId: string]: SelectionSetNode[];
@@ -28,7 +29,9 @@ export declare class StoreWriter {
28
29
  private reader?;
29
30
  private fragments?;
30
31
  constructor(cache: InMemoryCache, reader?: StoreReader | undefined, fragments?: InMemoryCacheConfig["fragments"]);
31
- writeToStore<TData = unknown, TVariables extends OperationVariables = OperationVariables>(store: NormalizedCache, { query, result, dataId, variables, overwrite, extensions, }: Cache.WriteOptions<TData, TVariables>): Reference | undefined;
32
+ writeToStore<TData = unknown, TVariables extends OperationVariables = OperationVariables>(store: NormalizedCache, { query, result, dataId, variables, overwrite, extensions, [handleIncrementalSymbol]: incrementalInfo, }: Cache.WriteOptions<TData, TVariables> & {
33
+ [handleIncrementalSymbol]?: DiffIncrementalInfo;
34
+ }): Reference | undefined;
32
35
  private processSelectionSet;
33
36
  private processFieldValue;
34
37
  private flattenFields;
@@ -78,8 +78,8 @@ class ApolloClient {
78
78
  */
79
79
  constructor(options) {
80
80
  if (environment_1.__DEV__) {
81
- (0, invariant_1.invariant)(options.cache, 70);
82
- (0, invariant_1.invariant)(options.link, 71);
81
+ (0, invariant_1.invariant)(options.cache, 71);
82
+ (0, invariant_1.invariant)(options.link, 72);
83
83
  }
84
84
  const { cache, documentTransform, ssrMode = false, ssrForceFetchDelay = 0, queryDeduplication = true, defaultOptions, defaultContext, assumeImmutableResults = cache.assumeImmutableResults, localState, devtools, dataMasking, link, incrementalHandler = new incremental_1.NotImplementedHandler(), experiments = [], refetchEventManager, } = options;
85
85
  this.link = link;
@@ -267,12 +267,12 @@ class ApolloClient {
267
267
  if (refetchOn) {
268
268
  const operationName = (0, internal_1.getOperationName)(query, "(anonymous)");
269
269
  if (!refetchEventManager) {
270
- __DEV__ && invariant_1.invariant.warn(72, operationName);
270
+ __DEV__ && invariant_1.invariant.warn(73, operationName);
271
271
  }
272
272
  else if (typeof refetchOn === "object") {
273
273
  Object.keys(refetchOn).forEach((source) => {
274
274
  if (!refetchEventManager.hasSource(source)) {
275
- __DEV__ && invariant_1.invariant.warn(73, source, operationName);
275
+ __DEV__ && invariant_1.invariant.warn(74, source, operationName);
276
276
  }
277
277
  });
278
278
  }
@@ -294,13 +294,13 @@ class ApolloClient {
294
294
  options = (0, internal_1.mergeOptions)(this.defaultOptions.query, options);
295
295
  }
296
296
  if (environment_1.__DEV__) {
297
- (0, invariant_1.invariant)(options.fetchPolicy !== "cache-and-network", 74);
298
- (0, invariant_1.invariant)(options.fetchPolicy !== "standby", 75);
299
- (0, invariant_1.invariant)(options.query, 76);
300
- (0, invariant_1.invariant)(options.query.kind === "Document", 77);
301
- (0, invariant_1.invariant)(!options.returnPartialData, 78);
302
- (0, invariant_1.invariant)(!options.pollInterval, 79);
303
- (0, invariant_1.invariant)(!options.notifyOnNetworkStatusChange, 80);
297
+ (0, invariant_1.invariant)(options.fetchPolicy !== "cache-and-network", 75);
298
+ (0, invariant_1.invariant)(options.fetchPolicy !== "standby", 76);
299
+ (0, invariant_1.invariant)(options.query, 77);
300
+ (0, invariant_1.invariant)(options.query.kind === "Document", 78);
301
+ (0, invariant_1.invariant)(!options.returnPartialData, 79);
302
+ (0, invariant_1.invariant)(!options.pollInterval, 80);
303
+ (0, invariant_1.invariant)(!options.notifyOnNetworkStatusChange, 81);
304
304
  }
305
305
  return this.queryManager.query(options);
306
306
  };
@@ -318,9 +318,9 @@ class ApolloClient {
318
318
  errorPolicy: "none",
319
319
  }, this.defaultOptions.mutate), options);
320
320
  if (environment_1.__DEV__) {
321
- (0, invariant_1.invariant)(optionsWithDefaults.mutation, 81);
321
+ (0, invariant_1.invariant)(optionsWithDefaults.mutation, 82);
322
322
  (0, invariant_1.invariant)(optionsWithDefaults.fetchPolicy === "network-only" ||
323
- optionsWithDefaults.fetchPolicy === "no-cache", 82);
323
+ optionsWithDefaults.fetchPolicy === "no-cache", 83);
324
324
  }
325
325
  (0, internal_1.checkDocument)(optionsWithDefaults.mutation, graphql_1.OperationTypeNode.MUTATION);
326
326
  return this.queryManager.mutate(optionsWithDefaults);
@@ -526,7 +526,7 @@ class ApolloClient {
526
526
  // result.queries and result.results instead, you shouldn't have to worry
527
527
  // about preventing uncaught rejections for the Promise.all result.
528
528
  result.catch((error) => {
529
- __DEV__ && invariant_1.invariant.debug(83, error);
529
+ __DEV__ && invariant_1.invariant.debug(84, error);
530
530
  });
531
531
  return result;
532
532
  }
@@ -110,7 +110,7 @@ class ObservableQuery {
110
110
  // Make sure we don't store "standby" as the initialFetchPolicy.
111
111
  initialFetchPolicy = fetchPolicy === "standby" ? defaultFetchPolicy : (fetchPolicy), } = options;
112
112
  if (options[internal_1.variablesUnknownSymbol]) {
113
- (0, invariant_1.invariant)(fetchPolicy === "standby", 84);
113
+ (0, invariant_1.invariant)(fetchPolicy === "standby", 85);
114
114
  this.variablesUnknown = true;
115
115
  }
116
116
  this.lastQuery = transformedQuery;
@@ -419,7 +419,7 @@ class ObservableQuery {
419
419
  const queryDef = (0, internal_1.getQueryDefinition)(this.query);
420
420
  const vars = queryDef.variableDefinitions;
421
421
  if (!vars || !vars.some((v) => v.variable.name.value === "variables")) {
422
- __DEV__ && invariant_1.invariant.warn(85, variables, queryDef.name?.value || queryDef);
422
+ __DEV__ && invariant_1.invariant.warn(86, variables, queryDef.name?.value || queryDef);
423
423
  }
424
424
  }
425
425
  if (variables && !(0, equality_1.equal)(this.variables, variables)) {
@@ -434,7 +434,7 @@ class ObservableQuery {
434
434
  fetchMore({ query, variables, context, errorPolicy, updateQuery, }) {
435
435
  (0, invariant_1.invariant)(
436
436
  this.options.fetchPolicy !== "cache-only",
437
- 86,
437
+ 87,
438
438
  (0, internal_1.getOperationName)(this.query, "(anonymous)")
439
439
  );
440
440
  const combinedOptions = {
@@ -468,7 +468,7 @@ class ObservableQuery {
468
468
  let wasUpdated = false;
469
469
  const isCached = this.options.fetchPolicy !== "no-cache";
470
470
  if (!isCached) {
471
- (0, invariant_1.invariant)(updateQuery, 87);
471
+ (0, invariant_1.invariant)(updateQuery, 88);
472
472
  }
473
473
  const { finalize, pushNotification } = this.pushOperation(networkStatus_js_1.NetworkStatus.fetchMore);
474
474
  pushNotification({
@@ -642,7 +642,7 @@ class ObservableQuery {
642
642
  onError(error);
643
643
  }
644
644
  else {
645
- invariant_1.invariant.error(88, error);
645
+ invariant_1.invariant.error(89, error);
646
646
  }
647
647
  return;
648
648
  }
@@ -893,7 +893,7 @@ class ObservableQuery {
893
893
  if (!this.didWarnCacheOnlyPolling &&
894
894
  pollInterval &&
895
895
  fetchPolicy === "cache-only") {
896
- __DEV__ && invariant_1.invariant.warn(89, (0, internal_1.getOperationName)(this.query, "(anonymous)"));
896
+ __DEV__ && invariant_1.invariant.warn(90, (0, internal_1.getOperationName)(this.query, "(anonymous)"));
897
897
  this.didWarnCacheOnlyPolling = true;
898
898
  }
899
899
  }
@@ -1520,7 +1520,7 @@ class ObservableQuery {
1520
1520
  exports.ObservableQuery = ObservableQuery;
1521
1521
  function logMissingFieldErrors(missing) {
1522
1522
  if (environment_1.__DEV__ && missing) {
1523
- __DEV__ && invariant_1.invariant.debug(90, missing);
1523
+ __DEV__ && invariant_1.invariant.debug(91, missing);
1524
1524
  }
1525
1525
  }
1526
1526
  function isEqualQuery(a, b) {
@@ -1565,7 +1565,7 @@ function getTrackingOperatorPromise(defaultValue) {
1565
1565
  }
1566
1566
  function warnOnFeud(query, diff) {
1567
1567
  __DEV__ && invariant_1.invariant.warn(
1568
- 91,
1568
+ 92,
1569
1569
  (0, internal_1.getOperationName)(query, "(anonymous)"),
1570
1570
  diff.missing?.missing
1571
1571
  );
@@ -5,7 +5,6 @@ const {
5
5
 
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.QueryInfo = void 0;
8
- const trie_1 = require("@wry/trie");
9
8
  const environment_1 = require("@apollo/client/utilities/environment");
10
9
  const internal_1 = require("@apollo/client/utilities/internal");
11
10
  const invariant_1 = require("@apollo/client/utilities/invariant");
@@ -74,26 +73,7 @@ class QueryInfo {
74
73
  ...incrementalResult,
75
74
  dataState: incrementalResult.data == null ? "empty" : "complete",
76
75
  };
77
- const hasPendingDefer = this.incremental
78
- ?.getPendingWithInfo?.()
79
- .some((pending) => pending.type === "defer" && !pending.delivered);
80
- if (hasPendingDefer ||
81
- // The Defer20220824Handler cannot track pending/completed incremental
82
- // chunks due to its data format so we naively set dataState to
83
- // streaming if we are still processing chunks. The only case where
84
- // streaming is incorrect and should actually be complete is when
85
- // both a @defer and @stream boundary is present and the @defer chunk
86
- // has completed before the `@stream` array.
87
- //
88
- // Assigning the naive "streaming" value avoids a much more expensive
89
- // pass over `result.data` that would otherwise need to traverse the
90
- // selection sets and evaluate the data object at each defer boundary
91
- // to see if it fulfills the selection set. For such a narrow case where
92
- // its incorrect on a format that is now outdated is not worth the
93
- // fix so we are ok with reporting a `streaming` here.
94
- (!this.incremental?.getPendingWithInfo &&
95
- this.hasNext &&
96
- (0, internal_1.hasDirectives)(["defer"], query))) {
76
+ if (this.incremental?.isDeferPending()) {
97
77
  result.dataState = "streaming";
98
78
  }
99
79
  if (skipCache || !shouldWriteResult(result, errorPolicy)) {
@@ -120,6 +100,9 @@ class QueryInfo {
120
100
  variables,
121
101
  overwrite: cacheWriteBehavior === 1 /* CacheWriteBehavior.OVERWRITE */,
122
102
  extensions: result.extensions,
103
+ [internal_1.handleIncrementalSymbol]: {
104
+ isDeferPending: this.incremental?.isDeferPending,
105
+ },
123
106
  });
124
107
  const { dataState, result: diffResult } = this.getDiff({
125
108
  ...diffOptions,
@@ -148,23 +131,18 @@ class QueryInfo {
148
131
  return result;
149
132
  }
150
133
  getIncrementalInfo({ prune }) {
151
- const pending = this.incremental?.getPendingWithInfo?.() ?? [];
152
134
  const streamInfo = this.incremental?.streamInfo;
153
135
  const incrementalInfo = { streamInfo };
154
136
  // We don't want to deliver stream items or complete defer boundaries
155
137
  // for a network-only request if they haven't yet streamed from the
156
138
  // network. We record all the still-pending paths so that cache.diff
157
139
  // can prune complete defer/stream boundaries at those paths.
158
- if (prune) {
159
- for (const item of pending) {
160
- if (item.type === "defer" && !item.delivered) {
161
- incrementalInfo.deferInfo ||= new trie_1.Trie(true, () => true);
162
- incrementalInfo.deferInfo.lookupArray(item.path.concat(item.label || []));
163
- }
164
- else if (streamInfo && item.type === "stream") {
165
- streamInfo.lookupArray(item.path).state.truncate = true;
166
- }
140
+ if (prune && this.incremental?.tracksPending) {
141
+ const isDeferPending = this.incremental.isDeferPending;
142
+ if (isDeferPending()) {
143
+ incrementalInfo.isDeferPending ||= (path, label) => isDeferPending(path, label);
167
144
  }
145
+ this.incremental.markStreamedPendingForTruncation?.();
168
146
  }
169
147
  return incrementalInfo;
170
148
  }
@@ -204,6 +182,9 @@ class QueryInfo {
204
182
  query: mutation.document,
205
183
  variables: mutation.variables,
206
184
  extensions: result.extensions,
185
+ [internal_1.handleIncrementalSymbol]: {
186
+ isDeferPending: this.incremental?.isDeferPending,
187
+ },
207
188
  });
208
189
  const { updateQueries } = mutation;
209
190
  if (updateQueries) {
@@ -361,17 +342,25 @@ class QueryInfo {
361
342
  returnPartialData: true,
362
343
  });
363
344
  if (diff.complete) {
364
- result.data = diff.result;
345
+ return diff.result;
365
346
  }
366
347
  }
367
348
  this.queryManager.broadcastQueries();
368
349
  }
350
+ else if (result.data != null &&
351
+ this.cache.configuresScalars() &&
352
+ shouldWriteResult(result, errorPolicy)) {
353
+ // The result is not written to the cache, so parse scalar values
354
+ // directly from the network result.
355
+ return (0, internal_1.coerceScalarFieldsToParsed)(result.data, document, this.cache);
356
+ }
357
+ return result.data;
369
358
  }
370
359
  }
371
360
  exports.QueryInfo = QueryInfo;
372
361
  function warnAboutPartialCacheResult(query, networkResult, diff) {
373
362
  __DEV__ && invariant_1.invariant.warn(
374
- 92,
363
+ 93,
375
364
  (0, internal_1.getOperationName)(query, "(anonymous)"),
376
365
  diff.missing?.missing,
377
366
  networkResult,