@apollo/client 4.4.0-alpha.0 → 4.4.0-alpha.1

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 (280) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/__cjs/cache/core/cache.cjs +50 -15
  3. package/__cjs/cache/core/cache.cjs.map +1 -1
  4. package/__cjs/cache/core/cache.d.cts +22 -4
  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 +4 -4
  8. package/__cjs/cache/inmemory/helpers.cjs +12 -0
  9. package/__cjs/cache/inmemory/helpers.cjs.map +1 -1
  10. package/__cjs/cache/inmemory/helpers.d.cts +10 -5
  11. package/__cjs/cache/inmemory/inMemoryCache.cjs +13 -2
  12. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  13. package/__cjs/cache/inmemory/inMemoryCache.d.cts +19 -4
  14. package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
  15. package/__cjs/cache/inmemory/policies.cjs +7 -7
  16. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  17. package/__cjs/cache/inmemory/readFromStore.cjs +86 -31
  18. package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
  19. package/__cjs/cache/inmemory/types.d.cts +11 -2
  20. package/__cjs/cache/inmemory/writeToStore.cjs +27 -24
  21. package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
  22. package/__cjs/cache/inmemory/writeToStore.d.cts +5 -4
  23. package/__cjs/core/ApolloClient.cjs +19 -15
  24. package/__cjs/core/ApolloClient.cjs.map +1 -1
  25. package/__cjs/core/ApolloClient.d.cts +1 -0
  26. package/__cjs/core/ObservableQuery.cjs +8 -8
  27. package/__cjs/core/QueryInfo.cjs +1 -1
  28. package/__cjs/core/QueryManager.cjs +12 -12
  29. package/__cjs/core/RefetchEventManager.cjs +3 -3
  30. package/__cjs/errors/CombinedGraphQLErrors.cjs +3 -7
  31. package/__cjs/errors/CombinedGraphQLErrors.cjs.map +1 -1
  32. package/__cjs/errors/CombinedGraphQLErrors.d.cts +2 -2
  33. package/__cjs/errors/CombinedProtocolErrors.cjs +3 -8
  34. package/__cjs/errors/CombinedProtocolErrors.cjs.map +1 -1
  35. package/__cjs/errors/CombinedProtocolErrors.d.cts +2 -2
  36. package/__cjs/incremental/handlers/graphql17Alpha9.cjs +2 -2
  37. package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
  38. package/__cjs/invariantErrorCodes.cjs +125 -120
  39. package/__cjs/link/core/ApolloLink.cjs +3 -3
  40. package/__cjs/link/http/checkFetcher.cjs +1 -1
  41. package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
  42. package/__cjs/link/persisted-queries/index.cjs +2 -2
  43. package/__cjs/link/ws/index.cjs +1 -1
  44. package/__cjs/local-state/LocalState.cjs +23 -22
  45. package/__cjs/local-state/LocalState.cjs.map +1 -1
  46. package/__cjs/masking/maskDefinition.cjs +20 -2
  47. package/__cjs/masking/maskDefinition.cjs.map +1 -1
  48. package/__cjs/masking/maskFragment.cjs +2 -2
  49. package/__cjs/masking/maskOperation.cjs +1 -1
  50. package/__cjs/masking/utils.cjs +3 -3
  51. package/__cjs/react/context/ApolloContext.cjs +1 -1
  52. package/__cjs/react/context/ApolloProvider.cjs +1 -1
  53. package/__cjs/react/hooks/internal/validateSuspenseHookOptions.cjs +2 -2
  54. package/__cjs/react/hooks/useApolloClient.cjs +1 -1
  55. package/__cjs/react/hooks/useFragment.cjs +8 -2
  56. package/__cjs/react/hooks/useFragment.cjs.map +1 -1
  57. package/__cjs/react/hooks/useLazyQuery.cjs +2 -2
  58. package/__cjs/react/hooks/useLoadableQuery.cjs +2 -2
  59. package/__cjs/react/hooks/useSubscription.cjs +1 -1
  60. package/__cjs/react/hooks/useSuspenseFragment.cjs +10 -4
  61. package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
  62. package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
  63. package/__cjs/react/internal/cache/FragmentReference.cjs +2 -2
  64. package/__cjs/react/internal/cache/FragmentReference.cjs.map +1 -1
  65. package/__cjs/react/internal/cache/FragmentReference.d.cts +4 -5
  66. package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
  67. package/__cjs/react/internal/cache/SuspenseCache.cjs +3 -3
  68. package/__cjs/react/internal/cache/SuspenseCache.cjs.map +1 -1
  69. package/__cjs/react/internal/cache/SuspenseCache.d.cts +4 -5
  70. package/__cjs/react/internal/cache/types.d.cts +0 -5
  71. package/__cjs/react/ssr/prerenderStatic.cjs +2 -2
  72. package/__cjs/testing/core/mocking/mockLink.cjs +4 -4
  73. package/__cjs/utilities/graphql/DocumentTransform.cjs +1 -1
  74. package/__cjs/utilities/internal/DeepMerger.cjs +6 -2
  75. package/__cjs/utilities/internal/DeepMerger.cjs.map +1 -1
  76. package/__cjs/utilities/internal/DeepMerger.d.cts +13 -3
  77. package/__cjs/utilities/internal/constants.cjs +33 -1
  78. package/__cjs/utilities/internal/constants.cjs.map +1 -1
  79. package/__cjs/utilities/internal/constants.d.cts +32 -0
  80. package/__cjs/utilities/internal/createArgumentNode.cjs +14 -0
  81. package/__cjs/utilities/internal/createArgumentNode.cjs.map +1 -0
  82. package/__cjs/utilities/internal/createArgumentNode.d.cts +3 -0
  83. package/__cjs/utilities/internal/createDirectiveNode.cjs +14 -0
  84. package/__cjs/utilities/internal/createDirectiveNode.cjs.map +1 -0
  85. package/__cjs/utilities/internal/createDirectiveNode.d.cts +3 -0
  86. package/__cjs/utilities/internal/createFragmentSpreadNode.cjs +4 -1
  87. package/__cjs/utilities/internal/createFragmentSpreadNode.cjs.map +1 -1
  88. package/__cjs/utilities/internal/createFragmentSpreadNode.d.cts +3 -2
  89. package/__cjs/utilities/internal/createValueNode.cjs +27 -0
  90. package/__cjs/utilities/internal/createValueNode.cjs.map +1 -0
  91. package/__cjs/utilities/internal/createValueNode.d.cts +12 -0
  92. package/__cjs/utilities/internal/equalByQuery.cjs +8 -8
  93. package/__cjs/utilities/internal/equalByQuery.cjs.map +1 -1
  94. package/__cjs/utilities/internal/equalByQuery.d.cts +2 -3
  95. package/__cjs/utilities/internal/getFragmentDefinition.cjs +3 -3
  96. package/__cjs/utilities/internal/getFragmentDefinition.cjs.map +1 -1
  97. package/__cjs/utilities/internal/getFragmentFromSelection.cjs +1 -1
  98. package/__cjs/utilities/internal/getFragmentQueryDocument.cjs +10 -2
  99. package/__cjs/utilities/internal/getFragmentQueryDocument.cjs.map +1 -1
  100. package/__cjs/utilities/internal/getFragmentScope.cjs +23 -0
  101. package/__cjs/utilities/internal/getFragmentScope.cjs.map +1 -0
  102. package/__cjs/utilities/internal/getFragmentScope.d.cts +13 -0
  103. package/__cjs/utilities/internal/getFragmentVariables.cjs +14 -15
  104. package/__cjs/utilities/internal/getFragmentVariables.cjs.map +1 -1
  105. package/__cjs/utilities/internal/getFragmentVariables.d.cts +8 -4
  106. package/__cjs/utilities/internal/getMainDefinition.cjs +1 -1
  107. package/__cjs/utilities/internal/getQueryDefinition.cjs +1 -1
  108. package/__cjs/utilities/internal/index.cjs +9 -2
  109. package/__cjs/utilities/internal/index.cjs.map +1 -1
  110. package/__cjs/utilities/internal/index.d.cts +5 -1
  111. package/__cjs/utilities/internal/isNonEmptyObject.cjs +13 -0
  112. package/__cjs/utilities/internal/isNonEmptyObject.cjs.map +1 -0
  113. package/__cjs/utilities/internal/isNonEmptyObject.d.cts +7 -0
  114. package/__cjs/utilities/internal/isNonNullObject.cjs.map +1 -1
  115. package/__cjs/utilities/internal/isNonNullObject.d.cts +1 -1
  116. package/__cjs/utilities/internal/mapObservableFragment.cjs +14 -9
  117. package/__cjs/utilities/internal/mapObservableFragment.cjs.map +1 -1
  118. package/__cjs/utilities/internal/mapObservableFragment.d.cts +5 -1
  119. package/__cjs/utilities/internal/mergeDeepArray.cjs +2 -2
  120. package/__cjs/utilities/internal/mergeDeepArray.cjs.map +1 -1
  121. package/__cjs/utilities/internal/mergeDeepArray.d.cts +2 -1
  122. package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +1 -1
  123. package/__cjs/utilities/internal/removeFragmentSpreads.cjs +55 -2
  124. package/__cjs/utilities/internal/removeFragmentSpreads.cjs.map +1 -1
  125. package/__cjs/utilities/internal/removeFragmentSpreads.d.cts +17 -1
  126. package/__cjs/utilities/internal/shouldInclude.cjs +4 -4
  127. package/__cjs/utilities/internal/types/FragmentInfo.cjs +3 -0
  128. package/__cjs/utilities/internal/types/FragmentInfo.cjs.map +1 -0
  129. package/__cjs/utilities/internal/types/FragmentInfo.d.cts +14 -0
  130. package/__cjs/utilities/internal/types/ObjectWithFragmentInfo.cjs +3 -0
  131. package/__cjs/utilities/internal/types/ObjectWithFragmentInfo.cjs.map +1 -0
  132. package/__cjs/utilities/internal/types/ObjectWithFragmentInfo.d.cts +13 -0
  133. package/__cjs/utilities/internal/valueToObjectRepresentation.cjs +1 -1
  134. package/__cjs/version.cjs +1 -1
  135. package/cache/core/cache.d.ts +22 -4
  136. package/cache/core/cache.js +51 -16
  137. package/cache/core/cache.js.map +1 -1
  138. package/cache/index.d.ts +1 -1
  139. package/cache/index.js.map +1 -1
  140. package/cache/inmemory/entityStore.js +4 -4
  141. package/cache/inmemory/helpers.d.ts +10 -5
  142. package/cache/inmemory/helpers.js +12 -1
  143. package/cache/inmemory/helpers.js.map +1 -1
  144. package/cache/inmemory/inMemoryCache.d.ts +19 -4
  145. package/cache/inmemory/inMemoryCache.js +14 -3
  146. package/cache/inmemory/inMemoryCache.js.map +1 -1
  147. package/cache/inmemory/key-extractor.js +1 -1
  148. package/cache/inmemory/policies.js +7 -7
  149. package/cache/inmemory/policies.js.map +1 -1
  150. package/cache/inmemory/readFromStore.js +89 -34
  151. package/cache/inmemory/readFromStore.js.map +1 -1
  152. package/cache/inmemory/types.d.ts +11 -2
  153. package/cache/inmemory/types.js.map +1 -1
  154. package/cache/inmemory/writeToStore.d.ts +5 -4
  155. package/cache/inmemory/writeToStore.js +30 -27
  156. package/cache/inmemory/writeToStore.js.map +1 -1
  157. package/core/ApolloClient.d.ts +1 -0
  158. package/core/ApolloClient.js +20 -16
  159. package/core/ApolloClient.js.map +1 -1
  160. package/core/ObservableQuery.js +8 -8
  161. package/core/QueryInfo.js +1 -1
  162. package/core/QueryManager.js +12 -12
  163. package/core/RefetchEventManager.js +3 -3
  164. package/errors/CombinedGraphQLErrors.d.ts +2 -2
  165. package/errors/CombinedGraphQLErrors.js +3 -7
  166. package/errors/CombinedGraphQLErrors.js.map +1 -1
  167. package/errors/CombinedProtocolErrors.d.ts +2 -2
  168. package/errors/CombinedProtocolErrors.js +3 -8
  169. package/errors/CombinedProtocolErrors.js.map +1 -1
  170. package/incremental/handlers/graphql17Alpha9.js +2 -2
  171. package/incremental/handlers/notImplemented.js +1 -1
  172. package/invariantErrorCodes.js +125 -120
  173. package/link/core/ApolloLink.js +3 -3
  174. package/link/http/checkFetcher.js +1 -1
  175. package/link/http/parseAndCheckHttpResponse.js +1 -1
  176. package/link/persisted-queries/index.js +2 -2
  177. package/link/ws/index.js +1 -1
  178. package/local-state/LocalState.js +24 -23
  179. package/local-state/LocalState.js.map +1 -1
  180. package/masking/maskDefinition.js +21 -3
  181. package/masking/maskDefinition.js.map +1 -1
  182. package/masking/maskFragment.js +2 -2
  183. package/masking/maskOperation.js +1 -1
  184. package/masking/utils.js +3 -3
  185. package/package.json +1 -1
  186. package/react/context/ApolloContext.js +1 -1
  187. package/react/context/ApolloProvider.js +1 -1
  188. package/react/hooks/internal/validateSuspenseHookOptions.js +2 -2
  189. package/react/hooks/useApolloClient.js +1 -1
  190. package/react/hooks/useFragment.js +8 -2
  191. package/react/hooks/useFragment.js.map +1 -1
  192. package/react/hooks/useLazyQuery.js +2 -2
  193. package/react/hooks/useLoadableQuery.js +2 -2
  194. package/react/hooks/useSubscription.js +1 -1
  195. package/react/hooks/useSuspenseFragment.js +10 -4
  196. package/react/hooks/useSuspenseFragment.js.map +1 -1
  197. package/react/hooks/useSyncExternalStore.js +1 -1
  198. package/react/hooks-compiled/internal/validateSuspenseHookOptions.js +2 -2
  199. package/react/hooks-compiled/useApolloClient.js +1 -1
  200. package/react/hooks-compiled/useFragment.js +56 -32
  201. package/react/hooks-compiled/useFragment.js.map +1 -1
  202. package/react/hooks-compiled/useLazyQuery.js +2 -2
  203. package/react/hooks-compiled/useLoadableQuery.js +2 -2
  204. package/react/hooks-compiled/useSubscription.js +1 -1
  205. package/react/hooks-compiled/useSuspenseFragment.js +10 -4
  206. package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
  207. package/react/hooks-compiled/useSyncExternalStore.js +1 -1
  208. package/react/internal/cache/FragmentReference.d.ts +4 -5
  209. package/react/internal/cache/FragmentReference.js +2 -2
  210. package/react/internal/cache/FragmentReference.js.map +1 -1
  211. package/react/internal/cache/QueryReference.js +1 -1
  212. package/react/internal/cache/SuspenseCache.d.ts +4 -5
  213. package/react/internal/cache/SuspenseCache.js +3 -3
  214. package/react/internal/cache/SuspenseCache.js.map +1 -1
  215. package/react/internal/cache/types.d.ts +0 -5
  216. package/react/internal/cache/types.js.map +1 -1
  217. package/react/ssr/prerenderStatic.js +2 -2
  218. package/testing/core/mocking/mockLink.js +4 -4
  219. package/utilities/graphql/DocumentTransform.js +1 -1
  220. package/utilities/internal/DeepMerger.d.ts +13 -3
  221. package/utilities/internal/DeepMerger.js +6 -2
  222. package/utilities/internal/DeepMerger.js.map +1 -1
  223. package/utilities/internal/constants.d.ts +32 -0
  224. package/utilities/internal/constants.js +32 -0
  225. package/utilities/internal/constants.js.map +1 -1
  226. package/utilities/internal/createArgumentNode.d.ts +3 -0
  227. package/utilities/internal/createArgumentNode.js +11 -0
  228. package/utilities/internal/createArgumentNode.js.map +1 -0
  229. package/utilities/internal/createDirectiveNode.d.ts +3 -0
  230. package/utilities/internal/createDirectiveNode.js +11 -0
  231. package/utilities/internal/createDirectiveNode.js.map +1 -0
  232. package/utilities/internal/createFragmentSpreadNode.d.ts +3 -2
  233. package/utilities/internal/createFragmentSpreadNode.js +4 -1
  234. package/utilities/internal/createFragmentSpreadNode.js.map +1 -1
  235. package/utilities/internal/createValueNode.d.ts +12 -0
  236. package/utilities/internal/createValueNode.js +24 -0
  237. package/utilities/internal/createValueNode.js.map +1 -0
  238. package/utilities/internal/equalByQuery.d.ts +2 -3
  239. package/utilities/internal/equalByQuery.js +8 -8
  240. package/utilities/internal/equalByQuery.js.map +1 -1
  241. package/utilities/internal/getFragmentDefinition.js +3 -3
  242. package/utilities/internal/getFragmentDefinition.js.map +1 -1
  243. package/utilities/internal/getFragmentFromSelection.js +1 -1
  244. package/utilities/internal/getFragmentQueryDocument.js +10 -2
  245. package/utilities/internal/getFragmentQueryDocument.js.map +1 -1
  246. package/utilities/internal/getFragmentScope.d.ts +13 -0
  247. package/utilities/internal/getFragmentScope.js +20 -0
  248. package/utilities/internal/getFragmentScope.js.map +1 -0
  249. package/utilities/internal/getFragmentVariables.d.ts +9 -5
  250. package/utilities/internal/getFragmentVariables.js +15 -16
  251. package/utilities/internal/getFragmentVariables.js.map +1 -1
  252. package/utilities/internal/getMainDefinition.js +1 -1
  253. package/utilities/internal/getQueryDefinition.js +1 -1
  254. package/utilities/internal/index.d.ts +5 -1
  255. package/utilities/internal/index.js +3 -1
  256. package/utilities/internal/index.js.map +1 -1
  257. package/utilities/internal/isNonEmptyObject.d.ts +7 -0
  258. package/utilities/internal/isNonEmptyObject.js +10 -0
  259. package/utilities/internal/isNonEmptyObject.js.map +1 -0
  260. package/utilities/internal/isNonNullObject.d.ts +1 -1
  261. package/utilities/internal/isNonNullObject.js.map +1 -1
  262. package/utilities/internal/mapObservableFragment.d.ts +5 -1
  263. package/utilities/internal/mapObservableFragment.js +14 -9
  264. package/utilities/internal/mapObservableFragment.js.map +1 -1
  265. package/utilities/internal/mergeDeepArray.d.ts +2 -1
  266. package/utilities/internal/mergeDeepArray.js +2 -2
  267. package/utilities/internal/mergeDeepArray.js.map +1 -1
  268. package/utilities/internal/removeDirectivesFromDocument.js +1 -1
  269. package/utilities/internal/removeFragmentSpreads.d.ts +18 -2
  270. package/utilities/internal/removeFragmentSpreads.js +56 -3
  271. package/utilities/internal/removeFragmentSpreads.js.map +1 -1
  272. package/utilities/internal/shouldInclude.js +4 -4
  273. package/utilities/internal/types/FragmentInfo.d.ts +14 -0
  274. package/utilities/internal/types/FragmentInfo.js +2 -0
  275. package/utilities/internal/types/FragmentInfo.js.map +1 -0
  276. package/utilities/internal/types/ObjectWithFragmentInfo.d.ts +13 -0
  277. package/utilities/internal/types/ObjectWithFragmentInfo.js +2 -0
  278. package/utilities/internal/types/ObjectWithFragmentInfo.js.map +1 -0
  279. package/utilities/internal/valueToObjectRepresentation.js +1 -1
  280. package/version.js +1 -1
@@ -131,13 +131,22 @@ export interface MergeTree {
131
131
  export interface ReadMergeModifyContext {
132
132
  store: NormalizedCache;
133
133
  variables?: OperationVariables;
134
- varString?: string;
134
+ variablesScope?: OperationVariables;
135
+ varString?: VarString;
135
136
  extensions?: ExtensionsWithStreamInfo;
136
137
  isDeferPending?: (path: Incremental.Path, label: string | undefined) => boolean;
137
- operationVariables?: OperationVariables;
138
138
  }
139
139
  type ListOf<T extends string> = `[${T}]`;
140
140
  type NestedScalarName<T extends string> = T | ListOf<T> | ListOf<ListOf<T>> | ListOf<ListOf<ListOf<T>>> | ListOf<ListOf<ListOf<ListOf<T>>>>;
141
141
  export type KnownScalars = RemoveIndexSignature<ApolloCache.Scalars>;
142
142
  export type ScalarType = NestedScalarName<keyof KnownScalars & string> | (string extends keyof ApolloCache.Scalars ? string & {} : never);
143
+ declare const varStringBrand: unique symbol;
144
+ /**
145
+ * @internal
146
+ *
147
+ * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
148
+ */
149
+ export type VarString = string & {
150
+ readonly [varStringBrand]: true;
151
+ };
143
152
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/cache/inmemory/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DocumentNode, FieldNode } from \"graphql\";\n\nimport type { OperationVariables } from \"@apollo/client\";\nimport type { Incremental } from \"@apollo/client/incremental\";\nimport type {\n Reference,\n StoreObject,\n StoreValue,\n} from \"@apollo/client/utilities\";\nimport type {\n ExtensionsWithStreamInfo,\n handleIncrementalSymbol,\n RemoveIndexSignature,\n StreamInfoTrie,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { ApolloCache, Transaction } from \"../core/cache.js\";\nimport type {\n AllFieldsModifier,\n CanReadFunction,\n Modifiers,\n ToReferenceFunction,\n} from \"../core/types/common.js\";\n\nimport type { FieldValueGetter } from \"./entityStore.js\";\nimport type { FragmentRegistryAPI } from \"./fragmentRegistry.js\";\nimport type { InMemoryCache } from \"./inMemoryCache.js\";\nimport type {\n FieldMergeFunction,\n KeyFieldsFunction,\n PossibleTypesMap,\n StorageType,\n TypePolicies,\n} from \"./policies.js\";\n\nexport type { Reference, StoreObject, StoreValue };\n\nexport interface IdGetterObj extends Object {\n __typename?: string;\n id?: string;\n _id?: string;\n}\n\nexport declare type IdGetter = (value: IdGetterObj) => string | undefined;\n\n/**\n * This is an interface used to access, set and remove\n * StoreObjects from the cache\n */\nexport interface NormalizedCache {\n has(dataId: string): boolean;\n get(dataId: string, fieldName: string): StoreValue;\n\n // The store.merge method allows either argument to be a string ID, but\n // the other argument has to be a StoreObject. Either way, newer fields\n // always take precedence over older fields.\n merge(olderId: string, newerObject: StoreObject): void;\n merge(olderObject: StoreObject, newerId: string): void;\n\n modify<Entity extends Record<string, any>>(\n dataId: string,\n fields: Modifiers<Entity> | AllFieldsModifier<Entity>,\n exact: boolean\n ): boolean;\n delete(dataId: string, fieldName?: string): boolean;\n clear(): void;\n\n // non-Map elements:\n /**\n * returns an Object with key-value pairs matching the contents of the store\n */\n toObject(): NormalizedCacheObject;\n /**\n * replace the state of the store\n */\n replace(newData: NormalizedCacheObject): void;\n\n /**\n * Retain (or release) a given root ID to protect (or expose) it and its\n * transitive child entities from (or to) garbage collection. The current\n * retainment count is returned by both methods. Note that releasing a root\n * ID does not cause that entity to be garbage collected, but merely removes\n * it from the set of root IDs that will be considered during the next\n * mark-and-sweep collection.\n */\n retain(rootId: string): number;\n release(rootId: string): number;\n\n getFieldValue: FieldValueGetter;\n toReference: ToReferenceFunction;\n canRead: CanReadFunction;\n\n getStorage(\n idOrObj: string | StoreObject,\n ...storeFieldNames: (string | number)[]\n ): StorageType;\n}\n\n/**\n * This is a normalized representation of the Apollo query result cache. It consists of\n * a flattened representation of query result trees.\n */\nexport interface NormalizedCacheObject {\n __META?: {\n // Well-known singleton IDs like ROOT_QUERY and ROOT_MUTATION are\n // always considered to be root IDs during cache.gc garbage\n // collection, but other IDs can become roots if they are written\n // directly with cache.writeFragment or retained explicitly with\n // cache.retain. When such IDs exist, we include them in the __META\n // section so that they can survive cache.{extract,restore}.\n extraRootIds: string[];\n };\n [dataId: string]: StoreObject | undefined;\n}\n\nexport type OptimisticStoreItem = {\n id: string;\n data: NormalizedCacheObject;\n transaction: Transaction;\n};\n\nexport type ReadQueryOptions = {\n /**\n * The Apollo Client store object.\n */\n store: NormalizedCache;\n /**\n * A parsed GraphQL query document.\n */\n query: DocumentNode;\n variables?: Object;\n previousResult?: any;\n rootId?: string;\n config?: ApolloReducerConfig;\n};\n\n/** @internal */\nexport interface DiffIncrementalInfo {\n streamInfo?: StreamInfoTrie;\n isDeferPending?: (\n path: Incremental.Path,\n label: string | undefined\n ) => boolean;\n}\n\nexport interface WithHandleIncremental {\n [handleIncrementalSymbol]?: DiffIncrementalInfo | undefined;\n}\n\nexport type DiffQueryAgainstStoreOptions = ReadQueryOptions & {\n returnPartialData?: boolean;\n};\n\nexport type ApolloReducerConfig = {\n dataIdFromObject?: KeyFieldsFunction;\n};\n\nexport interface InputObjectConfig {\n fields: Record<string, string>;\n}\n\nexport interface InputObjectsOption {\n [inputObjectName: string]: InputObjectConfig;\n}\n\nexport type InMemoryCacheConfig = ApolloReducerConfig & {\n resultCaching?: boolean;\n possibleTypes?: PossibleTypesMap;\n typePolicies?: TypePolicies;\n fragments?: FragmentRegistryAPI;\n inputObjects?: InputObjectsOption;\n} & ({} extends InMemoryCache.ScalarsOption ?\n InMemoryCache.ScalarsOption extends Record<string, never> ?\n {\n scalars?: Record<\n string,\n `Scalar types must be declared in ApolloCache.Scalars before usage. See https://www.apollographql.com/docs/react/data/typescript#declaring-scalar-types.`\n >;\n }\n : { scalars?: InMemoryCache.ScalarsOption }\n : { scalars: InMemoryCache.ScalarsOption });\n\nexport interface MergeInfo {\n field: FieldNode;\n typename: string | undefined;\n merge: FieldMergeFunction;\n path: Array<string | number>;\n variables: OperationVariables | undefined;\n}\n\nexport interface MergeTree {\n info?: MergeInfo;\n map: Map<string | number, MergeTree>;\n}\n\nexport interface ReadMergeModifyContext {\n store: NormalizedCache;\n variables?: OperationVariables;\n // A JSON.stringify-serialized version of context.variables.\n varString?: string;\n extensions?: ExtensionsWithStreamInfo;\n isDeferPending?: (\n path: Incremental.Path,\n label: string | undefined\n ) => boolean;\n // Keep a copy of the operation variables. variables reflects the current\n // scoped variables in fragments that have arguments\n operationVariables?: OperationVariables;\n}\n\ntype ListOf<T extends string> = `[${T}]`;\n\ntype NestedScalarName<T extends string> =\n | T\n | ListOf<T>\n | ListOf<ListOf<T>>\n | ListOf<ListOf<ListOf<T>>>\n | ListOf<ListOf<ListOf<ListOf<T>>>>;\n\nexport type KnownScalars = RemoveIndexSignature<ApolloCache.Scalars>;\n\nexport type ScalarType =\n | NestedScalarName<keyof KnownScalars & string>\n | (string extends keyof ApolloCache.Scalars ? string & {} : never);\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/cache/inmemory/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DocumentNode, FieldNode } from \"graphql\";\n\nimport type { OperationVariables } from \"@apollo/client\";\nimport type { Incremental } from \"@apollo/client/incremental\";\nimport type {\n Reference,\n StoreObject,\n StoreValue,\n} from \"@apollo/client/utilities\";\nimport type {\n ExtensionsWithStreamInfo,\n handleIncrementalSymbol,\n RemoveIndexSignature,\n StreamInfoTrie,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { ApolloCache, Transaction } from \"../core/cache.js\";\nimport type {\n AllFieldsModifier,\n CanReadFunction,\n Modifiers,\n ToReferenceFunction,\n} from \"../core/types/common.js\";\n\nimport type { FieldValueGetter } from \"./entityStore.js\";\nimport type { FragmentRegistryAPI } from \"./fragmentRegistry.js\";\nimport type { InMemoryCache } from \"./inMemoryCache.js\";\nimport type {\n FieldMergeFunction,\n KeyFieldsFunction,\n PossibleTypesMap,\n StorageType,\n TypePolicies,\n} from \"./policies.js\";\n\nexport type { Reference, StoreObject, StoreValue };\n\nexport interface IdGetterObj extends Object {\n __typename?: string;\n id?: string;\n _id?: string;\n}\n\nexport declare type IdGetter = (value: IdGetterObj) => string | undefined;\n\n/**\n * This is an interface used to access, set and remove\n * StoreObjects from the cache\n */\nexport interface NormalizedCache {\n has(dataId: string): boolean;\n get(dataId: string, fieldName: string): StoreValue;\n\n // The store.merge method allows either argument to be a string ID, but\n // the other argument has to be a StoreObject. Either way, newer fields\n // always take precedence over older fields.\n merge(olderId: string, newerObject: StoreObject): void;\n merge(olderObject: StoreObject, newerId: string): void;\n\n modify<Entity extends Record<string, any>>(\n dataId: string,\n fields: Modifiers<Entity> | AllFieldsModifier<Entity>,\n exact: boolean\n ): boolean;\n delete(dataId: string, fieldName?: string): boolean;\n clear(): void;\n\n // non-Map elements:\n /**\n * returns an Object with key-value pairs matching the contents of the store\n */\n toObject(): NormalizedCacheObject;\n /**\n * replace the state of the store\n */\n replace(newData: NormalizedCacheObject): void;\n\n /**\n * Retain (or release) a given root ID to protect (or expose) it and its\n * transitive child entities from (or to) garbage collection. The current\n * retainment count is returned by both methods. Note that releasing a root\n * ID does not cause that entity to be garbage collected, but merely removes\n * it from the set of root IDs that will be considered during the next\n * mark-and-sweep collection.\n */\n retain(rootId: string): number;\n release(rootId: string): number;\n\n getFieldValue: FieldValueGetter;\n toReference: ToReferenceFunction;\n canRead: CanReadFunction;\n\n getStorage(\n idOrObj: string | StoreObject,\n ...storeFieldNames: (string | number)[]\n ): StorageType;\n}\n\n/**\n * This is a normalized representation of the Apollo query result cache. It consists of\n * a flattened representation of query result trees.\n */\nexport interface NormalizedCacheObject {\n __META?: {\n // Well-known singleton IDs like ROOT_QUERY and ROOT_MUTATION are\n // always considered to be root IDs during cache.gc garbage\n // collection, but other IDs can become roots if they are written\n // directly with cache.writeFragment or retained explicitly with\n // cache.retain. When such IDs exist, we include them in the __META\n // section so that they can survive cache.{extract,restore}.\n extraRootIds: string[];\n };\n [dataId: string]: StoreObject | undefined;\n}\n\nexport type OptimisticStoreItem = {\n id: string;\n data: NormalizedCacheObject;\n transaction: Transaction;\n};\n\nexport type ReadQueryOptions = {\n /**\n * The Apollo Client store object.\n */\n store: NormalizedCache;\n /**\n * A parsed GraphQL query document.\n */\n query: DocumentNode;\n variables?: Object;\n previousResult?: any;\n rootId?: string;\n config?: ApolloReducerConfig;\n};\n\n/** @internal */\nexport interface DiffIncrementalInfo {\n streamInfo?: StreamInfoTrie;\n isDeferPending?: (\n path: Incremental.Path,\n label: string | undefined\n ) => boolean;\n}\n\nexport interface WithHandleIncremental {\n [handleIncrementalSymbol]?: DiffIncrementalInfo | undefined;\n}\n\nexport type DiffQueryAgainstStoreOptions = ReadQueryOptions & {\n returnPartialData?: boolean;\n};\n\nexport type ApolloReducerConfig = {\n dataIdFromObject?: KeyFieldsFunction;\n};\n\nexport interface InputObjectConfig {\n fields: Record<string, string>;\n}\n\nexport interface InputObjectsOption {\n [inputObjectName: string]: InputObjectConfig;\n}\n\nexport type InMemoryCacheConfig = ApolloReducerConfig & {\n resultCaching?: boolean;\n possibleTypes?: PossibleTypesMap;\n typePolicies?: TypePolicies;\n fragments?: FragmentRegistryAPI;\n inputObjects?: InputObjectsOption;\n} & ({} extends InMemoryCache.ScalarsOption ?\n InMemoryCache.ScalarsOption extends Record<string, never> ?\n {\n scalars?: Record<\n string,\n `Scalar types must be declared in ApolloCache.Scalars before usage. See https://www.apollographql.com/docs/react/data/typescript#declaring-scalar-types.`\n >;\n }\n : { scalars?: InMemoryCache.ScalarsOption }\n : { scalars: InMemoryCache.ScalarsOption });\n\nexport interface MergeInfo {\n field: FieldNode;\n typename: string | undefined;\n merge: FieldMergeFunction;\n path: Array<string | number>;\n variables: OperationVariables | undefined;\n}\n\nexport interface MergeTree {\n info?: MergeInfo;\n map: Map<string | number, MergeTree>;\n}\n\nexport interface ReadMergeModifyContext {\n store: NormalizedCache;\n // The operation variables.\n variables?: OperationVariables;\n // The variables in scope for the current selection set. This is the same as\n // variables except in fragments that have arguments.\n variablesScope?: OperationVariables;\n // A serialized version of variablesScope and variables.\n varString?: VarString;\n extensions?: ExtensionsWithStreamInfo;\n isDeferPending?: (\n path: Incremental.Path,\n label: string | undefined\n ) => boolean;\n}\n\ntype ListOf<T extends string> = `[${T}]`;\n\ntype NestedScalarName<T extends string> =\n | T\n | ListOf<T>\n | ListOf<ListOf<T>>\n | ListOf<ListOf<ListOf<T>>>\n | ListOf<ListOf<ListOf<ListOf<T>>>>;\n\nexport type KnownScalars = RemoveIndexSignature<ApolloCache.Scalars>;\n\nexport type ScalarType =\n | NestedScalarName<keyof KnownScalars & string>\n | (string extends keyof ApolloCache.Scalars ? string & {} : never);\n\ndeclare const varStringBrand: unique symbol;\n\n/** @internal */\nexport type VarString = string & { readonly [varStringBrand]: true };\n"]}
@@ -2,15 +2,15 @@ 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
+ import { handleIncrementalSymbol, rootFragmentVariablesSymbol } from "@apollo/client/utilities/internal";
6
6
  import type { InMemoryCache } from "./inMemoryCache.js";
7
7
  import type { StoreReader } from "./readFromStore.js";
8
- import type { DiffIncrementalInfo, InMemoryCacheConfig, MergeTree, NormalizedCache, ReadMergeModifyContext } from "./types.js";
8
+ import type { DiffIncrementalInfo, InMemoryCacheConfig, MergeTree, NormalizedCache, ReadMergeModifyContext, VarString } from "./types.js";
9
9
  export interface WriteContext extends ReadMergeModifyContext {
10
10
  readonly written: {
11
11
  [dataId: string]: Array<{
12
12
  selectionSet: SelectionSetNode;
13
- varString: string | undefined;
13
+ varString: VarString | undefined;
14
14
  }>;
15
15
  };
16
16
  readonly fragmentMap: FragmentMap;
@@ -32,8 +32,9 @@ export declare class StoreWriter {
32
32
  private reader?;
33
33
  private fragments?;
34
34
  constructor(cache: InMemoryCache, reader?: StoreReader | undefined, fragments?: InMemoryCacheConfig["fragments"]);
35
- writeToStore<TData = unknown, TVariables extends OperationVariables = OperationVariables>(store: NormalizedCache, { query, result, dataId, variables, overwrite, extensions, [handleIncrementalSymbol]: incrementalInfo, }: Cache.WriteOptions<TData, TVariables> & {
35
+ writeToStore<TData = unknown, TVariables extends OperationVariables = OperationVariables>(store: NormalizedCache, { query, result, dataId, variables, overwrite, extensions, [handleIncrementalSymbol]: incrementalInfo, [rootFragmentVariablesSymbol]: rootFragmentVariables, }: Cache.WriteOptions<TData, TVariables> & {
36
36
  [handleIncrementalSymbol]?: DiffIncrementalInfo;
37
+ [rootFragmentVariablesSymbol]?: OperationVariables;
37
38
  }): Reference | undefined;
38
39
  private processSelectionSet;
39
40
  private processFieldValue;
@@ -1,11 +1,11 @@
1
1
  import { equal } from "@wry/equality";
2
2
  import { Trie } from "@wry/trie";
3
3
  import { Kind } from "graphql";
4
- import { addTypenameToDocument, canonicalStringify, isReference, } from "@apollo/client/utilities";
4
+ import { addTypenameToDocument, isReference } from "@apollo/client/utilities";
5
5
  import { __DEV__ } from "@apollo/client/utilities/environment";
6
- import { argumentsObjectFromField, cloneDeep, getDefaultValues, getFragmentFromSelection, getFragmentVariables, getOperationDefinition, handleIncrementalSymbol, isArray, isField, isNonEmptyArray, isStreamField, makeReference, resultKeyNameFromField, shouldInclude, streamInfoSymbol, } from "@apollo/client/utilities/internal";
6
+ import { argumentsObjectFromField, cloneDeep, getDefaultValues, getFragmentFromSelection, getFragmentScope, getOperationDefinition, handleIncrementalSymbol, isArray, isField, isNonEmptyArray, isStreamField, makeReference, resultKeyNameFromField, rootFragmentVariablesSymbol, shouldInclude, streamInfoSymbol, } from "@apollo/client/utilities/internal";
7
7
  import { invariant, newInvariantError, } from "@apollo/client/utilities/invariant";
8
- import { extractFragmentContext, fieldNameFromStoreName, makeProcessedFieldsMerger, storeValueIsStoreObject, } from "./helpers.js";
8
+ import { extractFragmentContext, fieldNameFromStoreName, makeProcessedFieldsMerger, makeVarString, storeValueIsStoreObject, } from "./helpers.js";
9
9
  import { defaultStreamFieldMergeFn, normalizeReadFieldOptions, } from "./policies.js";
10
10
  // Since there are only four possible combinations of context.clientOnly and
11
11
  // context.deferred values, we should need at most four "flavors" of any given
@@ -37,7 +37,7 @@ export class StoreWriter {
37
37
  this.reader = reader;
38
38
  this.fragments = fragments;
39
39
  }
40
- writeToStore(store, { query, result, dataId, variables, overwrite, extensions, [handleIncrementalSymbol]: incrementalInfo, }) {
40
+ writeToStore(store, { query, result, dataId, variables, overwrite, extensions, [handleIncrementalSymbol]: incrementalInfo, [rootFragmentVariablesSymbol]: rootFragmentVariables, }) {
41
41
  const operationDefinition = getOperationDefinition(query);
42
42
  const merger = makeProcessedFieldsMerger();
43
43
  variables = {
@@ -50,9 +50,9 @@ export class StoreWriter {
50
50
  merge(existing, incoming) {
51
51
  return merger.merge(existing, incoming);
52
52
  },
53
- variables: variables,
54
- varString: canonicalStringify(variables),
55
- operationVariables: variables,
53
+ variables,
54
+ variablesScope: rootFragmentVariables ?? variables,
55
+ varString: makeVarString({ variables, scope: rootFragmentVariables }),
56
56
  ...extractFragmentContext(query, this.fragments),
57
57
  overwrite: !!overwrite,
58
58
  incomingById: new Map(),
@@ -71,7 +71,7 @@ export class StoreWriter {
71
71
  path: [],
72
72
  });
73
73
  if (!isReference(ref)) {
74
- throw newInvariantError(124, result);
74
+ throw newInvariantError(125, result);
75
75
  }
76
76
  // So far, the store has not been modified, so now it's time to process
77
77
  // context.incomingById and merge those incoming fields into context.store.
@@ -149,7 +149,7 @@ export class StoreWriter {
149
149
  // need to be extracted from a child object that processSelectionSet has
150
150
  // turned into a Reference.
151
151
  const readField = (...args) => {
152
- const options = normalizeReadFieldOptions(args, incoming, context.variables);
152
+ const options = normalizeReadFieldOptions(args, incoming, context.variablesScope);
153
153
  if (isReference(options.from)) {
154
154
  const info = context.incomingById.get(options.from.__ref);
155
155
  if (info) {
@@ -179,7 +179,7 @@ export class StoreWriter {
179
179
  typename,
180
180
  fieldName: field.name.value,
181
181
  field,
182
- variables: context.variables,
182
+ variables: context.variablesScope,
183
183
  });
184
184
  const childTree = getChildMergeTree(mergeTree, storeFieldName);
185
185
  let incomingValue = this.processFieldValue(value, field,
@@ -211,18 +211,18 @@ export class StoreWriter {
211
211
  typename,
212
212
  merge,
213
213
  path,
214
- variables: context.variables,
214
+ variables: context.variablesScope,
215
215
  };
216
216
  }
217
217
  else if (context.extensions?.[streamInfoSymbol] &&
218
218
  Array.isArray(incomingValue) &&
219
- isStreamField(field, context.variables)) {
219
+ isStreamField(field, context.variablesScope)) {
220
220
  childTree.info = {
221
221
  field,
222
222
  typename,
223
223
  merge: defaultStreamFieldMergeFn,
224
224
  path,
225
- variables: context.variables,
225
+ variables: context.variablesScope,
226
226
  };
227
227
  }
228
228
  else {
@@ -240,7 +240,7 @@ export class StoreWriter {
240
240
  // provide a default value, so its absence from the written data should
241
241
  // not be cause for alarm.
242
242
  !policies.getReadFunction(typename, field.name.value)) {
243
- invariant.error(125, resultKeyNameFromField(field), result);
243
+ invariant.error(126, resultKeyNameFromField(field), result);
244
244
  }
245
245
  });
246
246
  // Identify the result object, even if dataId was already provided,
@@ -353,7 +353,7 @@ export class StoreWriter {
353
353
  return;
354
354
  visitedNode.visited = true;
355
355
  selectionSet.selections.forEach((selection) => {
356
- if (!shouldInclude(selection, inheritedContext.variables))
356
+ if (!shouldInclude(selection, inheritedContext.variablesScope))
357
357
  return;
358
358
  let { clientOnly, deferred } = inheritedContext;
359
359
  if (
@@ -367,7 +367,7 @@ export class StoreWriter {
367
367
  if (name === "client")
368
368
  clientOnly = true;
369
369
  if (name === "defer") {
370
- const args = argumentsObjectFromField(dir, inheritedContext.variables);
370
+ const args = argumentsObjectFromField(dir, inheritedContext.variablesScope);
371
371
  // The @defer directive takes an optional args.if boolean
372
372
  // argument, similar to @include(if: boolean). Note that
373
373
  // @defer(if: false) does not make context.deferred false, but
@@ -403,25 +403,28 @@ export class StoreWriter {
403
403
  else {
404
404
  const fragment = getFragmentFromSelection(selection, context.lookupFragment);
405
405
  if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {
406
- throw newInvariantError(126, selection.name.value);
406
+ throw newInvariantError(127, selection.name.value);
407
407
  }
408
408
  if (!fragment)
409
409
  return;
410
- const variables = (selection.kind === Kind.FRAGMENT_SPREAD &&
410
+ const variablesScope = (selection.kind === Kind.FRAGMENT_SPREAD &&
411
411
  fragment.kind === Kind.FRAGMENT_DEFINITION) ?
412
- getFragmentVariables(selection, {
412
+ getFragmentScope(selection, {
413
413
  fragment,
414
- variables: context.operationVariables,
415
- parentScope: inheritedContext.variables,
414
+ variables: context.variables,
415
+ parentScope: inheritedContext.variablesScope,
416
416
  })
417
- : inheritedContext.variables;
418
- if (policies.fragmentMatches(fragment, typename, result, variables)) {
417
+ : inheritedContext.variablesScope;
418
+ if (policies.fragmentMatches(fragment, typename, result, variablesScope)) {
419
419
  let fragmentContext = getContextFlavor(inheritedContext, clientOnly, deferred);
420
- if (variables !== inheritedContext.variables) {
420
+ if (variablesScope !== inheritedContext.variablesScope) {
421
421
  fragmentContext = {
422
422
  ...fragmentContext,
423
- variables,
424
- varString: canonicalStringify(variables),
423
+ variablesScope,
424
+ varString: makeVarString({
425
+ variables: context.variables,
426
+ scope: variablesScope,
427
+ }),
425
428
  flavors: new Map(),
426
429
  };
427
430
  }
@@ -593,7 +596,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
593
596
  }
594
597
  });
595
598
  }
596
- __DEV__ && invariant.warn(127, fieldName, parentType, childTypenames.length ?
599
+ __DEV__ && invariant.warn(128, fieldName, parentType, childTypenames.length ?
597
600
  "either ensure all objects of type " +
598
601
  childTypenames.join(" and ") +
599
602
  " have an ID or a custom merge function, or "