Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cb33a4d
Add a Cache.Implementation type that checks TypeOverrides for used cache
jerelmiller Jun 2, 2026
5c8bc63
Set client.cache type to Cache.Implementation
jerelmiller Jun 2, 2026
8c891a5
Add type tests for defaults for cache override
jerelmiller Jun 2, 2026
57e0795
Add type tests for classic signature with cache override
jerelmiller Jun 2, 2026
6407b94
Add type tests for modern signature
jerelmiller Jun 2, 2026
11ca38d
Update useMutation to use Cache.Implementation where possible
jerelmiller Jun 2, 2026
4d0929f
Update client.mutate and client.refetchQueries to use Cache.Implement…
jerelmiller Jun 2, 2026
8345684
Add check on client.cache returned from useMutation
jerelmiller Jun 2, 2026
ed0ef9d
Handle an invalid cache override type
jerelmiller Jun 2, 2026
7831b88
Add checks on client.cache returned from hooks
jerelmiller Jun 2, 2026
f94e229
Add more checks to defaults
jerelmiller Jun 2, 2026
35cf6c5
Add more checks to invalid
jerelmiller Jun 2, 2026
1b619e8
Validate TCache in client.mutate matches subtype of Client.Implementa…
jerelmiller Jun 2, 2026
e0ac183
Validate TCache in client.refetchQueries matches subtype
jerelmiller Jun 2, 2026
dab8b45
Validate TCache in useMutation matches subtype
jerelmiller Jun 2, 2026
153f393
Add changeset
jerelmiller Jun 2, 2026
e6bacd4
Rerun api report
jerelmiller Jun 2, 2026
72fea26
Use Cache.Implementation as type constraint
jerelmiller Jun 2, 2026
1f3bace
Tweak changeset
jerelmiller Jun 2, 2026
02fe0f1
Fix missing import in tests
jerelmiller Jun 2, 2026
56d3511
Update deprecated types to add Cache.Implementation constraint
jerelmiller Jun 2, 2026
d0f1e51
Add check for invalid cache value with invalid type override
jerelmiller Jun 2, 2026
27e48cc
Fix type error in modernSignature tests
jerelmiller Jun 2, 2026
b10c4b1
BatchOptions TCache extends Cache.Implementation
jerelmiller Jun 2, 2026
6a00cfe
Add type tests for client.cache.batch
jerelmiller Jun 2, 2026
c0492f9
Update api report
jerelmiller Jun 2, 2026
fcaba7b
Make InMemoryCache the default when no cache is declared
jerelmiller Jun 8, 2026
88b7c7b
Use error message when cache type is invalid.
jerelmiller Jun 8, 2026
deadac7
Ensure MutationUpdaterFn extends Cache.Implementation
jerelmiller Jun 8, 2026
e8ac067
Set codebase cache to ApolloCache
jerelmiller Jun 8, 2026
ad5c887
Catch some more references to extends ApolloCache
jerelmiller Jun 8, 2026
fdbe3db
Rerun api report
jerelmiller Jun 8, 2026
6840733
Revert "Make InMemoryCache the default when no cache is declared"
jerelmiller Jun 9, 2026
8df9c40
Rerun api report
jerelmiller Jun 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .api-reports/api-report-cache.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type { StoreObject } from '@apollo/client/utilities';
import type { StoreValue } from '@apollo/client/utilities';
import { Trie } from '@wry/trie';
import type { TypedDocumentNode } from '@apollo/client';
import type { TypeOverrides } from '@apollo/client';
import type { Unmasked } from '@apollo/client/masking';

// Warning: (ae-forgotten-export) The symbol "StoreObjectValueMaybeReference" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -165,7 +166,7 @@ type BroadcastOptions = Pick<Cache_2.BatchOptions<InMemoryCache>, "optimistic" |
// @public (undocumented)
namespace Cache_2 {
// (undocumented)
interface BatchOptions<TCache extends ApolloCache, TUpdateResult = void> {
interface BatchOptions<TCache extends Cache_2.Implementation, TUpdateResult = void> {
onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult<any>, lastDiff?: Cache_2.DiffResult<any> | undefined) => any;
optimistic?: string | boolean;
removeOptimistic?: string;
Expand Down Expand Up @@ -206,6 +207,10 @@ namespace Cache_2 {
id?: string;
}
// (undocumented)
type Implementation = TypeOverrides extends {
cache: infer TCache;
} ? TCache extends ApolloCache ? TCache : "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." : ApolloCache;
// (undocumented)
interface ModifyOptions<Entity extends Record<string, any> = Record<string, any>> {
// (undocumented)
broadcast?: boolean;
Expand Down
34 changes: 17 additions & 17 deletions .api-reports/api-report-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export namespace ApolloClient {
}
// (undocumented)
export namespace DocumentationTypes {
export function mutate<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache>(options: ApolloClient.MutateOptions<TData, TVariables, TCache>): Promise<ApolloClient.MutateResult<MaybeMasked<TData>>>;
export function mutate<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends Cache_2.Implementation = Cache_2.Implementation>(options: ApolloClient.MutateOptions<TData, TVariables, TCache>): Promise<ApolloClient.MutateResult<MaybeMasked<TData>>>;
export function query<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.QueryOptions<TData, TVariables>): Promise<ApolloClient.QueryResult<MaybeMasked<TData>>>;
}
// (undocumented)
Expand All @@ -232,35 +232,35 @@ export namespace ApolloClient {
export interface DefaultOptions extends ApolloClient.DefaultOptions.Mutate.Calculated {
}
// (undocumented)
export type ResultForOptions<TData, TVariables extends OperationVariables, TCache extends ApolloCache, TOptions extends Record<string, unknown> | MutateOptions<any, TVariables, TCache>> = LazyType<MutateResult<MaybeMasked<TData>, OptionWithFallback<TOptions, DefaultOptions, "errorPolicy"> & ErrorPolicy>>;
export type ResultForOptions<TData, TVariables extends OperationVariables, TCache extends Cache_2.Implementation, TOptions extends Record<string, unknown> | MutateOptions<any, TVariables, TCache>> = LazyType<MutateResult<MaybeMasked<TData>, OptionWithFallback<TOptions, DefaultOptions, "errorPolicy"> & ErrorPolicy>>;
export interface Signature extends Signatures.Evaluated {
}
// (undocumented)
export namespace Signatures {
// (undocumented)
export interface Classic {
<TData, TVariables extends OperationVariables, _INFERENCE_ONLY_DO_NOT_SPECIFY extends "inferred", TErrorPolicy extends ErrorPolicy | undefined = undefined>(options: ApolloClient.MutateOptions<TData, TVariables, ApolloCache> & {
<TData, TVariables extends OperationVariables, _INFERENCE_ONLY_DO_NOT_SPECIFY extends "inferred", TErrorPolicy extends ErrorPolicy | undefined = undefined>(options: ApolloClient.MutateOptions<TData, TVariables, Cache_2.Implementation> & {
errorPolicy?: TErrorPolicy;
}): Promise<ApolloClient.MutateResult<MaybeMasked<TData>, TErrorPolicy>>;
// @deprecated (undocumented)
<TData, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache, TErrorPolicy extends ErrorPolicy | undefined = undefined>(options: ApolloClient.MutateOptions<TData, TVariables, TCache> & (TErrorPolicy extends undefined ? {} : {
<TData, TVariables extends OperationVariables = OperationVariables, TCache extends Cache_2.Implementation = Cache_2.Implementation, TErrorPolicy extends ErrorPolicy | undefined = undefined>(options: ApolloClient.MutateOptions<TData, TVariables, TCache> & (TErrorPolicy extends undefined ? {} : {
errorPolicy: TErrorPolicy;
})): Promise<ApolloClient.MutateResult<MaybeMasked<TData>, TErrorPolicy>>;
}
// (undocumented)
export type Evaluated = SignatureStyle extends "classic" ? Classic : Modern;
// (undocumented)
export interface Modern {
<TData, TVariables extends OperationVariables, TCache extends ApolloCache, TOptions extends ApolloClient.MutateOptions<NoInfer<TData>, NoInfer<TVariables>, TCache> & VariablesOption<TVariables & {
<TData, TVariables extends OperationVariables, TOptions extends ApolloClient.MutateOptions<NoInfer<TData>, NoInfer<TVariables>, Cache_2.Implementation> & VariablesOption<TVariables & {
[K in Exclude<keyof TOptions["variables"], keyof TVariables>]?: never;
}>>(options: TOptions & {
mutation: TypedDocumentNode<TData, TVariables>;
}): Promise<ApolloClient.mutate.ResultForOptions<TData, TVariables, TCache, TOptions>>;
}): Promise<ApolloClient.mutate.ResultForOptions<TData, TVariables, Cache_2.Implementation, TOptions>>;
}
}
}
// (undocumented)
export type MutateOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache> = {
export type MutateOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends Cache_2.Implementation = Cache_2.Implementation> = {
optimisticResponse?: Unmasked<NoInfer<TData>> | ((vars: TVariables, { IGNORE }: {
IGNORE: IgnoreModifier;
}) => Unmasked<NoInfer<TData>> | IgnoreModifier);
Expand Down Expand Up @@ -305,7 +305,7 @@ export namespace ApolloClient {
// (undocumented)
export interface Options extends InternalTypes_2.DefaultOptionsParentObject {
assumeImmutableResults?: boolean;
cache: ApolloCache;
cache: Cache_2.Implementation;
// (undocumented)
clientAwareness?: ClientAwarenessLink.ClientAwarenessOptions;
dataMasking?: boolean;
Expand Down Expand Up @@ -390,7 +390,7 @@ export namespace ApolloClient {
export type ReadFragmentOptions<TData, TVariables extends OperationVariables> = Base.ReadFragmentOptions<TData, TVariables> & VariablesOption<TVariables> & Cache_2.CacheIdentifierOption<TData>;
// (undocumented)
export type ReadQueryOptions<TData, TVariables extends OperationVariables> = Base.ReadQueryOptions<TData, TVariables> & VariablesOption<TVariables>;
export interface RefetchQueriesOptions<TCache extends ApolloCache, TResult> {
export interface RefetchQueriesOptions<TCache extends Cache_2.Implementation, TResult> {
include?: RefetchQueriesInclude;
onQueryUpdated?: OnQueryUpdated<TResult> | null;
optimistic?: boolean;
Expand Down Expand Up @@ -453,7 +453,7 @@ export class ApolloClient {
// (undocumented)
__requestRaw(request: ApolloLink.Request): Observable_2<ApolloLink.Result<unknown>>;
// (undocumented)
cache: ApolloCache;
cache: Cache_2.Implementation;
clearStore(): Promise<any[]>;
// (undocumented)
get defaultContext(): Partial<DefaultContext>;
Expand Down Expand Up @@ -491,7 +491,7 @@ export class ApolloClient {
// @deprecated
reFetchObservableQueries: (includeStandby?: boolean) => Promise<ApolloClient.QueryResult<any>[]>;
refetchObservableQueries(includeStandby?: boolean): Promise<ApolloClient.QueryResult<any>[]>;
refetchQueries<TCache extends ApolloCache = ApolloCache, TResult = Promise<ApolloClient.QueryResult<any>>>(options: ApolloClient.RefetchQueriesOptions<TCache, TResult>): ApolloClient.RefetchQueriesResult<TResult>;
refetchQueries<TCache extends Cache_2.Implementation = Cache_2.Implementation, TResult = Promise<ApolloClient.QueryResult<any>>>(options: ApolloClient.RefetchQueriesOptions<TCache, TResult>): ApolloClient.RefetchQueriesResult<TResult>;
resetStore(): Promise<ApolloClient.QueryResult<any>[] | null>;
restore(serializedState: unknown): ApolloCache;
setLink(newLink: ApolloLink): void;
Expand Down Expand Up @@ -732,7 +732,7 @@ export type MutateResult<TData = unknown> = ApolloClient.MutateResult<TData>;
export type MutationFetchPolicy = Extract<FetchPolicy, "network-only" | "no-cache">;

// @public @deprecated (undocumented)
export type MutationOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache> = ApolloClient.MutateOptions<TData, TVariables, TCache>;
export type MutationOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends Cache_2.Implementation = Cache_2.Implementation> = ApolloClient.MutateOptions<TData, TVariables, TCache>;

// @public (undocumented)
export type MutationQueryReducer<T> = (previousResult: Record<string, any>, options: {
Expand Down Expand Up @@ -761,7 +761,7 @@ interface MutationStoreValue {
}

// @public (undocumented)
export type MutationUpdaterFunction<TData, TVariables extends OperationVariables, TCache extends ApolloCache> = (cache: TCache, result: FormattedExecutionResult<Unmasked<TData>>, options: {
export type MutationUpdaterFunction<TData, TVariables extends OperationVariables, TCache extends Cache_2.Implementation> = (cache: TCache, result: FormattedExecutionResult<Unmasked<TData>>, options: {
context?: DefaultContext;
variables?: TVariables;
}) => void;
Expand Down Expand Up @@ -1059,7 +1059,7 @@ class QueryManager {
// (undocumented)
maskOperation<TData = unknown>(options: MaskOperationOptions<TData>): MaybeMasked<TData>;
// (undocumented)
mutate<TData, TVariables extends OperationVariables, TCache extends ApolloCache>({ mutation, variables, optimisticResponse, updateQueries, refetchQueries, awaitRefetchQueries, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }: ApolloClient.MutateOptions<TData, TVariables, TCache> & {
mutate<TData, TVariables extends OperationVariables, TCache extends Cache_2.Implementation>({ mutation, variables, optimisticResponse, updateQueries, refetchQueries, awaitRefetchQueries, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }: ApolloClient.MutateOptions<TData, TVariables, TCache> & {
errorPolicy: ErrorPolicy;
fetchPolicy: MutationFetchPolicy;
}): Promise<ApolloClient.MutateResult<MaybeMasked<TData>>>;
Expand All @@ -1074,7 +1074,7 @@ class QueryManager {
// (undocumented)
refetchObservableQueries(includeStandby?: boolean): Promise<ApolloClient.QueryResult<any>[]>;
// (undocumented)
refetchQueries<TResult>({ updateCache, include, optimistic, removeOptimistic, onQueryUpdated, }: InternalRefetchQueriesOptions<ApolloCache, TResult>): InternalRefetchQueriesMap<TResult>;
refetchQueries<TResult>({ updateCache, include, optimistic, removeOptimistic, onQueryUpdated, }: InternalRefetchQueriesOptions<Cache_2.Implementation, TResult>): InternalRefetchQueriesMap<TResult>;
// (undocumented)
readonly ssrMode: boolean;
// (undocumented)
Expand Down Expand Up @@ -1224,7 +1224,7 @@ export type RefetchQueriesInclude = RefetchQueryDescriptor[] | RefetchQueriesInc
type RefetchQueriesIncludeShorthand = "all" | "active";

// @public @deprecated (undocumented)
export type RefetchQueriesOptions<TCache extends ApolloCache, TResult> = ApolloClient.RefetchQueriesOptions<TCache, TResult>;
export type RefetchQueriesOptions<TCache extends Cache_2.Implementation, TResult> = ApolloClient.RefetchQueriesOptions<TCache, TResult>;

// @public (undocumented)
export type RefetchQueriesPromiseResults<TResult> = IsAny<TResult> extends true ? any[] : TResult extends boolean ? ApolloClient.QueryResult<any>[] : TResult extends PromiseLike<infer U> ? U[] : TResult[];
Expand Down Expand Up @@ -1367,7 +1367,7 @@ export const windowFocusSource: RefetchEventManager.EventSource<Event>;

// Warnings were encountered during analysis:
//
// src/core/ApolloClient.ts:633:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
// src/core/ApolloClient.ts:635:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:375:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:195:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts

Expand Down
Loading
Loading