@apollo/client 4.3.0-alpha.3 → 4.3.0-alpha.4
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.
- package/CHANGELOG.md +14 -0
- package/__cjs/cache/core/types/Cache.d.cts +25 -0
- package/__cjs/cache/index.cjs.map +1 -1
- package/__cjs/cache/index.d.cts +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.cjs +4 -0
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.d.cts +7 -3
- package/__cjs/cache/inmemory/readFromStore.cjs +453 -42
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/readFromStore.d.cts +11 -2
- package/__cjs/cache/inmemory/types.d.cts +11 -1
- package/__cjs/cache/inmemory/writeToStore.cjs +1 -5
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/core/QueryInfo.cjs +86 -172
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +8 -2
- package/__cjs/core/QueryManager.cjs +3 -1
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
- package/__cjs/incremental/handlers/defer20220824.d.cts +2 -4
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs +20 -12
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
- package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +5 -5
- package/__cjs/incremental/types.d.cts +16 -3
- package/__cjs/utilities/caching/sizes.cjs.map +1 -1
- package/__cjs/utilities/caching/sizes.d.cts +39 -1
- package/__cjs/utilities/internal/StreamArrayState.cjs +27 -0
- package/__cjs/utilities/internal/StreamArrayState.cjs.map +1 -0
- package/__cjs/utilities/internal/StreamArrayState.d.cts +12 -0
- package/__cjs/utilities/internal/constants.cjs +20 -1
- package/__cjs/utilities/internal/constants.cjs.map +1 -1
- package/__cjs/utilities/internal/constants.d.cts +19 -0
- package/__cjs/utilities/internal/getFragmentFromSelection.cjs +1 -1
- package/__cjs/utilities/internal/getFragmentFromSelection.cjs.map +1 -1
- package/__cjs/utilities/internal/getMemoryInternals.cjs +6 -0
- package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
- package/__cjs/utilities/internal/getMemoryInternals.d.cts +4 -0
- package/__cjs/utilities/internal/index.cjs +9 -4
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +5 -3
- package/__cjs/utilities/internal/isDeferredFragment.cjs +19 -4
- package/__cjs/utilities/internal/isDeferredFragment.cjs.map +1 -1
- package/__cjs/utilities/internal/isDeferredFragment.d.cts +6 -1
- package/__cjs/utilities/internal/isStreamField.cjs +37 -0
- package/__cjs/utilities/internal/isStreamField.cjs.map +1 -0
- package/__cjs/utilities/internal/isStreamField.d.cts +9 -0
- package/__cjs/utilities/internal/makeStreamInfoTrie.cjs +17 -0
- package/__cjs/utilities/internal/makeStreamInfoTrie.cjs.map +1 -0
- package/__cjs/utilities/internal/makeStreamInfoTrie.d.cts +8 -0
- package/__cjs/utilities/internal/types/DeferInfo.cjs +3 -0
- package/__cjs/utilities/internal/types/DeferInfo.cjs.map +1 -0
- package/__cjs/utilities/internal/types/DeferInfo.d.cts +10 -0
- package/__cjs/utilities/internal/types/StreamInfoTrie.d.cts +2 -0
- package/__cjs/version.cjs +1 -1
- package/cache/core/types/Cache.d.ts +25 -0
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/index.d.ts +1 -1
- package/cache/index.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +7 -3
- package/cache/inmemory/inMemoryCache.js +5 -1
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +11 -2
- package/cache/inmemory/readFromStore.js +454 -43
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +12 -2
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.js +2 -6
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/QueryInfo.d.ts +8 -2
- package/core/QueryInfo.js +87 -173
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.js +3 -1
- package/core/QueryManager.js.map +1 -1
- package/incremental/handlers/defer20220824.d.ts +2 -4
- package/incremental/handlers/defer20220824.js.map +1 -1
- package/incremental/handlers/graphql17Alpha9.d.ts +5 -5
- package/incremental/handlers/graphql17Alpha9.js +21 -13
- package/incremental/handlers/graphql17Alpha9.js.map +1 -1
- package/incremental/types.d.ts +16 -3
- package/incremental/types.js.map +1 -1
- package/package.json +1 -1
- package/utilities/caching/sizes.d.ts +39 -1
- package/utilities/caching/sizes.js.map +1 -1
- package/utilities/internal/StreamArrayState.d.ts +12 -0
- package/utilities/internal/StreamArrayState.js +23 -0
- package/utilities/internal/StreamArrayState.js.map +1 -0
- package/utilities/internal/constants.d.ts +19 -0
- package/utilities/internal/constants.js +19 -0
- package/utilities/internal/constants.js.map +1 -1
- package/utilities/internal/getFragmentFromSelection.js +1 -1
- package/utilities/internal/getFragmentFromSelection.js.map +1 -1
- package/utilities/internal/getMemoryInternals.d.ts +4 -0
- package/utilities/internal/getMemoryInternals.js +6 -0
- package/utilities/internal/getMemoryInternals.js.map +1 -1
- package/utilities/internal/index.d.ts +5 -3
- package/utilities/internal/index.js +4 -2
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/isDeferredFragment.d.ts +7 -2
- package/utilities/internal/isDeferredFragment.js +19 -4
- package/utilities/internal/isDeferredFragment.js.map +1 -1
- package/utilities/internal/isStreamField.d.ts +9 -0
- package/utilities/internal/isStreamField.js +34 -0
- package/utilities/internal/isStreamField.js.map +1 -0
- package/utilities/internal/makeStreamInfoTrie.d.ts +8 -0
- package/utilities/internal/makeStreamInfoTrie.js +14 -0
- package/utilities/internal/makeStreamInfoTrie.js.map +1 -0
- package/utilities/internal/types/DeferInfo.d.ts +10 -0
- package/utilities/internal/types/DeferInfo.js +2 -0
- package/utilities/internal/types/DeferInfo.js.map +1 -0
- package/utilities/internal/types/StreamInfoTrie.d.ts +2 -0
- package/utilities/internal/types/StreamInfoTrie.js.map +1 -1
- package/version.js +1 -1
- package/__cjs/utilities/internal/collectSiblingFields.cjs +0 -61
- package/__cjs/utilities/internal/collectSiblingFields.cjs.map +0 -1
- package/__cjs/utilities/internal/collectSiblingFields.d.cts +0 -21
- package/utilities/internal/collectSiblingFields.d.ts +0 -21
- package/utilities/internal/collectSiblingFields.js +0 -58
- package/utilities/internal/collectSiblingFields.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cache.js","sourceRoot":"","sources":["../../../../src/cache/core/types/Cache.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n DataValue,\n DocumentNode,\n OperationVariables,\n TypedDocumentNode,\n TypeOverrides,\n} from \"@apollo/client\";\nimport type { Unmasked } from \"@apollo/client/masking\";\nimport type { ExtensionsWithStreamInfo } from \"@apollo/client/utilities/internal\";\n\nimport type { ApolloCache } from \"../cache.js\";\n\nimport type {\n AllFieldsModifier,\n MissingFieldError,\n Modifiers,\n} from \"./common.js\";\nexport declare namespace Cache {\n export type WatchCallback<TData = unknown> = (\n diff: Cache.DiffResult<TData>,\n lastDiff?: Cache.DiffResult<TData>\n ) => void;\n\n export type Implementation =\n TypeOverrides extends { cache: infer TCache } ?\n TCache extends ApolloCache ?\n TCache\n : \"The cache type declared in TypeOverrides does not extend `ApolloCache` and cannot be used with Apollo Client. See https://www.apollographql.com/docs/react/data/typescript#declaring-the-cache-type.\"\n : ApolloCache;\n\n export interface ReadOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes writeQuery capable of writing data\n * to any object in the cache.\n */\n id?: string;\n rootId?: string;\n previousResult?: any;\n optimistic: boolean;\n returnPartialData?: boolean;\n }\n\n export interface WriteOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n dataId?: string;\n result: Unmasked<TData>;\n\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n\n /**\n * GraphQL extensions for the write operation. Any provided `extensions`\n * are available in `merge` functions.\n */\n extensions?: ExtensionsWithStreamInfo;\n }\n\n export interface DiffOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends Omit<ReadOptions<TData, TVariables>, \"rootId\"> {\n // The DiffOptions interface is currently just an alias for\n // ReadOptions, though DiffOptions used to be responsible for\n // declaring the returnPartialData option.\n }\n\n export interface WatchOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends DiffOptions<TData, TVariables> {\n watcher?: object;\n immediate?: boolean;\n callback: WatchCallback<TData>;\n lastDiff?: DiffResult<TData>;\n }\n\n export interface EvictOptions {\n id?: string;\n fieldName?: string;\n args?: Record<string, any>;\n broadcast?: boolean;\n }\n\n // Although you can call cache.reset() without options, its behavior can be\n // configured by passing a Cache.ResetOptions object.\n export interface ResetOptions {\n discardWatches?: boolean;\n }\n\n export interface ModifyOptions<\n Entity extends Record<string, any> = Record<string, any>,\n > {\n id?: string;\n fields: Modifiers<Entity> | AllFieldsModifier<Entity>;\n optimistic?: boolean;\n broadcast?: boolean;\n }\n\n export interface BatchOptions<\n TCache extends Cache.Implementation,\n TUpdateResult = void,\n > {\n /**\n * A function that performs cache operations. Receives the cache instance as its argument.\n *\n * The return value of this function becomes the return value of `batch`.\n */\n update(cache: TCache): TUpdateResult;\n\n /**\n * Controls how optimistic data is handled:\n *\n * - `string`: Creates a new optimistic layer with this ID. Use `removeOptimistic` later to remove it.\n * - `true`: Updates the current top layer of the cache (including any optimistic data).\n * - `false`: Updates only the root (non-optimistic) cache data.\n *\n * @defaultValue false\n */\n optimistic?: string | boolean;\n\n /**\n * If provided, removes the optimistic layer with this ID after the batch completes.\n *\n * This is useful for atomically applying server data while removing a pending optimistic update, triggering at most one broadcast for both operations.\n *\n * Note: this option is needed because calling `cache.removeOptimistic` during the transaction function may not be safe, since any modifications to cache layers may be discarded after the transaction finishes.\n */\n removeOptimistic?: string;\n\n /**\n * Optional callback invoked for each watcher affected by the batch operation.\n *\n * Receives the watch options, the new diff result, and optionally the previous diff result.\n *\n * Return `false` to prevent broadcasting to that specific watcher.\n */\n onWatchUpdated?: (\n this: TCache,\n watch: Cache.WatchOptions,\n diff: Cache.DiffResult<any>,\n lastDiff?: Cache.DiffResult<any> | undefined\n ) => any;\n }\n\n export interface ReadQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes readQuery capable of reading data\n * from any object in the cache.\n */\n id?: string;\n /**\n * Whether to return incomplete data rather than null.\n * @defaultValue false\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted.\n * @defaultValue false\n */\n optimistic?: boolean;\n }\n\n export type ReadFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to specify which\n * fragment is the root fragment.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that your GraphQL fragments depend on.\n */\n variables?: TVariables;\n\n /**\n * Whether to return incomplete data rather than null.\n * @defaultValue false\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readFragment method can be omitted.\n * @defaultValue false\n */\n optimistic?: boolean;\n } & Cache.CacheIdentifierOption<TData>;\n\n export interface WriteQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes writeQuery capable of writing data\n * to any object in the cache.\n */\n id?: string;\n\n /**\n * The data to write to the store.\n */\n data: Unmasked<TData>;\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n\n /**\n * GraphQL extensions for the write operation. Any provided `extensions`\n * are available in `merge` functions.\n */\n extensions?: ExtensionsWithStreamInfo;\n }\n\n export type WriteFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = {\n /**\n * A GraphQL document created using the `gql` template string\n * with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to specify specify which\n * fragment is the root fragment.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that your GraphQL fragments depend on.\n */\n variables?: TVariables;\n /**\n * The data to write to the store.\n */\n data: Unmasked<TData>;\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n } & Cache.CacheIdentifierOption<TData>;\n\n export interface UpdateQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > extends Omit<\n ReadQueryOptions<TData, TVariables> &\n WriteQueryOptions<TData, TVariables>,\n \"data\"\n > {}\n\n export type UpdateFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = Omit<\n ReadFragmentOptions<TData, TVariables> &\n WriteFragmentOptions<TData, TVariables>,\n \"data\" | \"id\" | \"from\"\n > &\n Cache.CacheIdentifierOption<TData>;\n\n export type DiffResult<TData> =\n | {\n result: DataValue.Complete<TData>;\n complete: true;\n missing?: never;\n fromOptimisticTransaction?: boolean;\n }\n | {\n result: DataValue.Partial<TData> | null;\n complete: false;\n missing?: MissingFieldError;\n fromOptimisticTransaction?: boolean;\n };\n\n export type CacheIdentifierOption<TData> =\n | {\n /**\n * The root id to be used. This id should take the same form as the\n * value returned by the `cache.identify` function. If a value with your\n * id does not exist in the store, `null` will be returned.\n */\n id?: string;\n\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @remarks\n * `from` is given precedence over `id` when both are provided.\n */\n from?: never;\n }\n | {\n /**\n * The root id to be used. This id should take the same form as the\n * value returned by the `cache.identify` function. If a value with your\n * id does not exist in the store, `null` will be returned.\n */\n id?: never;\n\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @remarks\n * `from` is given precedence over `id` when both are provided.\n */\n from?: ApolloCache.FromOptionValue<TData>;\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Cache.js","sourceRoot":"","sources":["../../../../src/cache/core/types/Cache.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n DataValue,\n DocumentNode,\n OperationVariables,\n TypedDocumentNode,\n TypeOverrides,\n} from \"@apollo/client\";\nimport type { Unmasked } from \"@apollo/client/masking\";\nimport type { ExtensionsWithStreamInfo } from \"@apollo/client/utilities/internal\";\n\nimport type { ApolloCache } from \"../cache.js\";\n\nimport type {\n AllFieldsModifier,\n MissingFieldError,\n Modifiers,\n} from \"./common.js\";\nexport declare namespace Cache {\n export type WatchCallback<TData = unknown> = (\n diff: Cache.DiffResult<TData>,\n lastDiff?: Cache.DiffResult<TData>\n ) => void;\n\n export type Implementation =\n TypeOverrides extends { cache: infer TCache } ?\n TCache extends ApolloCache ?\n TCache\n : \"The cache type declared in TypeOverrides does not extend `ApolloCache` and cannot be used with Apollo Client. See https://www.apollographql.com/docs/react/data/typescript#declaring-the-cache-type.\"\n : ApolloCache;\n\n export interface ReadOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes writeQuery capable of writing data\n * to any object in the cache.\n */\n id?: string;\n rootId?: string;\n previousResult?: any;\n optimistic: boolean;\n returnPartialData?: boolean;\n }\n\n export interface WriteOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n dataId?: string;\n result: Unmasked<TData>;\n\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n\n /**\n * GraphQL extensions for the write operation. Any provided `extensions`\n * are available in `merge` functions.\n */\n extensions?: ExtensionsWithStreamInfo;\n }\n\n export interface DiffOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends Omit<ReadOptions<TData, TVariables>, \"rootId\"> {\n // The DiffOptions interface is currently just an alias for\n // ReadOptions, though DiffOptions used to be responsible for\n // declaring the returnPartialData option.\n }\n\n export interface WatchOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends DiffOptions<TData, TVariables> {\n watcher?: object;\n immediate?: boolean;\n callback: WatchCallback<TData>;\n lastDiff?: DiffResult<TData>;\n }\n\n export interface EvictOptions {\n id?: string;\n fieldName?: string;\n args?: Record<string, any>;\n broadcast?: boolean;\n }\n\n // Although you can call cache.reset() without options, its behavior can be\n // configured by passing a Cache.ResetOptions object.\n export interface ResetOptions {\n discardWatches?: boolean;\n }\n\n export interface ModifyOptions<\n Entity extends Record<string, any> = Record<string, any>,\n > {\n id?: string;\n fields: Modifiers<Entity> | AllFieldsModifier<Entity>;\n optimistic?: boolean;\n broadcast?: boolean;\n }\n\n export interface BatchOptions<\n TCache extends Cache.Implementation,\n TUpdateResult = void,\n > {\n /**\n * A function that performs cache operations. Receives the cache instance as its argument.\n *\n * The return value of this function becomes the return value of `batch`.\n */\n update(cache: TCache): TUpdateResult;\n\n /**\n * Controls how optimistic data is handled:\n *\n * - `string`: Creates a new optimistic layer with this ID. Use `removeOptimistic` later to remove it.\n * - `true`: Updates the current top layer of the cache (including any optimistic data).\n * - `false`: Updates only the root (non-optimistic) cache data.\n *\n * @defaultValue false\n */\n optimistic?: string | boolean;\n\n /**\n * If provided, removes the optimistic layer with this ID after the batch completes.\n *\n * This is useful for atomically applying server data while removing a pending optimistic update, triggering at most one broadcast for both operations.\n *\n * Note: this option is needed because calling `cache.removeOptimistic` during the transaction function may not be safe, since any modifications to cache layers may be discarded after the transaction finishes.\n */\n removeOptimistic?: string;\n\n /**\n * Optional callback invoked for each watcher affected by the batch operation.\n *\n * Receives the watch options, the new diff result, and optionally the previous diff result.\n *\n * Return `false` to prevent broadcasting to that specific watcher.\n */\n onWatchUpdated?: (\n this: TCache,\n watch: Cache.WatchOptions,\n diff: Cache.DiffResult<any>,\n lastDiff?: Cache.DiffResult<any> | undefined\n ) => any;\n }\n\n export interface ReadQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes readQuery capable of reading data\n * from any object in the cache.\n */\n id?: string;\n /**\n * Whether to return incomplete data rather than null.\n * @defaultValue false\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted.\n * @defaultValue false\n */\n optimistic?: boolean;\n }\n\n export type ReadFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to specify which\n * fragment is the root fragment.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that your GraphQL fragments depend on.\n */\n variables?: TVariables;\n\n /**\n * Whether to return incomplete data rather than null.\n * @defaultValue false\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readFragment method can be omitted.\n * @defaultValue false\n */\n optimistic?: boolean;\n } & Cache.CacheIdentifierOption<TData>;\n\n export interface WriteQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes writeQuery capable of writing data\n * to any object in the cache.\n */\n id?: string;\n\n /**\n * The data to write to the store.\n */\n data: Unmasked<TData>;\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n\n /**\n * GraphQL extensions for the write operation. Any provided `extensions`\n * are available in `merge` functions.\n */\n extensions?: ExtensionsWithStreamInfo;\n }\n\n export type WriteFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = {\n /**\n * A GraphQL document created using the `gql` template string\n * with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to specify specify which\n * fragment is the root fragment.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that your GraphQL fragments depend on.\n */\n variables?: TVariables;\n /**\n * The data to write to the store.\n */\n data: Unmasked<TData>;\n /**\n * Whether to notify query watchers.\n * @defaultValue true\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data.\n * @defaultValue false\n */\n overwrite?: boolean;\n } & Cache.CacheIdentifierOption<TData>;\n\n export interface UpdateQueryOptions<\n TData,\n TVariables extends OperationVariables,\n > extends Omit<\n ReadQueryOptions<TData, TVariables> &\n WriteQueryOptions<TData, TVariables>,\n \"data\"\n > {}\n\n export type UpdateFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > = Omit<\n ReadFragmentOptions<TData, TVariables> &\n WriteFragmentOptions<TData, TVariables>,\n \"data\" | \"id\" | \"from\"\n > &\n Cache.CacheIdentifierOption<TData>;\n\n export type DiffResult<TData> =\n | {\n result: DataValue.Complete<TData>;\n complete: true;\n missing?: never;\n fromOptimisticTransaction?: boolean;\n }\n | {\n result: DataValue.Partial<TData> | null;\n complete: false;\n missing?: MissingFieldError;\n fromOptimisticTransaction?: boolean;\n };\n\n export type InternalDiffResultWithDataState<TData> =\n | {\n result: DataValue.Complete<TData>;\n complete: true;\n missing?: never;\n dataState: \"complete\";\n fromOptimisticTransaction?: boolean;\n }\n | {\n result: DataValue.Streaming<TData>;\n complete: false;\n missing?: never;\n dataState: \"streaming\";\n fromOptimisticTransaction?: boolean;\n }\n | {\n result: DataValue.Partial<TData>;\n complete: false;\n missing?: MissingFieldError;\n dataState: \"partial\";\n fromOptimisticTransaction?: boolean;\n }\n | {\n result: null;\n complete: false;\n missing?: MissingFieldError;\n dataState: \"empty\";\n fromOptimisticTransaction?: boolean;\n };\n\n export type CacheIdentifierOption<TData> =\n | {\n /**\n * The root id to be used. This id should take the same form as the\n * value returned by the `cache.identify` function. If a value with your\n * id does not exist in the store, `null` will be returned.\n */\n id?: string;\n\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @remarks\n * `from` is given precedence over `id` when both are provided.\n */\n from?: never;\n }\n | {\n /**\n * The root id to be used. This id should take the same form as the\n * value returned by the `cache.identify` function. If a value with your\n * id does not exist in the store, `null` will be returned.\n */\n id?: never;\n\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @remarks\n * `from` is given precedence over `id` when both are provided.\n */\n from?: ApolloCache.FromOptionValue<TData>;\n };\n}\n"]}
|
package/cache/index.d.ts
CHANGED
|
@@ -16,5 +16,5 @@ export type { FieldFunctionOptions, FieldMergeFunction, FieldMergeFunctionOption
|
|
|
16
16
|
export { Policies } from "./inmemory/policies.js";
|
|
17
17
|
export type { FragmentRegistryAPI } from "./inmemory/fragmentRegistry.js";
|
|
18
18
|
export { createFragmentRegistry } from "./inmemory/fragmentRegistry.js";
|
|
19
|
-
export type { ApolloReducerConfig, DiffQueryAgainstStoreOptions, IdGetter, IdGetterObj, InMemoryCacheConfig, InputObjectConfig, InputObjectsOption, MergeInfo, MergeTree, NormalizedCache, NormalizedCacheObject, OptimisticStoreItem, ReadMergeModifyContext, ReadQueryOptions, StoreObject, StoreValue, } from "./inmemory/types.js";
|
|
19
|
+
export type { ApolloReducerConfig, DiffIncrementalInfo, DiffQueryAgainstStoreOptions, IdGetter, IdGetterObj, InMemoryCacheConfig, InputObjectConfig, InputObjectsOption, MergeInfo, MergeTree, NormalizedCache, NormalizedCacheObject, OptimisticStoreItem, ReadMergeModifyContext, ReadQueryOptions, StoreObject, StoreValue, } from "./inmemory/types.js";
|
|
20
20
|
//# sourceMappingURL=index.d.ts.map
|
package/cache/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cache/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAU1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAchE,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGlD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC","sourcesContent":["export type { Transaction } from \"./core/cache.js\";\nexport type {\n WatchFragmentOptions,\n WatchFragmentResult,\n} from \"./deprecated.js\";\nexport { ApolloCache } from \"./core/cache.js\";\nexport { Scalar } from \"./core/Scalar.js\";\nexport type { Cache } from \"./core/types/Cache.js\";\nexport type {\n IgnoreModifier,\n MissingTree,\n Modifier,\n ModifierDetails,\n Modifiers,\n ReadFieldOptions,\n} from \"./core/types/common.js\";\nexport { MissingFieldError } from \"./core/types/common.js\";\n\nexport type { Reference } from \"@apollo/client/utilities\";\nexport { canonicalStringify, isReference } from \"@apollo/client/utilities\";\n\nexport { EntityStore } from \"./inmemory/entityStore.js\";\nexport {\n defaultDataIdFromObject,\n fieldNameFromStoreName,\n} from \"./inmemory/helpers.js\";\n\nexport { InMemoryCache } from \"./inmemory/inMemoryCache.js\";\n\nexport type { ReactiveVar } from \"./inmemory/reactiveVars.js\";\nexport { cacheSlot, makeVar } from \"./inmemory/reactiveVars.js\";\n\nexport type {\n FieldFunctionOptions,\n FieldMergeFunction,\n FieldMergeFunctionOptions,\n FieldPolicy,\n FieldReadFunction,\n FieldReadFunctionOptions,\n KeyArgsFunction,\n PossibleTypesMap,\n TypePolicies,\n TypePolicy,\n} from \"./inmemory/policies.js\";\nexport { Policies } from \"./inmemory/policies.js\";\n\nexport type { FragmentRegistryAPI } from \"./inmemory/fragmentRegistry.js\";\nexport { createFragmentRegistry } from \"./inmemory/fragmentRegistry.js\";\n\nexport type {\n ApolloReducerConfig,\n DiffQueryAgainstStoreOptions,\n IdGetter,\n IdGetterObj,\n InMemoryCacheConfig,\n InputObjectConfig,\n InputObjectsOption,\n MergeInfo,\n MergeTree,\n NormalizedCache,\n NormalizedCacheObject,\n OptimisticStoreItem,\n ReadMergeModifyContext,\n ReadQueryOptions,\n StoreObject,\n StoreValue,\n} from \"./inmemory/types.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cache/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAU1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAchE,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGlD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC","sourcesContent":["export type { Transaction } from \"./core/cache.js\";\nexport type {\n WatchFragmentOptions,\n WatchFragmentResult,\n} from \"./deprecated.js\";\nexport { ApolloCache } from \"./core/cache.js\";\nexport { Scalar } from \"./core/Scalar.js\";\nexport type { Cache } from \"./core/types/Cache.js\";\nexport type {\n IgnoreModifier,\n MissingTree,\n Modifier,\n ModifierDetails,\n Modifiers,\n ReadFieldOptions,\n} from \"./core/types/common.js\";\nexport { MissingFieldError } from \"./core/types/common.js\";\n\nexport type { Reference } from \"@apollo/client/utilities\";\nexport { canonicalStringify, isReference } from \"@apollo/client/utilities\";\n\nexport { EntityStore } from \"./inmemory/entityStore.js\";\nexport {\n defaultDataIdFromObject,\n fieldNameFromStoreName,\n} from \"./inmemory/helpers.js\";\n\nexport { InMemoryCache } from \"./inmemory/inMemoryCache.js\";\n\nexport type { ReactiveVar } from \"./inmemory/reactiveVars.js\";\nexport { cacheSlot, makeVar } from \"./inmemory/reactiveVars.js\";\n\nexport type {\n FieldFunctionOptions,\n FieldMergeFunction,\n FieldMergeFunctionOptions,\n FieldPolicy,\n FieldReadFunction,\n FieldReadFunctionOptions,\n KeyArgsFunction,\n PossibleTypesMap,\n TypePolicies,\n TypePolicy,\n} from \"./inmemory/policies.js\";\nexport { Policies } from \"./inmemory/policies.js\";\n\nexport type { FragmentRegistryAPI } from \"./inmemory/fragmentRegistry.js\";\nexport { createFragmentRegistry } from \"./inmemory/fragmentRegistry.js\";\n\nexport type {\n ApolloReducerConfig,\n DiffIncrementalInfo,\n DiffQueryAgainstStoreOptions,\n IdGetter,\n IdGetterObj,\n InMemoryCacheConfig,\n InputObjectConfig,\n InputObjectsOption,\n MergeInfo,\n MergeTree,\n NormalizedCache,\n NormalizedCacheObject,\n OptimisticStoreItem,\n ReadMergeModifyContext,\n ReadQueryOptions,\n StoreObject,\n StoreValue,\n} from \"./inmemory/types.js\";\n"]}
|
|
@@ -2,13 +2,13 @@ import type { DocumentNode, FragmentDefinitionNode, InlineFragmentNode } from "g
|
|
|
2
2
|
import type { OperationVariables, TypedDocumentNode } from "@apollo/client";
|
|
3
3
|
import type { DeepPartial, Reference, StoreObject } from "@apollo/client/utilities";
|
|
4
4
|
import type { IsLooselyEqual, NoInfer } from "@apollo/client/utilities/internal";
|
|
5
|
-
import { getInMemoryCacheMemoryInternals } from "@apollo/client/utilities/internal";
|
|
5
|
+
import { getInMemoryCacheMemoryInternals, handleIncrementalSymbol } from "@apollo/client/utilities/internal";
|
|
6
6
|
import { ApolloCache } from "../core/cache.js";
|
|
7
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 { InMemoryCacheConfig, KnownScalars, NormalizedCacheObject } from "./types.js";
|
|
11
|
+
import type { DiffIncrementalInfo, InMemoryCacheConfig, KnownScalars, NormalizedCacheObject } from "./types.js";
|
|
12
12
|
type BroadcastOptions = Pick<Cache.BatchOptions<InMemoryCache>, "optimistic" | "onWatchUpdated">;
|
|
13
13
|
export declare namespace InMemoryCache {
|
|
14
14
|
type ScalarsOption = {
|
|
@@ -36,6 +36,7 @@ export declare class InMemoryCache extends ApolloCache {
|
|
|
36
36
|
private addTypenameTransform;
|
|
37
37
|
private maybeBroadcastWatch;
|
|
38
38
|
readonly assumeImmutableResults = true;
|
|
39
|
+
readonly [handleIncrementalSymbol] = true;
|
|
39
40
|
readonly policies: Policies;
|
|
40
41
|
readonly makeVar: typeof makeVar;
|
|
41
42
|
constructor(...args: {} extends InMemoryCache.ScalarsOption ? [
|
|
@@ -63,7 +64,10 @@ export declare class InMemoryCache extends ApolloCache {
|
|
|
63
64
|
read<TData = unknown>(options: Cache.ReadOptions<TData, OperationVariables>): TData | null;
|
|
64
65
|
write<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: Cache.WriteOptions<TData, TVariables>): Reference | undefined;
|
|
65
66
|
modify<Entity extends Record<string, any> = Record<string, any>>(options: Cache.ModifyOptions<Entity>): boolean;
|
|
66
|
-
diff<TData = unknown, TVariables extends OperationVariables = OperationVariables>(
|
|
67
|
+
diff<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: Cache.DiffOptions<TData, TVariables> & {
|
|
68
|
+
[handleIncrementalSymbol]: true | DiffIncrementalInfo;
|
|
69
|
+
}): Cache.InternalDiffResultWithDataState<TData>;
|
|
70
|
+
diff<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: Cache.DiffOptions<TData, TVariables>): Cache.DiffResult<TData>;
|
|
67
71
|
watch<TData = unknown, TVariables extends OperationVariables = OperationVariables>(watch: Cache.WatchOptions<TData, TVariables>): () => void;
|
|
68
72
|
gc(options?: {
|
|
69
73
|
resetResultCache?: boolean;
|
|
@@ -2,7 +2,7 @@ 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, getUnwrappedType, handleIncrementalSymbol, isPlainObject, } 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";
|
|
@@ -23,6 +23,10 @@ export class InMemoryCache extends ApolloCache {
|
|
|
23
23
|
// Override the default value, since InMemoryCache result objects are frozen
|
|
24
24
|
// in development and expected to remain logically immutable in production.
|
|
25
25
|
assumeImmutableResults = true;
|
|
26
|
+
// InMemoryCache can handle incremental results in cache.diff. 3rd party
|
|
27
|
+
// caches that want to handle incremental results should talk to the Apollo
|
|
28
|
+
// Client team on how to handle this in Apollo Client 4.x.
|
|
29
|
+
[handleIncrementalSymbol] = true;
|
|
26
30
|
// Dynamically imported code can augment existing typePolicies or
|
|
27
31
|
// possibleTypes by calling cache.policies.addTypePolicies or
|
|
28
32
|
// cache.policies.addPossibletypes.
|