@apollo/client 4.1.0-alpha.7 → 4.1.0-alpha.9

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 (130) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/__cjs/cache/core/cache.cjs +64 -24
  3. package/__cjs/cache/core/cache.cjs.map +1 -1
  4. package/__cjs/cache/core/cache.d.cts +47 -0
  5. package/__cjs/cache/core/types/Cache.d.cts +38 -0
  6. package/__cjs/cache/inmemory/entityStore.cjs +3 -3
  7. package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
  8. package/__cjs/cache/inmemory/inMemoryCache.cjs +47 -0
  9. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  10. package/__cjs/cache/inmemory/inMemoryCache.d.cts +47 -0
  11. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  12. package/__cjs/cache/inmemory/policies.cjs +14 -5
  13. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  14. package/__cjs/cache/inmemory/policies.d.cts +5 -0
  15. package/__cjs/cache/inmemory/readFromStore.cjs +3 -3
  16. package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
  17. package/__cjs/cache/inmemory/types.d.cts +1 -0
  18. package/__cjs/cache/inmemory/writeToStore.cjs +6 -5
  19. package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
  20. package/__cjs/cache/inmemory/writeToStore.d.cts +2 -1
  21. package/__cjs/core/ApolloClient.cjs +14 -14
  22. package/__cjs/core/ApolloClient.cjs.map +1 -1
  23. package/__cjs/core/ApolloClient.d.cts +21 -1
  24. package/__cjs/core/ObservableQuery.cjs +22 -8
  25. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  26. package/__cjs/core/ObservableQuery.d.cts +1 -0
  27. package/__cjs/core/QueryInfo.cjs +3 -0
  28. package/__cjs/core/QueryInfo.cjs.map +1 -1
  29. package/__cjs/core/QueryManager.cjs +27 -17
  30. package/__cjs/core/QueryManager.cjs.map +1 -1
  31. package/__cjs/core/QueryManager.d.cts +18 -2
  32. package/__cjs/invariantErrorCodes.cjs +39 -33
  33. package/__cjs/link/client-awareness/ClientAwarenessLink.cjs +13 -1
  34. package/__cjs/link/client-awareness/ClientAwarenessLink.cjs.map +1 -1
  35. package/__cjs/link/client-awareness/ClientAwarenessLink.d.cts +1 -1
  36. package/__cjs/link/error/index.cjs +1 -1
  37. package/__cjs/link/error/index.cjs.map +1 -1
  38. package/__cjs/link/error/index.d.cts +1 -1
  39. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
  40. package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
  41. package/__cjs/react/hooks/useLazyQuery.cjs +1 -0
  42. package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
  43. package/__cjs/react/hooks/useQuery.cjs +7 -4
  44. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  45. package/__cjs/react/hooks/useSuspenseQuery.cjs +2 -0
  46. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  47. package/__cjs/utilities/internal/checkDocument.cjs +2 -4
  48. package/__cjs/utilities/internal/checkDocument.cjs.map +1 -1
  49. package/__cjs/utilities/internal/constants.cjs +21 -0
  50. package/__cjs/utilities/internal/constants.cjs.map +1 -0
  51. package/__cjs/utilities/internal/constants.d.cts +18 -0
  52. package/__cjs/utilities/internal/index.cjs +6 -1
  53. package/__cjs/utilities/internal/index.cjs.map +1 -1
  54. package/__cjs/utilities/internal/index.d.cts +2 -0
  55. package/__cjs/utilities/internal/mapObservableFragment.cjs +27 -0
  56. package/__cjs/utilities/internal/mapObservableFragment.cjs.map +1 -0
  57. package/__cjs/utilities/internal/mapObservableFragment.d.cts +3 -0
  58. package/__cjs/utilities/internal/memoize.cjs +31 -0
  59. package/__cjs/utilities/internal/memoize.cjs.map +1 -0
  60. package/__cjs/utilities/internal/memoize.d.cts +8 -0
  61. package/__cjs/version.cjs +1 -1
  62. package/cache/core/cache.d.ts +47 -0
  63. package/cache/core/cache.js +65 -25
  64. package/cache/core/cache.js.map +1 -1
  65. package/cache/core/types/Cache.d.ts +38 -0
  66. package/cache/core/types/Cache.js.map +1 -1
  67. package/cache/inmemory/entityStore.js +3 -3
  68. package/cache/inmemory/entityStore.js.map +1 -1
  69. package/cache/inmemory/inMemoryCache.d.ts +47 -0
  70. package/cache/inmemory/inMemoryCache.js +47 -0
  71. package/cache/inmemory/inMemoryCache.js.map +1 -1
  72. package/cache/inmemory/key-extractor.js +1 -1
  73. package/cache/inmemory/policies.d.ts +5 -0
  74. package/cache/inmemory/policies.js +14 -5
  75. package/cache/inmemory/policies.js.map +1 -1
  76. package/cache/inmemory/readFromStore.js +3 -3
  77. package/cache/inmemory/readFromStore.js.map +1 -1
  78. package/cache/inmemory/types.d.ts +1 -0
  79. package/cache/inmemory/types.js.map +1 -1
  80. package/cache/inmemory/writeToStore.d.ts +2 -1
  81. package/cache/inmemory/writeToStore.js +6 -5
  82. package/cache/inmemory/writeToStore.js.map +1 -1
  83. package/core/ApolloClient.d.ts +21 -1
  84. package/core/ApolloClient.js +15 -15
  85. package/core/ApolloClient.js.map +1 -1
  86. package/core/ObservableQuery.d.ts +1 -0
  87. package/core/ObservableQuery.js +23 -9
  88. package/core/ObservableQuery.js.map +1 -1
  89. package/core/QueryInfo.js +3 -0
  90. package/core/QueryInfo.js.map +1 -1
  91. package/core/QueryManager.d.ts +18 -2
  92. package/core/QueryManager.js +28 -18
  93. package/core/QueryManager.js.map +1 -1
  94. package/invariantErrorCodes.js +39 -33
  95. package/link/client-awareness/ClientAwarenessLink.d.ts +1 -1
  96. package/link/client-awareness/ClientAwarenessLink.js +13 -1
  97. package/link/client-awareness/ClientAwarenessLink.js.map +1 -1
  98. package/link/error/index.d.ts +1 -1
  99. package/link/error/index.js +1 -1
  100. package/link/error/index.js.map +1 -1
  101. package/link/http/parseAndCheckHttpResponse.js +1 -1
  102. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  103. package/package.json +1 -1
  104. package/react/hooks/useLazyQuery.js +2 -1
  105. package/react/hooks/useLazyQuery.js.map +1 -1
  106. package/react/hooks/useQuery.js +8 -5
  107. package/react/hooks/useQuery.js.map +1 -1
  108. package/react/hooks/useSuspenseQuery.js +2 -0
  109. package/react/hooks/useSuspenseQuery.js.map +1 -1
  110. package/react/hooks-compiled/useLazyQuery.js +2 -1
  111. package/react/hooks-compiled/useLazyQuery.js.map +1 -1
  112. package/react/hooks-compiled/useQuery.js +9 -5
  113. package/react/hooks-compiled/useQuery.js.map +1 -1
  114. package/react/hooks-compiled/useSuspenseQuery.js +3 -1
  115. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  116. package/utilities/internal/checkDocument.js +2 -4
  117. package/utilities/internal/checkDocument.js.map +1 -1
  118. package/utilities/internal/constants.d.ts +18 -0
  119. package/utilities/internal/constants.js +18 -0
  120. package/utilities/internal/constants.js.map +1 -0
  121. package/utilities/internal/index.d.ts +2 -0
  122. package/utilities/internal/index.js +2 -0
  123. package/utilities/internal/index.js.map +1 -1
  124. package/utilities/internal/mapObservableFragment.d.ts +3 -0
  125. package/utilities/internal/mapObservableFragment.js +24 -0
  126. package/utilities/internal/mapObservableFragment.js.map +1 -0
  127. package/utilities/internal/memoize.d.ts +8 -0
  128. package/utilities/internal/memoize.js +28 -0
  129. package/utilities/internal/memoize.js.map +1 -0
  130. package/version.js +1 -1
@@ -50,6 +50,11 @@ export declare namespace Cache {
50
50
  * @defaultValue false
51
51
  */
52
52
  overwrite?: boolean;
53
+ /**
54
+ * GraphQL extensions for the write operation. Any provided `extensions`
55
+ * are available in `merge` functions.
56
+ */
57
+ extensions?: Record<string, unknown>;
53
58
  }
54
59
  interface DiffOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> extends Omit<ReadOptions<TData, TVariables>, "rootId"> {
55
60
  }
@@ -75,9 +80,37 @@ export declare namespace Cache {
75
80
  broadcast?: boolean;
76
81
  }
77
82
  interface BatchOptions<TCache extends ApolloCache, TUpdateResult = void> {
83
+ /**
84
+ * A function that performs cache operations. Receives the cache instance as its argument.
85
+ *
86
+ * The return value of this function becomes the return value of `batch`.
87
+ */
78
88
  update(cache: TCache): TUpdateResult;
89
+ /**
90
+ * Controls how optimistic data is handled:
91
+ *
92
+ * - `string`: Creates a new optimistic layer with this ID. Use `removeOptimistic` later to remove it.
93
+ * - `true`: Updates the current top layer of the cache (including any optimistic data).
94
+ * - `false`: Updates only the root (non-optimistic) cache data.
95
+ *
96
+ * @defaultValue false
97
+ */
79
98
  optimistic?: string | boolean;
99
+ /**
100
+ * If provided, removes the optimistic layer with this ID after the batch completes.
101
+ *
102
+ * This is useful for atomically applying server data while removing a pending optimistic update, triggering at most one broadcast for both operations.
103
+ *
104
+ * Note: this option is needed because calling `cache.removeOptimistic` during the transaction function may not be safe, since any modifications to cache layers may be discarded after the transaction finishes.
105
+ */
80
106
  removeOptimistic?: string;
107
+ /**
108
+ * Optional callback invoked for each watcher affected by the batch operation.
109
+ *
110
+ * Receives the watch options, the new diff result, and optionally the previous diff result.
111
+ *
112
+ * Return `false` to prevent broadcasting to that specific watcher.
113
+ */
81
114
  onWatchUpdated?: (this: TCache, watch: Cache.WatchOptions, diff: Cache.DiffResult<any>, lastDiff?: Cache.DiffResult<any> | undefined) => any;
82
115
  }
83
116
  interface ReadQueryOptions<TData, TVariables extends OperationVariables> {
@@ -174,6 +207,11 @@ export declare namespace Cache {
174
207
  * @defaultValue false
175
208
  */
176
209
  overwrite?: boolean;
210
+ /**
211
+ * GraphQL extensions for the write operation. Any provided `extensions`
212
+ * are available in `merge` functions.
213
+ */
214
+ extensions?: Record<string, unknown>;
177
215
  }
178
216
  type WriteFragmentOptions<TData, TVariables extends OperationVariables> = {
179
217
  /**
@@ -82,7 +82,7 @@ class EntityStore {
82
82
  // then there are no fields to be merged, so we're done.
83
83
  if (!incoming)
84
84
  return;
85
- (0, invariant_1.invariant)(typeof dataId === "string", 98);
85
+ (0, invariant_1.invariant)(typeof dataId === "string", 99);
86
86
  const merged = new internal_1.DeepMerger({
87
87
  reconciler: storeObjectReconciler,
88
88
  }).merge(existing, incoming);
@@ -184,7 +184,7 @@ class EntityStore {
184
184
  if (environment_1.__DEV__) {
185
185
  const checkReference = (ref) => {
186
186
  if (this.lookup(ref.__ref) === undefined) {
187
- __DEV__ && invariant_1.invariant.warn(99, ref);
187
+ __DEV__ && invariant_1.invariant.warn(100, ref);
188
188
  return true;
189
189
  }
190
190
  };
@@ -213,7 +213,7 @@ class EntityStore {
213
213
  }
214
214
  }
215
215
  if (seenReference && someNonReference !== undefined) {
216
- __DEV__ && invariant_1.invariant.warn(100, someNonReference);
216
+ __DEV__ && invariant_1.invariant.warn(101, someNonReference);
217
217
  break;
218
218
  }
219
219
  }