@apollo/client 3.12.7 → 3.12.9
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 +29 -0
- package/apollo-client.cjs +3 -2
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +2 -1
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +2 -1
- package/cache/core/cache.js +4 -1
- package/cache/core/cache.js.map +1 -1
- package/core/core.cjs +1 -1
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +1 -1
- package/dev/dev.cjs +1 -1
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +1 -1
- package/errors/index.d.ts +2 -8
- package/errors/index.js.map +1 -1
- package/link/error/index.d.ts +2 -5
- package/link/error/index.js.map +1 -1
- package/link/retry/retry.cjs +13 -1
- package/link/retry/retry.cjs.map +1 -1
- package/link/retry/retry.cjs.native.js +13 -1
- package/link/retry/retryLink.js +15 -1
- package/link/retry/retryLink.js.map +1 -1
- package/package.json +2 -3
- package/react/internal/internal.cjs +1 -1
- package/react/internal/internal.cjs.map +1 -1
- package/react/internal/internal.cjs.native.js +1 -1
- package/testing/internal/ObservableStream.d.ts +3 -0
- package/testing/internal/ObservableStream.js +30 -1
- package/testing/internal/ObservableStream.js.map +1 -1
- package/testing/matchers/index.js +6 -0
- package/testing/matchers/index.js.map +1 -1
- package/testing/matchers/toEmitAnything.js +1 -1
- package/testing/matchers/toEmitAnything.js.map +1 -1
- package/testing/matchers/toEmitApolloQueryResult.d.ts +8 -0
- package/testing/matchers/toEmitApolloQueryResult.js +51 -0
- package/testing/matchers/toEmitApolloQueryResult.js.map +1 -0
- package/testing/matchers/toEmitFetchResult.d.ts +8 -0
- package/testing/matchers/toEmitFetchResult.js +51 -0
- package/testing/matchers/toEmitFetchResult.js.map +1 -0
- package/testing/matchers/toEqualFetchResult.d.ts +4 -0
- package/testing/matchers/toEqualFetchResult.js +20 -0
- package/testing/matchers/toEqualFetchResult.js.map +1 -0
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/version.js +1 -1
- package/testing/core/mocking/mockQueryManager.d.ts +0 -21
- package/testing/core/mocking/mockQueryManager.js +0 -19
- package/testing/core/mocking/mockQueryManager.js.map +0 -1
- package/testing/core/mocking/mockWatchQuery.d.ts +0 -5
- package/testing/core/mocking/mockWatchQuery.js +0 -15
- package/testing/core/mocking/mockWatchQuery.js.map +0 -1
|
@@ -193,7 +193,8 @@ var ApolloCache = (function () {
|
|
|
193
193
|
: diff.result;
|
|
194
194
|
if (
|
|
195
195
|
latestDiff &&
|
|
196
|
-
equalByQuery(query, { data: latestDiff
|
|
196
|
+
equalByQuery(query, { data: latestDiff.result }, { data: data },
|
|
197
|
+
options.variables)) {
|
|
197
198
|
return;
|
|
198
199
|
}
|
|
199
200
|
var result = {
|
package/cache/core/cache.js
CHANGED
|
@@ -97,7 +97,10 @@ var ApolloCache = /** @class */ (function () {
|
|
|
97
97
|
if (
|
|
98
98
|
// Always ensure we deliver the first result
|
|
99
99
|
latestDiff &&
|
|
100
|
-
equalByQuery(query, { data: latestDiff
|
|
100
|
+
equalByQuery(query, { data: latestDiff.result }, { data: data },
|
|
101
|
+
// TODO: Fix the type on WatchFragmentOptions so that TVars
|
|
102
|
+
// extends OperationVariables
|
|
103
|
+
options.variables)) {
|
|
101
104
|
return;
|
|
102
105
|
}
|
|
103
106
|
var result = {
|
package/cache/core/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/cache/core/cache.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAQhC,OAAO,EACL,UAAU,EACV,UAAU,EAEV,qBAAqB,EACrB,wBAAwB,EACxB,cAAc,GACf,MAAM,0BAA0B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;IACJ,CAAC;IAEM,iCAAW,GAAlB,UACE,OAAoD,EACpD,MAAuE;QAEvE,OAAO,IAAI,CAAC,KAAK,CAAC;YAChB,MAAM,YAAC,KAAK;gBACV,IAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAoB,OAAO,CAAC,CAAC;gBAC1D,IAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC3B,IAAI,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,KAAK,IAAI;oBAAE,OAAO,KAAK,CAAC;gBACnD,KAAK,CAAC,UAAU,uBAAyB,OAAO,KAAE,IAAI,MAAA,IAAG,CAAC;gBAC1D,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAEM,oCAAc,GAArB,UACE,OAAuD,EACvD,MAAuE;QAEvE,OAAO,IAAI,CAAC,KAAK,CAAC;YAChB,MAAM,YAAC,KAAK;gBACV,IAAM,KAAK,GAAG,KAAK,CAAC,YAAY,CAAoB,OAAO,CAAC,CAAC;gBAC7D,IAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC3B,IAAI,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,KAAK,IAAI;oBAAE,OAAO,KAAK,CAAC;gBACnD,KAAK,CAAC,aAAa,uBAAyB,OAAO,KAAE,IAAI,MAAA,IAAG,CAAC;gBAC7D,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAUH,kBAAC;AAAD,CAAC,AA7TD,IA6TC;;AAED,IAAI,OAAO,EAAE,CAAC;IACZ,WAAW,CAAC,SAAS,CAAC,kBAAkB,GAAG,6BAA6B,CAAC;AAC3E,CAAC","sourcesContent":["import type {\n DocumentNode,\n FragmentDefinitionNode,\n InlineFragmentNode,\n} from \"graphql\";\nimport { wrap } from \"optimism\";\n\nimport type {\n StoreObject,\n Reference,\n DeepPartial,\n NoInfer,\n} from \"../../utilities/index.js\";\nimport {\n Observable,\n cacheSizes,\n defaultCacheSizes,\n getFragmentDefinition,\n getFragmentQueryDocument,\n mergeDeepArray,\n} from \"../../utilities/index.js\";\nimport type { DataProxy } from \"./types/DataProxy.js\";\nimport type { Cache } from \"./types/Cache.js\";\nimport { WeakCache } from \"@wry/caches\";\nimport { getApolloCacheMemoryInternals } from \"../../utilities/caching/getMemoryInternals.js\";\nimport type {\n OperationVariables,\n TypedDocumentNode,\n} from \"../../core/types.js\";\nimport type { MissingTree } from \"./types/common.js\";\nimport { equalByQuery } from \"../../core/equalByQuery.js\";\nimport { invariant } from \"../../utilities/globals/index.js\";\nimport { maskFragment } from \"../../masking/index.js\";\nimport type {\n FragmentType,\n MaybeMasked,\n Unmasked,\n} from \"../../masking/index.js\";\n\nexport type Transaction<T> = (c: ApolloCache<T>) => void;\n\n/**\n * Watched fragment options.\n */\nexport interface WatchFragmentOptions<TData, TVars> {\n /**\n * A GraphQL fragment document parsed into an AST with the `gql`\n * template literal.\n *\n * @docGroup 1. Required options\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVars>;\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 * @docGroup 1. Required options\n */\n from: StoreObject | Reference | FragmentType<NoInfer<TData>> | string;\n /**\n * Any variables that the GraphQL fragment may depend on.\n *\n * @docGroup 2. Cache options\n */\n variables?: TVars;\n /**\n * The name of the fragment defined in the fragment document.\n *\n * Required if the fragment document includes more than one fragment,\n * optional otherwise.\n *\n * @docGroup 2. Cache options\n */\n fragmentName?: string;\n /**\n * If `true`, `watchFragment` returns optimistic results.\n *\n * The default value is `true`.\n *\n * @docGroup 2. Cache options\n */\n optimistic?: boolean;\n}\n\n/**\n * Watched fragment results.\n */\nexport type WatchFragmentResult<TData> =\n | {\n data: MaybeMasked<TData>;\n complete: true;\n missing?: never;\n }\n | {\n data: DeepPartial<MaybeMasked<TData>>;\n complete: false;\n missing: MissingTree;\n };\n\nexport abstract class ApolloCache<TSerialized> implements DataProxy {\n public readonly assumeImmutableResults: boolean = false;\n\n // required to implement\n // core API\n public abstract read<TData = any, TVariables = any>(\n query: Cache.ReadOptions<TVariables, TData>\n ): Unmasked<TData> | null;\n public abstract write<TData = any, TVariables = any>(\n write: Cache.WriteOptions<TData, TVariables>\n ): Reference | undefined;\n public abstract diff<T>(query: Cache.DiffOptions): Cache.DiffResult<T>;\n public abstract watch<TData = any, TVariables = any>(\n watch: Cache.WatchOptions<TData, TVariables>\n ): () => void;\n\n // Empty the cache and restart all current watches (unless\n // options.discardWatches is true).\n public abstract reset(options?: Cache.ResetOptions): Promise<void>;\n\n // Remove whole objects from the cache by passing just options.id, or\n // specific fields by passing options.field and/or options.args. If no\n // options.args are provided, all fields matching options.field (even\n // those with arguments) will be removed. Returns true iff any data was\n // removed from the cache.\n public abstract evict(options: Cache.EvictOptions): boolean;\n\n // initializer / offline / ssr API\n /**\n * Replaces existing state in the cache (if any) with the values expressed by\n * `serializedState`.\n *\n * Called when hydrating a cache (server side rendering, or offline storage),\n * and also (potentially) during hot reloads.\n */\n public abstract restore(\n serializedState: TSerialized\n ): ApolloCache<TSerialized>;\n\n /**\n * Exposes the cache's complete state, in a serializable format for later restoration.\n */\n public abstract extract(optimistic?: boolean): TSerialized;\n\n // Optimistic API\n\n public abstract removeOptimistic(id: string): void;\n\n // Data masking API\n\n // Used by data masking to determine if an inline fragment with a type\n // condition matches a given typename.\n //\n // If not implemented by a cache subclass, data masking will effectively be\n // disabled since we will not be able to accurately determine if a given type\n // condition for a union or interface matches a particular type.\n public fragmentMatches?(\n fragment: InlineFragmentNode,\n typename: string\n ): boolean;\n\n // Function used to lookup a fragment when a fragment definition is not part\n // of the GraphQL document. This is useful for caches, such as InMemoryCache,\n // that register fragments ahead of time so they can be referenced by name.\n public lookupFragment(fragmentName: string): FragmentDefinitionNode | null {\n return null;\n }\n\n // Transactional API\n\n // The batch method is intended to replace/subsume both performTransaction\n // and recordOptimisticTransaction, but performTransaction came first, so we\n // provide a default batch implementation that's just another way of calling\n // performTransaction. Subclasses of ApolloCache (such as InMemoryCache) can\n // override the batch method to do more interesting things with its options.\n public batch<U>(options: Cache.BatchOptions<this, U>): U {\n const optimisticId =\n typeof options.optimistic === \"string\" ? options.optimistic\n : options.optimistic === false ? null\n : void 0;\n let updateResult: U;\n this.performTransaction(\n () => (updateResult = options.update(this)),\n optimisticId\n );\n return updateResult!;\n }\n\n public abstract performTransaction(\n transaction: Transaction<TSerialized>,\n // Although subclasses may implement recordOptimisticTransaction\n // however they choose, the default implementation simply calls\n // performTransaction with a string as the second argument, allowing\n // performTransaction to handle both optimistic and non-optimistic\n // (broadcast-batching) transactions. Passing null for optimisticId is\n // also allowed, and indicates that performTransaction should apply\n // the transaction non-optimistically (ignoring optimistic data).\n optimisticId?: string | null\n ): void;\n\n public recordOptimisticTransaction(\n transaction: Transaction<TSerialized>,\n optimisticId: string\n ) {\n this.performTransaction(transaction, optimisticId);\n }\n\n // Optional API\n\n // Called once per input document, allowing the cache to make static changes\n // to the query, such as adding __typename fields.\n public transformDocument(document: DocumentNode): DocumentNode {\n return document;\n }\n\n // Called before each ApolloLink request, allowing the cache to make dynamic\n // changes to the query, such as filling in missing fragment definitions.\n public transformForLink(document: DocumentNode): DocumentNode {\n return document;\n }\n\n public identify(object: StoreObject | Reference): string | undefined {\n return;\n }\n\n public gc(): string[] {\n return [];\n }\n\n public modify<Entity extends Record<string, any> = Record<string, any>>(\n options: Cache.ModifyOptions<Entity>\n ): boolean {\n return false;\n }\n\n // DataProxy API\n public readQuery<QueryType, TVariables = any>(\n options: Cache.ReadQueryOptions<QueryType, TVariables>,\n optimistic = !!options.optimistic\n ): Unmasked<QueryType> | null {\n return this.read({\n ...options,\n rootId: options.id || \"ROOT_QUERY\",\n optimistic,\n });\n }\n\n /** {@inheritDoc @apollo/client!ApolloClient#watchFragment:member(1)} */\n public watchFragment<TData = any, TVars = OperationVariables>(\n options: WatchFragmentOptions<TData, TVars>\n ): Observable<WatchFragmentResult<TData>> {\n const {\n fragment,\n fragmentName,\n from,\n optimistic = true,\n ...otherOptions\n } = options;\n const query = this.getFragmentDoc(fragment, fragmentName);\n // While our TypeScript types do not allow for `undefined` as a valid\n // `from`, its possible `useFragment` gives us an `undefined` since it\n // calls` cache.identify` and provides that value to `from`. We are\n // adding this fix here however to ensure those using plain JavaScript\n // and using `cache.identify` themselves will avoid seeing the obscure\n // warning.\n const id =\n typeof from === \"undefined\" || typeof from === \"string\" ?\n from\n : this.identify(from);\n const dataMasking = !!(options as any)[Symbol.for(\"apollo.dataMasking\")];\n\n if (__DEV__) {\n const actualFragmentName =\n fragmentName || getFragmentDefinition(fragment).name.value;\n\n if (!id) {\n invariant.warn(\n \"Could not identify object passed to `from` for '%s' fragment, either because the object is non-normalized or the key fields are missing. If you are masking this object, please ensure the key fields are requested by the parent object.\",\n actualFragmentName\n );\n }\n }\n\n const diffOptions: Cache.DiffOptions<TData, TVars> = {\n ...otherOptions,\n returnPartialData: true,\n id,\n query,\n optimistic,\n };\n\n let latestDiff: DataProxy.DiffResult<TData> | undefined;\n\n return new Observable((observer) => {\n return this.watch<TData, TVars>({\n ...diffOptions,\n immediate: true,\n callback: (diff) => {\n const data =\n dataMasking ?\n maskFragment(diff.result, fragment, this, fragmentName)\n : diff.result;\n\n if (\n // Always ensure we deliver the first result\n latestDiff &&\n equalByQuery(query, { data: latestDiff?.result }, { data })\n ) {\n return;\n }\n\n const result = {\n data,\n complete: !!diff.complete,\n } as WatchFragmentResult<TData>;\n\n if (diff.missing) {\n result.missing = mergeDeepArray(\n diff.missing.map((error) => error.missing)\n );\n }\n\n latestDiff = { ...diff, result: data };\n observer.next(result);\n },\n });\n });\n }\n\n // Make sure we compute the same (===) fragment query document every\n // time we receive the same fragment in readFragment.\n private getFragmentDoc = wrap(getFragmentQueryDocument, {\n max:\n cacheSizes[\"cache.fragmentQueryDocuments\"] ||\n defaultCacheSizes[\"cache.fragmentQueryDocuments\"],\n cache: WeakCache,\n });\n\n public readFragment<FragmentType, TVariables = any>(\n options: Cache.ReadFragmentOptions<FragmentType, TVariables>,\n optimistic = !!options.optimistic\n ): Unmasked<FragmentType> | null {\n return this.read({\n ...options,\n query: this.getFragmentDoc(options.fragment, options.fragmentName),\n rootId: options.id,\n optimistic,\n });\n }\n\n public writeQuery<TData = any, TVariables = any>({\n id,\n data,\n ...options\n }: Cache.WriteQueryOptions<TData, TVariables>): Reference | undefined {\n return this.write(\n Object.assign(options, {\n dataId: id || \"ROOT_QUERY\",\n result: data,\n })\n );\n }\n\n public writeFragment<TData = any, TVariables = any>({\n id,\n data,\n fragment,\n fragmentName,\n ...options\n }: Cache.WriteFragmentOptions<TData, TVariables>): Reference | undefined {\n return this.write(\n Object.assign(options, {\n query: this.getFragmentDoc(fragment, fragmentName),\n dataId: id,\n result: data,\n })\n );\n }\n\n public updateQuery<TData = any, TVariables = any>(\n options: Cache.UpdateQueryOptions<TData, TVariables>,\n update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void\n ): Unmasked<TData> | null {\n return this.batch({\n update(cache) {\n const value = cache.readQuery<TData, TVariables>(options);\n const data = update(value);\n if (data === void 0 || data === null) return value;\n cache.writeQuery<TData, TVariables>({ ...options, data });\n return data;\n },\n });\n }\n\n public updateFragment<TData = any, TVariables = any>(\n options: Cache.UpdateFragmentOptions<TData, TVariables>,\n update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void\n ): Unmasked<TData> | null {\n return this.batch({\n update(cache) {\n const value = cache.readFragment<TData, TVariables>(options);\n const data = update(value);\n if (data === void 0 || data === null) return value;\n cache.writeFragment<TData, TVariables>({ ...options, data });\n return data;\n },\n });\n }\n\n /**\n * @experimental\n * @internal\n * This is not a stable API - it is used in development builds to expose\n * information to the DevTools.\n * Use at your own risk!\n */\n public getMemoryInternals?: typeof getApolloCacheMemoryInternals;\n}\n\nif (__DEV__) {\n ApolloCache.prototype.getMemoryInternals = getApolloCacheMemoryInternals;\n}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O,EAAE,CAAC;IACZ,WAAW,CAAC,SAAS,CAAC,kBAAkB,GAAG,6BAA6B,CAAC;AAC3E,CAAC","sourcesContent":["import type {\n DocumentNode,\n FragmentDefinitionNode,\n InlineFragmentNode,\n} from \"graphql\";\nimport { wrap } from \"optimism\";\n\nimport type {\n StoreObject,\n Reference,\n DeepPartial,\n NoInfer,\n} from \"../../utilities/index.js\";\nimport {\n Observable,\n cacheSizes,\n defaultCacheSizes,\n getFragmentDefinition,\n getFragmentQueryDocument,\n mergeDeepArray,\n} from \"../../utilities/index.js\";\nimport type { DataProxy } from \"./types/DataProxy.js\";\nimport type { Cache } from \"./types/Cache.js\";\nimport { WeakCache } from \"@wry/caches\";\nimport { getApolloCacheMemoryInternals } from \"../../utilities/caching/getMemoryInternals.js\";\nimport type {\n OperationVariables,\n TypedDocumentNode,\n} from \"../../core/types.js\";\nimport type { MissingTree } from \"./types/common.js\";\nimport { equalByQuery } from \"../../core/equalByQuery.js\";\nimport { invariant } from \"../../utilities/globals/index.js\";\nimport { maskFragment } from \"../../masking/index.js\";\nimport type {\n FragmentType,\n MaybeMasked,\n Unmasked,\n} from \"../../masking/index.js\";\n\nexport type Transaction<T> = (c: ApolloCache<T>) => void;\n\n/**\n * Watched fragment options.\n */\nexport interface WatchFragmentOptions<TData, TVars> {\n /**\n * A GraphQL fragment document parsed into an AST with the `gql`\n * template literal.\n *\n * @docGroup 1. Required options\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVars>;\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 * @docGroup 1. Required options\n */\n from: StoreObject | Reference | FragmentType<NoInfer<TData>> | string;\n /**\n * Any variables that the GraphQL fragment may depend on.\n *\n * @docGroup 2. Cache options\n */\n variables?: TVars;\n /**\n * The name of the fragment defined in the fragment document.\n *\n * Required if the fragment document includes more than one fragment,\n * optional otherwise.\n *\n * @docGroup 2. Cache options\n */\n fragmentName?: string;\n /**\n * If `true`, `watchFragment` returns optimistic results.\n *\n * The default value is `true`.\n *\n * @docGroup 2. Cache options\n */\n optimistic?: boolean;\n}\n\n/**\n * Watched fragment results.\n */\nexport type WatchFragmentResult<TData> =\n | {\n data: MaybeMasked<TData>;\n complete: true;\n missing?: never;\n }\n | {\n data: DeepPartial<MaybeMasked<TData>>;\n complete: false;\n missing: MissingTree;\n };\n\nexport abstract class ApolloCache<TSerialized> implements DataProxy {\n public readonly assumeImmutableResults: boolean = false;\n\n // required to implement\n // core API\n public abstract read<TData = any, TVariables = any>(\n query: Cache.ReadOptions<TVariables, TData>\n ): Unmasked<TData> | null;\n public abstract write<TData = any, TVariables = any>(\n write: Cache.WriteOptions<TData, TVariables>\n ): Reference | undefined;\n public abstract diff<T>(query: Cache.DiffOptions): Cache.DiffResult<T>;\n public abstract watch<TData = any, TVariables = any>(\n watch: Cache.WatchOptions<TData, TVariables>\n ): () => void;\n\n // Empty the cache and restart all current watches (unless\n // options.discardWatches is true).\n public abstract reset(options?: Cache.ResetOptions): Promise<void>;\n\n // Remove whole objects from the cache by passing just options.id, or\n // specific fields by passing options.field and/or options.args. If no\n // options.args are provided, all fields matching options.field (even\n // those with arguments) will be removed. Returns true iff any data was\n // removed from the cache.\n public abstract evict(options: Cache.EvictOptions): boolean;\n\n // initializer / offline / ssr API\n /**\n * Replaces existing state in the cache (if any) with the values expressed by\n * `serializedState`.\n *\n * Called when hydrating a cache (server side rendering, or offline storage),\n * and also (potentially) during hot reloads.\n */\n public abstract restore(\n serializedState: TSerialized\n ): ApolloCache<TSerialized>;\n\n /**\n * Exposes the cache's complete state, in a serializable format for later restoration.\n */\n public abstract extract(optimistic?: boolean): TSerialized;\n\n // Optimistic API\n\n public abstract removeOptimistic(id: string): void;\n\n // Data masking API\n\n // Used by data masking to determine if an inline fragment with a type\n // condition matches a given typename.\n //\n // If not implemented by a cache subclass, data masking will effectively be\n // disabled since we will not be able to accurately determine if a given type\n // condition for a union or interface matches a particular type.\n public fragmentMatches?(\n fragment: InlineFragmentNode,\n typename: string\n ): boolean;\n\n // Function used to lookup a fragment when a fragment definition is not part\n // of the GraphQL document. This is useful for caches, such as InMemoryCache,\n // that register fragments ahead of time so they can be referenced by name.\n public lookupFragment(fragmentName: string): FragmentDefinitionNode | null {\n return null;\n }\n\n // Transactional API\n\n // The batch method is intended to replace/subsume both performTransaction\n // and recordOptimisticTransaction, but performTransaction came first, so we\n // provide a default batch implementation that's just another way of calling\n // performTransaction. Subclasses of ApolloCache (such as InMemoryCache) can\n // override the batch method to do more interesting things with its options.\n public batch<U>(options: Cache.BatchOptions<this, U>): U {\n const optimisticId =\n typeof options.optimistic === \"string\" ? options.optimistic\n : options.optimistic === false ? null\n : void 0;\n let updateResult: U;\n this.performTransaction(\n () => (updateResult = options.update(this)),\n optimisticId\n );\n return updateResult!;\n }\n\n public abstract performTransaction(\n transaction: Transaction<TSerialized>,\n // Although subclasses may implement recordOptimisticTransaction\n // however they choose, the default implementation simply calls\n // performTransaction with a string as the second argument, allowing\n // performTransaction to handle both optimistic and non-optimistic\n // (broadcast-batching) transactions. Passing null for optimisticId is\n // also allowed, and indicates that performTransaction should apply\n // the transaction non-optimistically (ignoring optimistic data).\n optimisticId?: string | null\n ): void;\n\n public recordOptimisticTransaction(\n transaction: Transaction<TSerialized>,\n optimisticId: string\n ) {\n this.performTransaction(transaction, optimisticId);\n }\n\n // Optional API\n\n // Called once per input document, allowing the cache to make static changes\n // to the query, such as adding __typename fields.\n public transformDocument(document: DocumentNode): DocumentNode {\n return document;\n }\n\n // Called before each ApolloLink request, allowing the cache to make dynamic\n // changes to the query, such as filling in missing fragment definitions.\n public transformForLink(document: DocumentNode): DocumentNode {\n return document;\n }\n\n public identify(object: StoreObject | Reference): string | undefined {\n return;\n }\n\n public gc(): string[] {\n return [];\n }\n\n public modify<Entity extends Record<string, any> = Record<string, any>>(\n options: Cache.ModifyOptions<Entity>\n ): boolean {\n return false;\n }\n\n // DataProxy API\n public readQuery<QueryType, TVariables = any>(\n options: Cache.ReadQueryOptions<QueryType, TVariables>,\n optimistic = !!options.optimistic\n ): Unmasked<QueryType> | null {\n return this.read({\n ...options,\n rootId: options.id || \"ROOT_QUERY\",\n optimistic,\n });\n }\n\n /** {@inheritDoc @apollo/client!ApolloClient#watchFragment:member(1)} */\n public watchFragment<TData = any, TVars = OperationVariables>(\n options: WatchFragmentOptions<TData, TVars>\n ): Observable<WatchFragmentResult<TData>> {\n const {\n fragment,\n fragmentName,\n from,\n optimistic = true,\n ...otherOptions\n } = options;\n const query = this.getFragmentDoc(fragment, fragmentName);\n // While our TypeScript types do not allow for `undefined` as a valid\n // `from`, its possible `useFragment` gives us an `undefined` since it\n // calls` cache.identify` and provides that value to `from`. We are\n // adding this fix here however to ensure those using plain JavaScript\n // and using `cache.identify` themselves will avoid seeing the obscure\n // warning.\n const id =\n typeof from === \"undefined\" || typeof from === \"string\" ?\n from\n : this.identify(from);\n const dataMasking = !!(options as any)[Symbol.for(\"apollo.dataMasking\")];\n\n if (__DEV__) {\n const actualFragmentName =\n fragmentName || getFragmentDefinition(fragment).name.value;\n\n if (!id) {\n invariant.warn(\n \"Could not identify object passed to `from` for '%s' fragment, either because the object is non-normalized or the key fields are missing. If you are masking this object, please ensure the key fields are requested by the parent object.\",\n actualFragmentName\n );\n }\n }\n\n const diffOptions: Cache.DiffOptions<TData, TVars> = {\n ...otherOptions,\n returnPartialData: true,\n id,\n query,\n optimistic,\n };\n\n let latestDiff: DataProxy.DiffResult<TData> | undefined;\n\n return new Observable((observer) => {\n return this.watch<TData, TVars>({\n ...diffOptions,\n immediate: true,\n callback: (diff) => {\n const data =\n dataMasking ?\n maskFragment(diff.result, fragment, this, fragmentName)\n : diff.result;\n\n if (\n // Always ensure we deliver the first result\n latestDiff &&\n equalByQuery(\n query,\n { data: latestDiff.result },\n { data },\n // TODO: Fix the type on WatchFragmentOptions so that TVars\n // extends OperationVariables\n options.variables as OperationVariables\n )\n ) {\n return;\n }\n\n const result = {\n data,\n complete: !!diff.complete,\n } as WatchFragmentResult<TData>;\n\n if (diff.missing) {\n result.missing = mergeDeepArray(\n diff.missing.map((error) => error.missing)\n );\n }\n\n latestDiff = { ...diff, result: data };\n observer.next(result);\n },\n });\n });\n }\n\n // Make sure we compute the same (===) fragment query document every\n // time we receive the same fragment in readFragment.\n private getFragmentDoc = wrap(getFragmentQueryDocument, {\n max:\n cacheSizes[\"cache.fragmentQueryDocuments\"] ||\n defaultCacheSizes[\"cache.fragmentQueryDocuments\"],\n cache: WeakCache,\n });\n\n public readFragment<FragmentType, TVariables = any>(\n options: Cache.ReadFragmentOptions<FragmentType, TVariables>,\n optimistic = !!options.optimistic\n ): Unmasked<FragmentType> | null {\n return this.read({\n ...options,\n query: this.getFragmentDoc(options.fragment, options.fragmentName),\n rootId: options.id,\n optimistic,\n });\n }\n\n public writeQuery<TData = any, TVariables = any>({\n id,\n data,\n ...options\n }: Cache.WriteQueryOptions<TData, TVariables>): Reference | undefined {\n return this.write(\n Object.assign(options, {\n dataId: id || \"ROOT_QUERY\",\n result: data,\n })\n );\n }\n\n public writeFragment<TData = any, TVariables = any>({\n id,\n data,\n fragment,\n fragmentName,\n ...options\n }: Cache.WriteFragmentOptions<TData, TVariables>): Reference | undefined {\n return this.write(\n Object.assign(options, {\n query: this.getFragmentDoc(fragment, fragmentName),\n dataId: id,\n result: data,\n })\n );\n }\n\n public updateQuery<TData = any, TVariables = any>(\n options: Cache.UpdateQueryOptions<TData, TVariables>,\n update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void\n ): Unmasked<TData> | null {\n return this.batch({\n update(cache) {\n const value = cache.readQuery<TData, TVariables>(options);\n const data = update(value);\n if (data === void 0 || data === null) return value;\n cache.writeQuery<TData, TVariables>({ ...options, data });\n return data;\n },\n });\n }\n\n public updateFragment<TData = any, TVariables = any>(\n options: Cache.UpdateFragmentOptions<TData, TVariables>,\n update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void\n ): Unmasked<TData> | null {\n return this.batch({\n update(cache) {\n const value = cache.readFragment<TData, TVariables>(options);\n const data = update(value);\n if (data === void 0 || data === null) return value;\n cache.writeFragment<TData, TVariables>({ ...options, data });\n return data;\n },\n });\n }\n\n /**\n * @experimental\n * @internal\n * This is not a stable API - it is used in development builds to expose\n * information to the DevTools.\n * Use at your own risk!\n */\n public getMemoryInternals?: typeof getApolloCacheMemoryInternals;\n}\n\nif (__DEV__) {\n ApolloCache.prototype.getMemoryInternals = getApolloCacheMemoryInternals;\n}\n"]}
|
package/core/core.cjs
CHANGED
|
@@ -21,7 +21,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
21
21
|
|
|
22
22
|
var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
|
|
23
23
|
|
|
24
|
-
var version = "3.12.
|
|
24
|
+
var version = "3.12.9";
|
|
25
25
|
|
|
26
26
|
function isNonNullObject(obj) {
|
|
27
27
|
return obj !== null && typeof obj === "object";
|