@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
@@ -1,4 +1,4 @@
1
- import type { DocumentNode, SelectionSetNode } from "graphql";
1
+ import type { DocumentNode, SelectionSetNode, TypeNode } from "graphql";
2
2
  import type { Reference, StoreObject, StoreValue } from "@apollo/client/utilities";
3
3
  import type { FragmentMap, FragmentMapFunction } from "@apollo/client/utilities/internal";
4
4
  import { DeepMerger } from "@apollo/client/utilities/internal";
@@ -26,4 +26,5 @@ export declare function extractFragmentContext(document: DocumentNode, fragments
26
26
  fragmentMap: FragmentMap;
27
27
  lookupFragment: FragmentMapFunction;
28
28
  };
29
+ export declare function getScalarTypeFromTypeNode(node: TypeNode): string;
29
30
  //# sourceMappingURL=helpers.d.ts.map
@@ -1,3 +1,4 @@
1
+ import { Kind } from "graphql";
1
2
  import { isReference } from "@apollo/client/utilities";
2
3
  import { compact, createFragmentMap, DeepMerger, getFragmentDefinitions, isArray, isField, isNonNullObject, resultKeyNameFromField, shouldInclude, } from "@apollo/client/utilities/internal";
3
4
  export const { hasOwnProperty: hasOwn } = Object.prototype;
@@ -79,4 +80,14 @@ export function extractFragmentContext(document, fragments) {
79
80
  },
80
81
  };
81
82
  }
83
+ export function getScalarTypeFromTypeNode(node) {
84
+ switch (node.kind) {
85
+ case Kind.NAMED_TYPE:
86
+ return node.name.value;
87
+ case Kind.LIST_TYPE:
88
+ return `[${getScalarTypeFromTypeNode(node.type)}]`;
89
+ case Kind.NON_NULL_TYPE:
90
+ return getScalarTypeFromTypeNode(node.type);
91
+ }
92
+ }
82
93
  //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/cache/inmemory/helpers.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAKvD,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,UAAU,EACV,sBAAsB,EACtB,OAAO,EACP,OAAO,EACP,eAAe,EACf,sBAAsB,EACtB,aAAa,GACd,MAAM,mCAAmC,CAAC;AAM3C,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC;AAE3D,MAAM,UAAU,uBAAuB,CACrC,EAAE,UAAU,EAAE,EAAE,EAAE,GAAG,EAAyB,EAC9C,OAA0B;IAE1B,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,SAAS;gBACf,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE;oBACnB,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE;wBACvB,CAAC,CAAC,KAAK,CAAC,CAAC;QACb,CAAC;QAED,qDAAqD;QACrD,IAAI,EAAE,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YAC9B,EAAE,GAAG,GAAG,CAAC;QACX,CAAC;QAED,IAAI,EAAE,IAAI,I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OAAO,GAAG,IAAI,IAAI,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n DocumentNode,\n FragmentDefinitionNode,\n SelectionSetNode,\n} from \"graphql\";\n\nimport type {\n Reference,\n StoreObject,\n StoreValue,\n} from \"@apollo/client/utilities\";\nimport { isReference } from \"@apollo/client/utilities\";\nimport type {\n FragmentMap,\n FragmentMapFunction,\n} from \"@apollo/client/utilities/internal\";\nimport {\n compact,\n createFragmentMap,\n DeepMerger,\n getFragmentDefinitions,\n isArray,\n isField,\n isNonNullObject,\n resultKeyNameFromField,\n shouldInclude,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { FragmentRegistryAPI } from \"./fragmentRegistry.js\";\nimport type { KeyFieldsContext } from \"./policies.js\";\nimport type { InMemoryCacheConfig, NormalizedCache } from \"./types.js\";\n\nexport const { hasOwnProperty: hasOwn } = Object.prototype;\n\nexport function defaultDataIdFromObject(\n { __typename, id, _id }: Readonly<StoreObject>,\n context?: KeyFieldsContext\n): string | undefined {\n if (typeof __typename === \"string\") {\n if (context) {\n context.keyObject =\n id != null ? { id }\n : _id != null ? { _id }\n : void 0;\n }\n\n // If there is no object.id, fall back to object._id.\n if (id == null && _id != null) {\n id = _id;\n }\n\n if (id != null) {\n return `${__typename}:${\n typeof id === \"number\" || typeof id === \"string\" ?\n id\n : JSON.stringify(id)\n }`;\n }\n }\n}\n\nconst defaultConfig: InMemoryCacheConfig = {\n dataIdFromObject: defaultDataIdFromObject,\n resultCaching: true,\n};\n\nexport function normalizeConfig(config: InMemoryCacheConfig) {\n return compact(defaultConfig, config);\n}\n\nexport function getTypenameFromStoreObject(\n store: NormalizedCache,\n objectOrReference: StoreObject | Reference\n): string | undefined {\n return isReference(objectOrReference) ?\n (store.get(objectOrReference.__ref, \"__typename\") as string)\n : objectOrReference && objectOrReference.__typename;\n}\n\nexport const TypeOrFieldNameRegExp = /^[_a-z][_0-9a-z]*/i;\n\nexport function fieldNameFromStoreName(storeFieldName: string): string {\n const match = storeFieldName.match(TypeOrFieldNameRegExp);\n return match ? match[0] : storeFieldName;\n}\n\nexport function selectionSetMatchesResult(\n selectionSet: SelectionSetNode,\n result: Record<string, any>,\n variables?: Record<string, any>\n): boolean {\n if (isNonNullObject(result)) {\n return isArray(result) ?\n result.every((item) =>\n selectionSetMatchesResult(selectionSet, item, variables)\n )\n : selectionSet.selections.every((field) => {\n if (isField(field) && shouldInclude(field, variables)) {\n const key = resultKeyNameFromField(field);\n return (\n hasOwn.call(result, key) &&\n (!field.selectionSet ||\n selectionSetMatchesResult(\n field.selectionSet,\n result[key],\n variables\n ))\n );\n }\n // If the selection has been skipped with @skip(true) or\n // @include(false), it should not count against the matching. If\n // the selection is not a field, it must be a fragment (inline or\n // named). We will determine if selectionSetMatchesResult for that\n // fragment when we get to it, so for now we return true.\n return true;\n });\n }\n return false;\n}\n\nexport function storeValueIsStoreObject(\n value: StoreValue\n): value is StoreObject {\n return isNonNullObject(value) && !isReference(value) && !isArray(value);\n}\n\nexport function makeProcessedFieldsMerger() {\n return new DeepMerger();\n}\n\nexport function extractFragmentContext(\n document: DocumentNode,\n fragments?: FragmentRegistryAPI\n): {\n fragmentMap: FragmentMap;\n lookupFragment: FragmentMapFunction;\n} {\n // FragmentMap consisting only of fragments defined directly in document, not\n // including other fragments registered in the FragmentRegistry.\n const fragmentMap = createFragmentMap(getFragmentDefinitions(document));\n return {\n fragmentMap,\n lookupFragment(name) {\n let def: FragmentDefinitionNode | null = fragmentMap[name];\n if (!def && fragments) {\n def = fragments.lookup(name);\n }\n return def || null;\n },\n };\n}\n"]}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/cache/inmemory/helpers.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAO/B,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAKvD,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,UAAU,EACV,sBAAsB,EACt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CAAC,CAAC;IACT,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,KAAiB;IAEjB,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,OAAO,IAAI,UAAU,EAAE,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,QAAsB,EACtB,SAA+B;IAK/B,6EAA6E;IAC7E,gEAAgE;IAChE,MAAM,WAAW,GAAG,iBAAiB,CAAC,sBAAsB,CAAC,QAAQ,CAAC,CAAC,CAAC;IACxE,OAAO;QACL,WAAW;QACX,cAAc,CAAC,IAAI;YACjB,IAAI,GAAG,GAAkC,WAAW,CAAC,IAAI,CAAC,CAAC;YAC3D,IAAI,CAAC,GAAG,IAAI,SAAS,EAAE,CAAC;gBACtB,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;YACD,OAAO,GAAG,IAAI,IAAI,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,IAAc;IACtD,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,IAAI,CAAC,UAAU;YAClB,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;QACzB,KAAK,IAAI,CAAC,SAAS;YACjB,OAAO,IAAI,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;QACrD,KAAK,IAAI,CAAC,aAAa;YACrB,OAAO,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;AACH,CAAC","sourcesContent":["import type {\n DocumentNode,\n FragmentDefinitionNode,\n SelectionSetNode,\n TypeNode,\n} from \"graphql\";\nimport { Kind } from \"graphql\";\n\nimport type {\n Reference,\n StoreObject,\n StoreValue,\n} from \"@apollo/client/utilities\";\nimport { isReference } from \"@apollo/client/utilities\";\nimport type {\n FragmentMap,\n FragmentMapFunction,\n} from \"@apollo/client/utilities/internal\";\nimport {\n compact,\n createFragmentMap,\n DeepMerger,\n getFragmentDefinitions,\n isArray,\n isField,\n isNonNullObject,\n resultKeyNameFromField,\n shouldInclude,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { FragmentRegistryAPI } from \"./fragmentRegistry.js\";\nimport type { KeyFieldsContext } from \"./policies.js\";\nimport type { InMemoryCacheConfig, NormalizedCache } from \"./types.js\";\n\nexport const { hasOwnProperty: hasOwn } = Object.prototype;\n\nexport function defaultDataIdFromObject(\n { __typename, id, _id }: Readonly<StoreObject>,\n context?: KeyFieldsContext\n): string | undefined {\n if (typeof __typename === \"string\") {\n if (context) {\n context.keyObject =\n id != null ? { id }\n : _id != null ? { _id }\n : void 0;\n }\n\n // If there is no object.id, fall back to object._id.\n if (id == null && _id != null) {\n id = _id;\n }\n\n if (id != null) {\n return `${__typename}:${\n typeof id === \"number\" || typeof id === \"string\" ?\n id\n : JSON.stringify(id)\n }`;\n }\n }\n}\n\nconst defaultConfig: InMemoryCacheConfig = {\n dataIdFromObject: defaultDataIdFromObject,\n resultCaching: true,\n};\n\nexport function normalizeConfig(config: InMemoryCacheConfig) {\n return compact(defaultConfig, config);\n}\n\nexport function getTypenameFromStoreObject(\n store: NormalizedCache,\n objectOrReference: StoreObject | Reference\n): string | undefined {\n return isReference(objectOrReference) ?\n (store.get(objectOrReference.__ref, \"__typename\") as string)\n : objectOrReference && objectOrReference.__typename;\n}\n\nexport const TypeOrFieldNameRegExp = /^[_a-z][_0-9a-z]*/i;\n\nexport function fieldNameFromStoreName(storeFieldName: string): string {\n const match = storeFieldName.match(TypeOrFieldNameRegExp);\n return match ? match[0] : storeFieldName;\n}\n\nexport function selectionSetMatchesResult(\n selectionSet: SelectionSetNode,\n result: Record<string, any>,\n variables?: Record<string, any>\n): boolean {\n if (isNonNullObject(result)) {\n return isArray(result) ?\n result.every((item) =>\n selectionSetMatchesResult(selectionSet, item, variables)\n )\n : selectionSet.selections.every((field) => {\n if (isField(field) && shouldInclude(field, variables)) {\n const key = resultKeyNameFromField(field);\n return (\n hasOwn.call(result, key) &&\n (!field.selectionSet ||\n selectionSetMatchesResult(\n field.selectionSet,\n result[key],\n variables\n ))\n );\n }\n // If the selection has been skipped with @skip(true) or\n // @include(false), it should not count against the matching. If\n // the selection is not a field, it must be a fragment (inline or\n // named). We will determine if selectionSetMatchesResult for that\n // fragment when we get to it, so for now we return true.\n return true;\n });\n }\n return false;\n}\n\nexport function storeValueIsStoreObject(\n value: StoreValue\n): value is StoreObject {\n return isNonNullObject(value) && !isReference(value) && !isArray(value);\n}\n\nexport function makeProcessedFieldsMerger() {\n return new DeepMerger();\n}\n\nexport function extractFragmentContext(\n document: DocumentNode,\n fragments?: FragmentRegistryAPI\n): {\n fragmentMap: FragmentMap;\n lookupFragment: FragmentMapFunction;\n} {\n // FragmentMap consisting only of fragments defined directly in document, not\n // including other fragments registered in the FragmentRegistry.\n const fragmentMap = createFragmentMap(getFragmentDefinitions(document));\n return {\n fragmentMap,\n lookupFragment(name) {\n let def: FragmentDefinitionNode | null = fragmentMap[name];\n if (!def && fragments) {\n def = fragments.lookup(name);\n }\n return def || null;\n },\n };\n}\n\nexport function getScalarTypeFromTypeNode(node: TypeNode): string {\n switch (node.kind) {\n case Kind.NAMED_TYPE:\n return node.name.value;\n case Kind.LIST_TYPE:\n return `[${getScalarTypeFromTypeNode(node.type)}]`;\n case Kind.NON_NULL_TYPE:\n return getScalarTypeFromTypeNode(node.type);\n }\n}\n"]}
@@ -8,7 +8,7 @@ import type { Scalar } from "../core/Scalar.js";
8
8
  import type { Cache } from "../core/types/Cache.js";
9
9
  import { Policies } from "./policies.js";
10
10
  import { makeVar } from "./reactiveVars.js";
11
- import type { DiffIncrementalInfo, InMemoryCacheConfig, KnownScalars, NormalizedCacheObject } from "./types.js";
11
+ import type { DiffIncrementalInfo, InMemoryCacheConfig, KnownScalars, NormalizedCacheObject, ScalarType } from "./types.js";
12
12
  type BroadcastOptions = Pick<Cache.BatchOptions<InMemoryCache>, "optimistic" | "onWatchUpdated">;
13
13
  export declare namespace InMemoryCache {
14
14
  type ScalarsOption = {
@@ -45,8 +45,8 @@ export declare class InMemoryCache extends ApolloCache {
45
45
  private resetResultCache;
46
46
  getRootTypename(operation: OperationTypeNode): string;
47
47
  getScalar<TKey extends keyof ApolloCache.Scalars>(key: TKey): ApolloCache.GetScalarType<TKey> extends (Scalar<infer TSerialized, infer TParsed>) ? IsLooselyEqual<TSerialized, TParsed> extends true ? ApolloCache.GetScalarType<TKey> | undefined : ApolloCache.GetScalarType<TKey> : never;
48
- /** Get a scalar instance for a field in a type */
49
- getScalarForField<TSerialized = unknown, TParsed = unknown>(typename: string, fieldName: string): Scalar<TSerialized, TParsed> | undefined;
48
+ /** Get the configured scalar type for a field */
49
+ getScalarTypeForField(typename: string, fieldName: string): ScalarType | undefined;
50
50
  configuresScalars(): boolean;
51
51
  /**
52
52
  * Serializes scalar values in the variables object
@@ -2,11 +2,11 @@ import { equal } from "@wry/equality";
2
2
  import { wrap } from "optimism";
3
3
  import { addTypenameToDocument, cacheSizes, canonicalStringify, DocumentTransform, isReference, print, } from "@apollo/client/utilities";
4
4
  import { __DEV__ } from "@apollo/client/utilities/environment";
5
- import { getInMemoryCacheMemoryInternals, getOperationDefinition, getUnwrappedType, isPlainObject, } from "@apollo/client/utilities/internal";
5
+ import { getInMemoryCacheMemoryInternals, getOperationDefinition, isPlainObject, matchScalarList, unwrapScalarType, } from "@apollo/client/utilities/internal";
6
6
  import { invariant } from "@apollo/client/utilities/invariant";
7
7
  import { ApolloCache } from "../core/cache.js";
8
8
  import { EntityStore, supportsResultCaching } from "./entityStore.js";
9
- import { hasOwn, normalizeConfig } from "./helpers.js";
9
+ import { getScalarTypeFromTypeNode, hasOwn, normalizeConfig, } from "./helpers.js";
10
10
  import { Policies } from "./policies.js";
11
11
  import { forgetCache, makeVar, recallCache } from "./reactiveVars.js";
12
12
  import { StoreReader } from "./readFromStore.js";
@@ -96,9 +96,9 @@ export class InMemoryCache extends ApolloCache {
96
96
  getScalar(key) {
97
97
  return this.config.scalars?.[key];
98
98
  }
99
- /** Get a scalar instance for a field in a type */
100
- getScalarForField(typename, fieldName) {
101
- return this.policies.getScalarForField(typename, fieldName);
99
+ /** Get the configured scalar type for a field */
100
+ getScalarTypeForField(typename, fieldName) {
101
+ return this.policies.getScalarTypeForField(typename, fieldName);
102
102
  }
103
103
  configuresScalars() {
104
104
  return !!this.config.scalars;
@@ -110,7 +110,7 @@ export class InMemoryCache extends ApolloCache {
110
110
  return variables;
111
111
  }
112
112
  const variableTypes = getOperationDefinition(document)?.variableDefinitions?.reduce((memo, node) => {
113
- memo[node.variable.name.value] = getUnwrappedType(node.type);
113
+ memo[node.variable.name.value] = getScalarTypeFromTypeNode(node.type);
114
114
  return memo;
115
115
  }, {});
116
116
  if (!variableTypes || Object.keys(variableTypes).length === 0) {
@@ -118,47 +118,59 @@ export class InMemoryCache extends ApolloCache {
118
118
  }
119
119
  return this.serializeVariablesValue(variables, variableTypes);
120
120
  }
121
- serializeVariablesValue(value, variableTypes, scalar) {
122
- if (Array.isArray(value)) {
123
- return this.serializeInputArray(value, variableTypes, scalar);
121
+ serializeVariablesValue(value, variableTypes, scalarType, coordinate) {
122
+ if (value == null) {
123
+ return value;
124
+ }
125
+ if (scalarType) {
126
+ const match = matchScalarList(scalarType);
127
+ if (match) {
128
+ if (Array.isArray(value)) {
129
+ return this.serializeInputArray(value, variableTypes, match[1], coordinate);
130
+ }
131
+ else if (__DEV__) {
132
+ __DEV__ && invariant.warn(112, coordinate, scalarType, unwrapScalarType(scalarType));
133
+ }
134
+ }
135
+ const scalar = this.getScalar(unwrapScalarType(scalarType));
136
+ if (scalar) {
137
+ return scalar.coerceToSerialized(value);
138
+ }
124
139
  }
125
- if (scalar && value != null) {
126
- return scalar.coerceToSerialized(value);
140
+ if (Array.isArray(value)) {
141
+ return this.serializeInputArray(value, variableTypes, undefined, coordinate);
127
142
  }
128
143
  if (isPlainObject(value)) {
129
- return this.serializeInputObject(value, variableTypes);
144
+ return this.serializeInputObject(value, variableTypes, coordinate);
130
145
  }
131
146
  return value;
132
147
  }
133
- serializeInputArray(value, variableTypes, scalar) {
148
+ serializeInputArray(value, variableTypes, scalarType, coordinate) {
134
149
  let changed = false;
135
150
  const newValue = value.map((item) => {
136
- const newItem = this.serializeVariablesValue(item, variableTypes, scalar);
151
+ const newItem = this.serializeVariablesValue(item, variableTypes, scalarType, coordinate);
137
152
  changed ||= newItem !== item;
138
153
  return newItem;
139
154
  });
140
155
  return changed ? newValue : value;
141
156
  }
142
- serializeInputObject(value, variableTypes) {
157
+ serializeInputObject(value, variableTypes, coordinate) {
143
158
  let changed = false;
144
159
  const entries = Object.entries(value).map(([name, value]) => {
145
160
  const type = variableTypes[name];
161
+ const fieldCoordinate = coordinate ? `${coordinate}.${name}` : name;
146
162
  if (!type) {
147
163
  return [name, value];
148
164
  }
149
- const inputObject = this.config.inputObjects?.[type];
165
+ const inputObject = this.config.inputObjects?.[unwrapScalarType(type)];
150
166
  if (inputObject) {
151
- const newValue = this.serializeVariablesValue(value, inputObject.fields);
152
- changed ||= newValue !== value;
153
- return [name, newValue];
154
- }
155
- const scalar = this.getScalar(type);
156
- if (scalar) {
157
- const newValue = this.serializeVariablesValue(value, variableTypes, scalar);
167
+ const newValue = this.serializeVariablesValue(value, inputObject.fields, undefined, fieldCoordinate);
158
168
  changed ||= newValue !== value;
159
169
  return [name, newValue];
160
170
  }
161
- return [name, value];
171
+ const newValue = this.serializeVariablesValue(value, variableTypes, type, fieldCoordinate);
172
+ changed ||= newValue !== value;
173
+ return [name, newValue];
162
174
  });
163
175
  return changed ? Object.fromEntries(entries) : value;
164
176
  }