@apollo/client 4.3.0-rc.0 → 4.3.0-rc.2

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 (191) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/__cjs/cache/core/cache.cjs +3 -3
  3. package/__cjs/cache/core/cache.cjs.map +1 -1
  4. package/__cjs/cache/core/cache.d.cts +3 -3
  5. package/__cjs/cache/index.cjs.map +1 -1
  6. package/__cjs/cache/index.d.cts +1 -1
  7. package/__cjs/cache/inmemory/entityStore.cjs +25 -10
  8. package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
  9. package/__cjs/cache/inmemory/helpers.cjs +12 -0
  10. package/__cjs/cache/inmemory/helpers.cjs.map +1 -1
  11. package/__cjs/cache/inmemory/helpers.d.cts +2 -1
  12. package/__cjs/cache/inmemory/inMemoryCache.cjs +34 -22
  13. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  14. package/__cjs/cache/inmemory/inMemoryCache.d.cts +3 -3
  15. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  16. package/__cjs/cache/inmemory/policies.cjs +7 -8
  17. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  18. package/__cjs/cache/inmemory/policies.d.cts +3 -4
  19. package/__cjs/cache/inmemory/readFromStore.cjs +3 -3
  20. package/__cjs/cache/inmemory/types.d.cts +3 -1
  21. package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
  22. package/__cjs/core/ApolloClient.cjs +14 -14
  23. package/__cjs/core/ObservableQuery.cjs +8 -8
  24. package/__cjs/core/QueryInfo.cjs +1 -1
  25. package/__cjs/core/QueryManager.cjs +12 -12
  26. package/__cjs/core/RefetchEventManager.cjs +3 -3
  27. package/__cjs/core/index.cjs.map +1 -1
  28. package/__cjs/core/index.d.cts +1 -1
  29. package/__cjs/core/types.d.cts +1 -1
  30. package/__cjs/incremental/handlers/graphql17Alpha9.cjs +1 -1
  31. package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
  32. package/__cjs/invariantErrorCodes.cjs +131 -116
  33. package/__cjs/link/core/ApolloLink.cjs +3 -3
  34. package/__cjs/link/http/checkFetcher.cjs +1 -1
  35. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
  36. package/__cjs/link/persisted-queries/index.cjs +2 -2
  37. package/__cjs/link/ws/index.cjs +1 -1
  38. package/__cjs/local-state/LocalState.cjs +11 -11
  39. package/__cjs/masking/maskDefinition.cjs +2 -2
  40. package/__cjs/masking/maskFragment.cjs +2 -2
  41. package/__cjs/masking/maskOperation.cjs +1 -1
  42. package/__cjs/masking/utils.cjs +3 -3
  43. package/__cjs/react/context/ApolloContext.cjs +1 -1
  44. package/__cjs/react/context/ApolloProvider.cjs +1 -1
  45. package/__cjs/react/hooks/internal/validateSuspenseHookOptions.cjs +2 -2
  46. package/__cjs/react/hooks/useApolloClient.cjs +1 -1
  47. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  48. package/__cjs/react/hooks/useBackgroundQuery.d.cts +2 -2
  49. package/__cjs/react/hooks/useLazyQuery.cjs +2 -2
  50. package/__cjs/react/hooks/useLoadableQuery.cjs +2 -2
  51. package/__cjs/react/hooks/useQuery.cjs.map +1 -1
  52. package/__cjs/react/hooks/useQuery.d.cts +15 -2
  53. package/__cjs/react/hooks/useSubscription.cjs +1 -1
  54. package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
  55. package/__cjs/react/hooks/useSubscription.d.cts +20 -1
  56. package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
  57. package/__cjs/react/hooks/useSuspenseQuery.d.cts +29 -29
  58. package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
  59. package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
  60. package/__cjs/react/ssr/prerenderStatic.cjs +2 -2
  61. package/__cjs/react/types/types.documentation.d.cts +12 -1
  62. package/__cjs/testing/core/mocking/mockLink.cjs +4 -4
  63. package/__cjs/utilities/graphql/DocumentTransform.cjs +1 -1
  64. package/__cjs/utilities/internal/coerceScalarFieldsToParsed.cjs +45 -12
  65. package/__cjs/utilities/internal/coerceScalarFieldsToParsed.cjs.map +1 -1
  66. package/__cjs/utilities/internal/getFragmentDefinition.cjs +3 -3
  67. package/__cjs/utilities/internal/getFragmentDefinition.cjs.map +1 -1
  68. package/__cjs/utilities/internal/getFragmentFromSelection.cjs +1 -1
  69. package/__cjs/utilities/internal/getFragmentQueryDocument.cjs +2 -2
  70. package/__cjs/utilities/internal/getMainDefinition.cjs +1 -1
  71. package/__cjs/utilities/internal/getQueryDefinition.cjs +1 -1
  72. package/__cjs/utilities/internal/index.cjs +6 -4
  73. package/__cjs/utilities/internal/index.cjs.map +1 -1
  74. package/__cjs/utilities/internal/index.d.cts +2 -1
  75. package/__cjs/utilities/internal/matchScalarList.cjs +12 -0
  76. package/__cjs/utilities/internal/matchScalarList.cjs.map +1 -0
  77. package/__cjs/utilities/internal/matchScalarList.d.cts +8 -0
  78. package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +1 -1
  79. package/__cjs/utilities/internal/shouldInclude.cjs +4 -4
  80. package/__cjs/utilities/internal/unwrapScalarType.cjs +12 -0
  81. package/__cjs/utilities/internal/unwrapScalarType.cjs.map +1 -0
  82. package/__cjs/utilities/internal/unwrapScalarType.d.cts +10 -0
  83. package/__cjs/utilities/internal/valueToObjectRepresentation.cjs +1 -1
  84. package/__cjs/version.cjs +1 -1
  85. package/cache/core/cache.d.ts +3 -3
  86. package/cache/core/cache.js +3 -3
  87. package/cache/core/cache.js.map +1 -1
  88. package/cache/index.d.ts +1 -1
  89. package/cache/index.js.map +1 -1
  90. package/cache/inmemory/entityStore.js +26 -11
  91. package/cache/inmemory/entityStore.js.map +1 -1
  92. package/cache/inmemory/helpers.d.ts +2 -1
  93. package/cache/inmemory/helpers.js +11 -0
  94. package/cache/inmemory/helpers.js.map +1 -1
  95. package/cache/inmemory/inMemoryCache.d.ts +3 -3
  96. package/cache/inmemory/inMemoryCache.js +36 -24
  97. package/cache/inmemory/inMemoryCache.js.map +1 -1
  98. package/cache/inmemory/key-extractor.js +1 -1
  99. package/cache/inmemory/policies.d.ts +3 -4
  100. package/cache/inmemory/policies.js +7 -8
  101. package/cache/inmemory/policies.js.map +1 -1
  102. package/cache/inmemory/readFromStore.js +3 -3
  103. package/cache/inmemory/types.d.ts +3 -1
  104. package/cache/inmemory/types.js.map +1 -1
  105. package/cache/inmemory/writeToStore.js +4 -4
  106. package/core/ApolloClient.js +14 -14
  107. package/core/ObservableQuery.js +8 -8
  108. package/core/QueryInfo.js +1 -1
  109. package/core/QueryManager.js +12 -12
  110. package/core/RefetchEventManager.js +3 -3
  111. package/core/index.d.ts +1 -1
  112. package/core/index.js.map +1 -1
  113. package/core/types.d.ts +1 -1
  114. package/core/types.js.map +1 -1
  115. package/incremental/handlers/graphql17Alpha9.js +1 -1
  116. package/incremental/handlers/notImplemented.js +1 -1
  117. package/invariantErrorCodes.js +131 -116
  118. package/link/core/ApolloLink.js +3 -3
  119. package/link/http/checkFetcher.js +1 -1
  120. package/link/http/parseAndCheckHttpResponse.js +1 -1
  121. package/link/persisted-queries/index.js +2 -2
  122. package/link/ws/index.js +1 -1
  123. package/local-state/LocalState.js +11 -11
  124. package/masking/maskDefinition.js +2 -2
  125. package/masking/maskFragment.js +2 -2
  126. package/masking/maskOperation.js +1 -1
  127. package/masking/utils.js +3 -3
  128. package/package.json +1 -1
  129. package/react/context/ApolloContext.js +1 -1
  130. package/react/context/ApolloProvider.js +1 -1
  131. package/react/hooks/internal/validateSuspenseHookOptions.js +2 -2
  132. package/react/hooks/useApolloClient.js +1 -1
  133. package/react/hooks/useBackgroundQuery.d.ts +2 -2
  134. package/react/hooks/useBackgroundQuery.js.map +1 -1
  135. package/react/hooks/useLazyQuery.js +2 -2
  136. package/react/hooks/useLoadableQuery.js +2 -2
  137. package/react/hooks/useQuery.d.ts +15 -2
  138. package/react/hooks/useQuery.js.map +1 -1
  139. package/react/hooks/useSubscription.d.ts +20 -1
  140. package/react/hooks/useSubscription.js +1 -1
  141. package/react/hooks/useSubscription.js.map +1 -1
  142. package/react/hooks/useSuspenseQuery.d.ts +29 -29
  143. package/react/hooks/useSuspenseQuery.js.map +1 -1
  144. package/react/hooks/useSyncExternalStore.js +1 -1
  145. package/react/hooks-compiled/internal/validateSuspenseHookOptions.js +2 -2
  146. package/react/hooks-compiled/useApolloClient.js +1 -1
  147. package/react/hooks-compiled/useBackgroundQuery.d.ts +2 -2
  148. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  149. package/react/hooks-compiled/useLazyQuery.js +2 -2
  150. package/react/hooks-compiled/useLoadableQuery.js +2 -2
  151. package/react/hooks-compiled/useQuery.d.ts +15 -2
  152. package/react/hooks-compiled/useQuery.js.map +1 -1
  153. package/react/hooks-compiled/useSubscription.d.ts +20 -1
  154. package/react/hooks-compiled/useSubscription.js +1 -1
  155. package/react/hooks-compiled/useSubscription.js.map +1 -1
  156. package/react/hooks-compiled/useSuspenseQuery.d.ts +29 -29
  157. package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
  158. package/react/hooks-compiled/useSyncExternalStore.js +1 -1
  159. package/react/internal/cache/QueryReference.js +1 -1
  160. package/react/ssr/prerenderStatic.js +2 -2
  161. package/react/types/types.documentation.d.ts +12 -1
  162. package/react/types/types.documentation.js.map +1 -1
  163. package/testing/core/mocking/mockLink.js +4 -4
  164. package/utilities/graphql/DocumentTransform.js +1 -1
  165. package/utilities/internal/coerceScalarFieldsToParsed.js +40 -11
  166. package/utilities/internal/coerceScalarFieldsToParsed.js.map +1 -1
  167. package/utilities/internal/getFragmentDefinition.js +3 -3
  168. package/utilities/internal/getFragmentDefinition.js.map +1 -1
  169. package/utilities/internal/getFragmentFromSelection.js +1 -1
  170. package/utilities/internal/getFragmentQueryDocument.js +2 -2
  171. package/utilities/internal/getMainDefinition.js +1 -1
  172. package/utilities/internal/getQueryDefinition.js +1 -1
  173. package/utilities/internal/index.d.ts +2 -1
  174. package/utilities/internal/index.js +2 -1
  175. package/utilities/internal/index.js.map +1 -1
  176. package/utilities/internal/matchScalarList.d.ts +8 -0
  177. package/utilities/internal/matchScalarList.js +9 -0
  178. package/utilities/internal/matchScalarList.js.map +1 -0
  179. package/utilities/internal/removeDirectivesFromDocument.js +1 -1
  180. package/utilities/internal/shouldInclude.js +4 -4
  181. package/utilities/internal/unwrapScalarType.d.ts +10 -0
  182. package/utilities/internal/unwrapScalarType.js +9 -0
  183. package/utilities/internal/unwrapScalarType.js.map +1 -0
  184. package/utilities/internal/valueToObjectRepresentation.js +1 -1
  185. package/version.js +1 -1
  186. package/__cjs/utilities/internal/getUnwrappedType.cjs +0 -20
  187. package/__cjs/utilities/internal/getUnwrappedType.cjs.map +0 -1
  188. package/__cjs/utilities/internal/getUnwrappedType.d.cts +0 -8
  189. package/utilities/internal/getUnwrappedType.d.ts +0 -8
  190. package/utilities/internal/getUnwrappedType.js +0 -17
  191. package/utilities/internal/getUnwrappedType.js.map +0 -1
@@ -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", 107);
85
+ (0, invariant_1.invariant)(typeof dataId === "string", 108);
86
86
  // Parse all scalars before merging so that the storeObjectReconciler can
87
87
  // deep compare the parsed value with the existing value
88
88
  incoming = this.coerceStoreObject(incoming, (scalar, value) => scalar.coerceToParsed(value), incoming.__typename ||
@@ -189,7 +189,7 @@ class EntityStore {
189
189
  if (environment_1.__DEV__) {
190
190
  const checkReference = (ref) => {
191
191
  if (this.lookup(ref.__ref) === undefined) {
192
- __DEV__ && invariant_1.invariant.warn(108, ref);
192
+ __DEV__ && invariant_1.invariant.warn(109, ref);
193
193
  return true;
194
194
  }
195
195
  };
@@ -218,7 +218,7 @@ class EntityStore {
218
218
  }
219
219
  }
220
220
  if (seenReference && someNonReference !== undefined) {
221
- __DEV__ && invariant_1.invariant.warn(109, someNonReference);
221
+ __DEV__ && invariant_1.invariant.warn(110, someNonReference);
222
222
  break;
223
223
  }
224
224
  }
@@ -319,22 +319,37 @@ class EntityStore {
319
319
  }
320
320
  let changed = false;
321
321
  const entries = Object.entries(obj).map(([storeFieldName, value]) => {
322
- const scalar = this.policies.getScalarForField(typename, (0, helpers_js_1.fieldNameFromStoreName)(storeFieldName));
323
- const newValue = this.coerceValue(value, coerce, scalar);
322
+ const fieldName = (0, helpers_js_1.fieldNameFromStoreName)(storeFieldName);
323
+ const scalarType = this.policies.getScalarTypeForField(typename, fieldName);
324
+ const newValue = this.coerceValue(value, coerce, scalarType, `${typename}.${fieldName}`);
324
325
  changed ||= newValue !== value;
325
326
  return [storeFieldName, newValue];
326
327
  });
327
328
  return changed ? Object.fromEntries(entries) : obj;
328
329
  }
329
- coerceValue(value, coerce, scalar) {
330
+ coerceValue(value, coerce, scalarType, coordinate) {
330
331
  if (value == null) {
331
332
  return value;
332
333
  }
333
- if (Array.isArray(value)) {
334
- return value.map((item) => this.coerceValue(item, coerce, scalar));
334
+ if (scalarType) {
335
+ const match = (0, internal_1.matchScalarList)(scalarType);
336
+ if (match) {
337
+ if (Array.isArray(value)) {
338
+ return value.map((item) => this.coerceValue(item, coerce, match[1], coordinate));
339
+ }
340
+ else {
341
+ if (environment_1.__DEV__) {
342
+ __DEV__ && invariant_1.invariant.warn(111, coordinate, scalarType, (0, internal_1.unwrapScalarType)(scalarType));
343
+ }
344
+ }
345
+ }
346
+ const scalar = this.policies.cache.getScalar((0, internal_1.unwrapScalarType)(scalarType));
347
+ if (scalar) {
348
+ return coerce(scalar, value);
349
+ }
335
350
  }
336
- if (scalar) {
337
- return coerce(scalar, value);
351
+ if (Array.isArray(value)) {
352
+ return value.map((item) => this.coerceValue(item, coerce, scalarType, coordinate));
338
353
  }
339
354
  if ((0, internal_1.isPlainObject)(value) && "__typename" in value) {
340
355
  return this.coerceStoreObject(value, coerce);