@apollo/client 4.1.0-alpha.9 → 4.1.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/__cjs/cache/core/types/Cache.d.cts +3 -2
  3. package/__cjs/cache/index.cjs.map +1 -1
  4. package/__cjs/cache/index.d.cts +1 -1
  5. package/__cjs/cache/inmemory/policies.cjs +72 -22
  6. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  7. package/__cjs/cache/inmemory/policies.d.cts +31 -9
  8. package/__cjs/cache/inmemory/types.d.cts +3 -1
  9. package/__cjs/cache/inmemory/writeToStore.cjs +18 -4
  10. package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
  11. package/__cjs/cache/inmemory/writeToStore.d.cts +0 -1
  12. package/__cjs/core/QueryInfo.cjs +6 -1
  13. package/__cjs/core/QueryInfo.cjs.map +1 -1
  14. package/__cjs/core/QueryInfo.d.cts +4 -3
  15. package/__cjs/core/QueryManager.cjs +13 -3
  16. package/__cjs/core/QueryManager.cjs.map +1 -1
  17. package/__cjs/core/QueryManager.d.cts +2 -1
  18. package/__cjs/incremental/handlers/graphql17Alpha9.cjs +39 -0
  19. package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
  20. package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +1 -0
  21. package/__cjs/incremental/types.d.cts +9 -0
  22. package/__cjs/react/query-preloader/createQueryPreloader.cjs +41 -1
  23. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  24. package/__cjs/utilities/internal/constants.cjs +6 -1
  25. package/__cjs/utilities/internal/constants.cjs.map +1 -1
  26. package/__cjs/utilities/internal/constants.d.cts +5 -0
  27. package/__cjs/utilities/internal/index.cjs +2 -1
  28. package/__cjs/utilities/internal/index.cjs.map +1 -1
  29. package/__cjs/utilities/internal/index.d.cts +3 -1
  30. package/__cjs/utilities/internal/ponyfills/FinalizationRegistry.cjs +61 -0
  31. package/__cjs/utilities/internal/ponyfills/FinalizationRegistry.cjs.map +1 -0
  32. package/__cjs/utilities/internal/ponyfills/FinalizationRegistry.d.cts +11 -0
  33. package/__cjs/utilities/internal/ponyfills/index.cjs +6 -0
  34. package/__cjs/utilities/internal/ponyfills/index.cjs.map +1 -0
  35. package/__cjs/utilities/internal/ponyfills/index.d.cts +3 -0
  36. package/__cjs/utilities/internal/ponyfills/index.react-native.cjs +6 -0
  37. package/__cjs/utilities/internal/ponyfills/index.react-native.cjs.map +1 -0
  38. package/__cjs/utilities/internal/ponyfills/index.react-native.d.cts +2 -0
  39. package/__cjs/utilities/internal/types/ExtensionsWithStreamDetails.cjs +3 -0
  40. package/__cjs/utilities/internal/types/ExtensionsWithStreamDetails.cjs.map +1 -0
  41. package/__cjs/utilities/internal/types/ExtensionsWithStreamDetails.d.cts +12 -0
  42. package/__cjs/utilities/internal/types/StreamInfoTrie.cjs +3 -0
  43. package/__cjs/utilities/internal/types/StreamInfoTrie.cjs.map +1 -0
  44. package/__cjs/utilities/internal/types/StreamInfoTrie.d.cts +16 -0
  45. package/__cjs/version.cjs +1 -1
  46. package/__cjs/version.cjs.map +1 -1
  47. package/cache/core/types/Cache.d.ts +3 -2
  48. package/cache/core/types/Cache.js.map +1 -1
  49. package/cache/index.d.ts +1 -1
  50. package/cache/index.js.map +1 -1
  51. package/cache/inmemory/policies.d.ts +31 -9
  52. package/cache/inmemory/policies.js +60 -11
  53. package/cache/inmemory/policies.js.map +1 -1
  54. package/cache/inmemory/types.d.ts +3 -1
  55. package/cache/inmemory/types.js.map +1 -1
  56. package/cache/inmemory/writeToStore.d.ts +0 -1
  57. package/cache/inmemory/writeToStore.js +20 -6
  58. package/cache/inmemory/writeToStore.js.map +1 -1
  59. package/core/QueryInfo.d.ts +4 -3
  60. package/core/QueryInfo.js +7 -2
  61. package/core/QueryInfo.js.map +1 -1
  62. package/core/QueryManager.d.ts +2 -1
  63. package/core/QueryManager.js +14 -4
  64. package/core/QueryManager.js.map +1 -1
  65. package/incremental/handlers/graphql17Alpha9.d.ts +1 -0
  66. package/incremental/handlers/graphql17Alpha9.js +40 -1
  67. package/incremental/handlers/graphql17Alpha9.js.map +1 -1
  68. package/incremental/types.d.ts +9 -0
  69. package/incremental/types.js.map +1 -1
  70. package/legacyEntryPoints/utilities/internal/ponyfills/index.d.ts +1 -0
  71. package/legacyEntryPoints/utilities/internal/ponyfills/index.js +1 -0
  72. package/legacyEntryPoints/utilities/internal/ponyfills/ponyfills.cjs +1 -0
  73. package/legacyEntryPoints/utilities/internal/ponyfills/ponyfills.d.cts +1 -0
  74. package/package.json +15 -1
  75. package/react/query-preloader/createQueryPreloader.js +41 -1
  76. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  77. package/utilities/internal/constants.d.ts +5 -0
  78. package/utilities/internal/constants.js +5 -0
  79. package/utilities/internal/constants.js.map +1 -1
  80. package/utilities/internal/index.d.ts +3 -1
  81. package/utilities/internal/index.js +1 -1
  82. package/utilities/internal/index.js.map +1 -1
  83. package/utilities/internal/ponyfills/FinalizationRegistry.d.ts +11 -0
  84. package/utilities/internal/ponyfills/FinalizationRegistry.js +57 -0
  85. package/utilities/internal/ponyfills/FinalizationRegistry.js.map +1 -0
  86. package/utilities/internal/ponyfills/index.d.ts +3 -0
  87. package/utilities/internal/ponyfills/index.js +3 -0
  88. package/utilities/internal/ponyfills/index.js.map +1 -0
  89. package/utilities/internal/ponyfills/index.react-native.d.ts +2 -0
  90. package/utilities/internal/ponyfills/index.react-native.js +2 -0
  91. package/utilities/internal/ponyfills/index.react-native.js.map +1 -0
  92. package/utilities/internal/types/ExtensionsWithStreamDetails.d.ts +12 -0
  93. package/utilities/internal/types/ExtensionsWithStreamDetails.js +2 -0
  94. package/utilities/internal/types/ExtensionsWithStreamDetails.js.map +1 -0
  95. package/utilities/internal/types/StreamInfoTrie.d.ts +16 -0
  96. package/utilities/internal/types/StreamInfoTrie.js +2 -0
  97. package/utilities/internal/types/StreamInfoTrie.js.map +1 -0
  98. package/version.js +1 -1
  99. package/version.js.map +1 -1
@@ -1,6 +1,7 @@
1
1
  import type { DocumentNode, FieldNode } from "graphql";
2
2
  import type { OperationVariables } from "@apollo/client";
3
3
  import type { Reference, StoreObject, StoreValue } from "@apollo/client/utilities";
4
+ import type { ExtensionsWithStreamInfo } from "@apollo/client/utilities/internal";
4
5
  import type { Transaction } from "../core/cache.js";
5
6
  import type { AllFieldsModifier, CanReadFunction, Modifiers, ToReferenceFunction } from "../core/types/common.js";
6
7
  import type { FieldValueGetter } from "./entityStore.js";
@@ -93,6 +94,7 @@ export interface MergeInfo {
93
94
  field: FieldNode;
94
95
  typename: string | undefined;
95
96
  merge: FieldMergeFunction;
97
+ path: Array<string | number>;
96
98
  }
97
99
  export interface MergeTree {
98
100
  info?: MergeInfo;
@@ -102,6 +104,6 @@ export interface ReadMergeModifyContext {
102
104
  store: NormalizedCache;
103
105
  variables?: OperationVariables;
104
106
  varString?: string;
105
- extensions?: Record<string, unknown>;
107
+ extensions?: ExtensionsWithStreamInfo;
106
108
  }
107
109
  //# 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 {\n Reference,\n StoreObject,\n StoreValue,\n} from \"@apollo/client/utilities\";\n\nimport type { 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 {\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\nexport type DiffQueryAgainstStoreOptions = ReadQueryOptions & {\n returnPartialData?: boolean;\n};\n\nexport type ApolloReducerConfig = {\n dataIdFromObject?: KeyFieldsFunction;\n};\n\nexport interface InMemoryCacheConfig extends ApolloReducerConfig {\n resultCaching?: boolean;\n possibleTypes?: PossibleTypesMap;\n typePolicies?: TypePolicies;\n fragments?: FragmentRegistryAPI;\n}\n\nexport interface MergeInfo {\n field: FieldNode;\n typename: string | undefined;\n merge: FieldMergeFunction;\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?: Record<string, unknown>;\n}\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 {\n Reference,\n StoreObject,\n StoreValue,\n} from \"@apollo/client/utilities\";\nimport type { ExtensionsWithStreamInfo } from \"@apollo/client/utilities/internal\";\n\nimport type { 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 {\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\nexport type DiffQueryAgainstStoreOptions = ReadQueryOptions & {\n returnPartialData?: boolean;\n};\n\nexport type ApolloReducerConfig = {\n dataIdFromObject?: KeyFieldsFunction;\n};\n\nexport interface InMemoryCacheConfig extends ApolloReducerConfig {\n resultCaching?: boolean;\n possibleTypes?: PossibleTypesMap;\n typePolicies?: TypePolicies;\n fragments?: FragmentRegistryAPI;\n}\n\nexport interface MergeInfo {\n field: FieldNode;\n typename: string | undefined;\n merge: FieldMergeFunction;\n path: Array<string | number>;\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}\n"]}
@@ -21,7 +21,6 @@ export interface WriteContext extends ReadMergeModifyContext {
21
21
  clientOnly: boolean;
22
22
  deferred: boolean;
23
23
  flavors: Map<string, FlavorableWriteContext>;
24
- extensions?: Record<string, unknown>;
25
24
  }
26
25
  type FlavorableWriteContext = Pick<WriteContext, "clientOnly" | "deferred" | "flavors">;
27
26
  export declare class StoreWriter {
@@ -3,10 +3,10 @@ import { Trie } from "@wry/trie";
3
3
  import { Kind } from "graphql";
4
4
  import { addTypenameToDocument, canonicalStringify, isReference, } from "@apollo/client/utilities";
5
5
  import { __DEV__ } from "@apollo/client/utilities/environment";
6
- import { argumentsObjectFromField, cloneDeep, getDefaultValues, getFragmentFromSelection, getOperationDefinition, isArray, isField, isNonEmptyArray, makeReference, resultKeyNameFromField, shouldInclude, } from "@apollo/client/utilities/internal";
6
+ import { argumentsObjectFromField, cloneDeep, getDefaultValues, getFragmentFromSelection, getOperationDefinition, hasDirectives, isArray, isField, isNonEmptyArray, makeReference, resultKeyNameFromField, shouldInclude, streamInfoSymbol, } from "@apollo/client/utilities/internal";
7
7
  import { invariant, newInvariantError, } from "@apollo/client/utilities/invariant";
8
8
  import { extractFragmentContext, fieldNameFromStoreName, makeProcessedFieldsMerger, storeValueIsStoreObject, } from "./helpers.js";
9
- import { normalizeReadFieldOptions } from "./policies.js";
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
12
12
  // WriteContext. To avoid creating multiple copies of the same context, we cache
@@ -65,6 +65,7 @@ export class StoreWriter {
65
65
  selectionSet: operationDefinition.selectionSet,
66
66
  mergeTree: { map: new Map() },
67
67
  context,
68
+ path: [],
68
69
  });
69
70
  if (!isReference(ref)) {
70
71
  throw newInvariantError(109, result);
@@ -122,7 +123,7 @@ export class StoreWriter {
122
123
  processSelectionSet({ dataId, result, selectionSet, context,
123
124
  // This object allows processSelectionSet to report useful information
124
125
  // to its callers without explicitly returning that information.
125
- mergeTree, }) {
126
+ mergeTree, path: currentPath, }) {
126
127
  const { policies } = this.cache;
127
128
  // This variable will be repeatedly updated using context.merge to
128
129
  // accumulate all fields that need to be written into the store.
@@ -168,6 +169,7 @@ export class StoreWriter {
168
169
  context, typename).forEach((context, field) => {
169
170
  const resultFieldKey = resultKeyNameFromField(field);
170
171
  const value = result[resultFieldKey];
172
+ const path = [...currentPath, field.name.value];
171
173
  fieldNodeSet.add(field);
172
174
  if (value !== void 0) {
173
175
  const storeFieldName = policies.getStoreFieldName({
@@ -182,7 +184,7 @@ export class StoreWriter {
182
184
  // values before processing nested selection sets.
183
185
  field.selectionSet ?
184
186
  getContextFlavor(context, false, false)
185
- : context, childTree);
187
+ : context, childTree, path);
186
188
  // To determine if this field holds a child object with a merge function
187
189
  // defined in its type policy (see PR #7070), we need to figure out the
188
190
  // child object's __typename.
@@ -200,6 +202,17 @@ export class StoreWriter {
200
202
  field,
201
203
  typename,
202
204
  merge,
205
+ path,
206
+ };
207
+ }
208
+ else if (hasDirectives(["stream"], field) &&
209
+ Array.isArray(incomingValue) &&
210
+ context.extensions?.[streamInfoSymbol]) {
211
+ childTree.info = {
212
+ field,
213
+ typename,
214
+ merge: defaultStreamFieldMergeFn,
215
+ path,
203
216
  };
204
217
  }
205
218
  else {
@@ -285,7 +298,7 @@ export class StoreWriter {
285
298
  }
286
299
  return incoming;
287
300
  }
288
- processFieldValue(value, field, context, mergeTree) {
301
+ processFieldValue(value, field, context, mergeTree, path) {
289
302
  if (!field.selectionSet || value === null) {
290
303
  // In development, we need to clone scalar values so that they can be
291
304
  // safely frozen with maybeDeepFreeze in readFromStore.ts. In production,
@@ -294,7 +307,7 @@ export class StoreWriter {
294
307
  }
295
308
  if (isArray(value)) {
296
309
  return value.map((item, i) => {
297
- const value = this.processFieldValue(item, field, context, getChildMergeTree(mergeTree, i));
310
+ const value = this.processFieldValue(item, field, context, getChildMergeTree(mergeTree, i), [...path, i]);
298
311
  maybeRecycleChildMergeTree(mergeTree, i);
299
312
  return value;
300
313
  });
@@ -304,6 +317,7 @@ export class StoreWriter {
304
317
  selectionSet: field.selectionSet,
305
318
  context,
306
319
  mergeTree,
320
+ path,
307
321
  });
308
322
  }
309
323
  // Implements https://spec.graphql.org/draft/#sec-Field-Collection, but with