@apollo/client 4.1.0-alpha.5 → 4.1.0-alpha.7

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.
@@ -110,13 +110,7 @@ export declare namespace Cache {
110
110
  */
111
111
  optimistic?: boolean;
112
112
  }
113
- interface ReadFragmentOptions<TData, TVariables extends OperationVariables> {
114
- /**
115
- * The root id to be used. This id should take the same form as the
116
- * value returned by the `cache.identify` function. If a value with your
117
- * id does not exist in the store, `null` will be returned.
118
- */
119
- id?: string;
113
+ type ReadFragmentOptions<TData, TVariables extends OperationVariables> = {
120
114
  /**
121
115
  * A GraphQL document created using the `gql` template string tag from
122
116
  * `graphql-tag` with one or more fragments which will be used to determine
@@ -147,7 +141,7 @@ export declare namespace Cache {
147
141
  * @defaultValue false
148
142
  */
149
143
  optimistic?: boolean;
150
- }
144
+ } & Cache.CacheIdentifierOption<TData>;
151
145
  interface WriteQueryOptions<TData, TVariables extends OperationVariables> {
152
146
  /**
153
147
  * The GraphQL query shape to be used constructed using the `gql` template
@@ -181,13 +175,7 @@ export declare namespace Cache {
181
175
  */
182
176
  overwrite?: boolean;
183
177
  }
184
- interface WriteFragmentOptions<TData, TVariables extends OperationVariables> {
185
- /**
186
- * The root id to be used. This id should take the same form as the
187
- * value returned by the `cache.identify` function. If a value with your
188
- * id does not exist in the store, `null` will be returned.
189
- */
190
- id?: string;
178
+ type WriteFragmentOptions<TData, TVariables extends OperationVariables> = {
191
179
  /**
192
180
  * A GraphQL document created using the `gql` template string
193
181
  * with one or more fragments which will be used to determine
@@ -221,11 +209,10 @@ export declare namespace Cache {
221
209
  * @defaultValue false
222
210
  */
223
211
  overwrite?: boolean;
224
- }
212
+ } & Cache.CacheIdentifierOption<TData>;
225
213
  interface UpdateQueryOptions<TData, TVariables extends OperationVariables> extends Omit<ReadQueryOptions<TData, TVariables> & WriteQueryOptions<TData, TVariables>, "data"> {
226
214
  }
227
- interface UpdateFragmentOptions<TData, TVariables extends OperationVariables> extends Omit<ReadFragmentOptions<TData, TVariables> & WriteFragmentOptions<TData, TVariables>, "data"> {
228
- }
215
+ type UpdateFragmentOptions<TData, TVariables extends OperationVariables> = Omit<ReadFragmentOptions<TData, TVariables> & WriteFragmentOptions<TData, TVariables>, "data" | "id" | "from"> & Cache.CacheIdentifierOption<TData>;
229
216
  type DiffResult<TData> = {
230
217
  result: DataValue.Complete<TData>;
231
218
  complete: true;
@@ -237,5 +224,40 @@ export declare namespace Cache {
237
224
  missing?: MissingFieldError;
238
225
  fromOptimisticTransaction?: boolean;
239
226
  };
227
+ type CacheIdentifierOption<TData> = {
228
+ /**
229
+ * The root id to be used. This id should take the same form as the
230
+ * value returned by the `cache.identify` function. If a value with your
231
+ * id does not exist in the store, `null` will be returned.
232
+ */
233
+ id?: string;
234
+ /**
235
+ * An object containing a `__typename` and primary key fields
236
+ * (such as `id`) identifying the entity object from which the fragment will
237
+ * be retrieved, or a `{ __ref: "..." }` reference, or a `string` ID
238
+ * (uncommon).
239
+ *
240
+ * @remarks
241
+ * `from` is given precedence over `id` when both are provided.
242
+ */
243
+ from?: never;
244
+ } | {
245
+ /**
246
+ * The root id to be used. This id should take the same form as the
247
+ * value returned by the `cache.identify` function. If a value with your
248
+ * id does not exist in the store, `null` will be returned.
249
+ */
250
+ id?: never;
251
+ /**
252
+ * An object containing a `__typename` and primary key fields
253
+ * (such as `id`) identifying the entity object from which the fragment will
254
+ * be retrieved, or a `{ __ref: "..." }` reference, or a `string` ID
255
+ * (uncommon).
256
+ *
257
+ * @remarks
258
+ * `from` is given precedence over `id` when both are provided.
259
+ */
260
+ from?: ApolloCache.FromOptionValue<TData>;
261
+ };
240
262
  }
241
263
  //# sourceMappingURL=Cache.d.ts.map
@@ -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} from \"@apollo/client\";\nimport type { Unmasked } from \"@apollo/client/masking\";\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 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 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 ApolloCache,\n TUpdateResult = void,\n > {\n // Same as the first parameter of performTransaction, except the cache\n // argument will have the subclass type rather than ApolloCache.\n update(cache: TCache): TUpdateResult;\n\n // Passing a string for this option creates a new optimistic layer, with the\n // given string as its layer.id, just like passing a string for the\n // optimisticId parameter of performTransaction. Passing true is the same as\n // passing undefined to performTransaction (running the batch operation\n // against the current top layer of the cache), and passing false is the\n // same as passing null (running the operation against root/non-optimistic\n // cache data).\n optimistic?: string | boolean;\n\n // If you specify the ID of an optimistic layer using this option, that\n // layer will be removed as part of the batch transaction, triggering at\n // most one broadcast for both the transaction and the removal of the layer.\n // Note: this option is needed because calling cache.removeOptimistic during\n // the transaction function may not be not safe, since any modifications to\n // cache layers may be discarded after the transaction finishes.\n removeOptimistic?: string;\n\n // If you want to find out which watched queries were invalidated during\n // this batch operation, pass this optional callback function. Returning\n // false from the callback will prevent broadcasting this result.\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 interface ReadFragmentOptions<\n TData,\n TVariables extends OperationVariables,\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 * 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 }\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 export interface WriteFragmentOptions<\n TData,\n TVariables extends OperationVariables,\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 * 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 }\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 interface UpdateFragmentOptions<\n TData,\n TVariables extends OperationVariables,\n > extends Omit<\n ReadFragmentOptions<TData, TVariables> &\n WriteFragmentOptions<TData, TVariables>,\n \"data\"\n > {}\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"]}
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} from \"@apollo/client\";\nimport type { Unmasked } from \"@apollo/client/masking\";\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 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 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 ApolloCache,\n TUpdateResult = void,\n > {\n // Same as the first parameter of performTransaction, except the cache\n // argument will have the subclass type rather than ApolloCache.\n update(cache: TCache): TUpdateResult;\n\n // Passing a string for this option creates a new optimistic layer, with the\n // given string as its layer.id, just like passing a string for the\n // optimisticId parameter of performTransaction. Passing true is the same as\n // passing undefined to performTransaction (running the batch operation\n // against the current top layer of the cache), and passing false is the\n // same as passing null (running the operation against root/non-optimistic\n // cache data).\n optimistic?: string | boolean;\n\n // If you specify the ID of an optimistic layer using this option, that\n // layer will be removed as part of the batch transaction, triggering at\n // most one broadcast for both the transaction and the removal of the layer.\n // Note: this option is needed because calling cache.removeOptimistic during\n // the transaction function may not be not safe, since any modifications to\n // cache layers may be discarded after the transaction finishes.\n removeOptimistic?: string;\n\n // If you want to find out which watched queries were invalidated during\n // this batch operation, pass this optional callback function. Returning\n // false from the callback will prevent broadcasting this result.\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 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,6 +1,6 @@
1
1
  import type { DocumentNode } from "graphql";
2
2
  import type { Observable } from "rxjs";
3
- import type { ApolloCache, IgnoreModifier, Reference } from "@apollo/client/cache";
3
+ import type { ApolloCache, Cache, IgnoreModifier, Reference } from "@apollo/client/cache";
4
4
  import type { Incremental } from "@apollo/client/incremental";
5
5
  import type { ApolloLink } from "@apollo/client/link";
6
6
  import type { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
@@ -522,12 +522,6 @@ export declare namespace ApolloClient {
522
522
  }
523
523
  namespace Base {
524
524
  interface ReadFragmentOptions<TData, TVariables extends OperationVariables> {
525
- /**
526
- * The root id to be used. This id should take the same form as the
527
- * value returned by the `cache.identify` function. If a value with your
528
- * id does not exist in the store, `null` will be returned.
529
- */
530
- id?: string;
531
525
  /**
532
526
  * A GraphQL document created using the `gql` template string tag
533
527
  * with one or more fragments which will be used to determine
@@ -556,7 +550,27 @@ export declare namespace ApolloClient {
556
550
  optimistic?: boolean;
557
551
  }
558
552
  }
559
- type ReadFragmentOptions<TData, TVariables extends OperationVariables> = Base.ReadFragmentOptions<TData, TVariables> & VariablesOption<TVariables>;
553
+ namespace DocumentationTypes {
554
+ interface ReadFragmentOptions<TData, TVariables extends OperationVariables> extends Base.ReadFragmentOptions<TData, TVariables> {
555
+ /**
556
+ * The root id to be used. This id should take the same form as the
557
+ * value returned by the `cache.identify` function. If a value with your
558
+ * id does not exist in the store, `null` will be returned.
559
+ */
560
+ id?: string;
561
+ /**
562
+ * An object containing a `__typename` and primary key fields
563
+ * (such as `id`) identifying the entity object from which the fragment will
564
+ * be retrieved, or a `{ __ref: "..." }` reference, or a `string` ID
565
+ * (uncommon).
566
+ *
567
+ * @remarks
568
+ * `from` is given precedence over `id` when both are provided.
569
+ */
570
+ from?: ApolloCache.FromOptionValue<TData>;
571
+ }
572
+ }
573
+ type ReadFragmentOptions<TData, TVariables extends OperationVariables> = Base.ReadFragmentOptions<TData, TVariables> & VariablesOption<TVariables> & Cache.CacheIdentifierOption<TData>;
560
574
  namespace DocumentationTypes {
561
575
  interface WriteQueryOptions<TData, TVariables extends OperationVariables> extends Base.WriteQueryOptions<TData, TVariables> {
562
576
  /**
@@ -607,12 +621,6 @@ export declare namespace ApolloClient {
607
621
  }
608
622
  namespace Base {
609
623
  interface WriteFragmentOptions<TData, TVariables extends OperationVariables> {
610
- /**
611
- * The root id to be used. This id should take the same form as the
612
- * value returned by the `cache.identify` function. If a value with your
613
- * id does not exist in the store, `null` will be returned.
614
- */
615
- id?: string;
616
624
  /**
617
625
  * A GraphQL document created using the `gql` template string tag from
618
626
  * `graphql-tag` with one or more fragments which will be used to determine
@@ -644,9 +652,25 @@ export declare namespace ApolloClient {
644
652
  overwrite?: boolean;
645
653
  }
646
654
  }
647
- type WriteFragmentOptions<TData, TVariables extends OperationVariables> = Base.WriteFragmentOptions<TData, TVariables> & VariablesOption<TVariables>;
655
+ type WriteFragmentOptions<TData, TVariables extends OperationVariables> = Base.WriteFragmentOptions<TData, TVariables> & VariablesOption<TVariables> & Cache.CacheIdentifierOption<TData>;
648
656
  namespace DocumentationTypes {
649
657
  interface WriteFragmentOptions<TData, TVariables extends OperationVariables> extends Base.WriteFragmentOptions<TData, TVariables> {
658
+ /**
659
+ * The root id to be used. This id should take the same form as the
660
+ * value returned by the `cache.identify` function. If a value with your
661
+ * id does not exist in the store, `null` will be returned.
662
+ */
663
+ id?: string;
664
+ /**
665
+ * An object containing a `__typename` and primary key fields
666
+ * (such as `id`) identifying the entity object from which the fragment will
667
+ * be retrieved, or a `{ __ref: "..." }` reference, or a `string` ID
668
+ * (uncommon).
669
+ *
670
+ * @remarks
671
+ * `from` is given precedence over `id` when both are provided.
672
+ */
673
+ from?: ApolloCache.FromOptionValue<TData>;
650
674
  /**
651
675
  * Any variables that your GraphQL fragments depend on.
652
676
  */
@@ -830,7 +854,7 @@ export declare class ApolloClient {
830
854
  * to optimistic updates.
831
855
  */
832
856
  watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables> & {
833
- from: Array<NonNullable<ApolloCache.WatchFragmentFromValue<TData>>>;
857
+ from: Array<ApolloCache.FromOptionValue<TData>>;
834
858
  }): ApolloClient.ObservableFragment<Array<TData>>;
835
859
  /**
836
860
  * Watches the cache store of the fragment according to the options specified
@@ -852,7 +876,7 @@ export declare class ApolloClient {
852
876
  from: Array<null>;
853
877
  }): ApolloClient.ObservableFragment<Array<null>>;
854
878
  watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables> & {
855
- from: Array<ApolloCache.WatchFragmentFromValue<TData>>;
879
+ from: Array<ApolloCache.FromOptionValue<TData> | null>;
856
880
  }): ApolloClient.ObservableFragment<Array<TData | null>>;
857
881
  /**
858
882
  * Watches the cache store of the fragment according to the options specified
@@ -890,7 +914,7 @@ export declare class ApolloClient {
890
914
  * to optimistic updates.
891
915
  */
892
916
  watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables> & {
893
- from: NonNullable<ApolloCache.WatchFragmentFromValue<TData>>;
917
+ from: ApolloCache.FromOptionValue<TData>;
894
918
  }): ApolloClient.ObservableFragment<TData>;
895
919
  /**
896
920
  * Watches the cache store of the fragment according to the options specified
@@ -288,11 +288,7 @@ export class ApolloClient {
288
288
  }
289
289
  watchFragment(options) {
290
290
  const dataMasking = this.queryManager.dataMasking;
291
- const observable = this.cache.watchFragment({
292
- ...options,
293
- fragment: this.transform(options.fragment, dataMasking),
294
- });
295
- const mask = (result) => {
291
+ const mask = (data) => {
296
292
  // The transform will remove fragment spreads from the fragment
297
293
  // document when dataMasking is enabled. The `mask` function
298
294
  // remains to apply warnings to fragments marked as
@@ -300,29 +296,17 @@ export class ApolloClient {
300
296
  // in dev, we can skip the masking algorithm entirely for production.
301
297
  if (__DEV__) {
302
298
  if (dataMasking) {
303
- return {
304
- ...result,
305
- data: this.queryManager.maskFragment({
306
- ...options,
307
- data: result.data,
308
- }),
309
- };
299
+ return this.queryManager.maskFragment({ ...options, data });
310
300
  }
311
301
  }
312
- return result;
302
+ return data;
313
303
  };
314
- let currentResult;
315
- let stableMaskedResult;
316
- return Object.assign(observable.pipe(map(mask)), {
317
- getCurrentResult: () => {
318
- const result = observable.getCurrentResult();
319
- if (result !== currentResult) {
320
- currentResult = result;
321
- stableMaskedResult = mask(currentResult);
322
- }
323
- return stableMaskedResult;
324
- },
304
+ const observable = this.cache.watchFragment({
305
+ ...options,
306
+ fragment: this.transform(options.fragment, dataMasking),
307
+ [Symbol.for("apollo.transformData")]: mask,
325
308
  });
309
+ return observable;
326
310
  }
327
311
  readFragment(options, optimistic = false) {
328
312
  return this.cache.readFragment({ ...options, fragment: this.transform(options.fragment) }, optimistic);