Skip to content

Commit 4179446

Browse files
authored
enforce extends OperationVariables for TVariables generics (#12788)
1 parent 8ce31fa commit 4179446

29 files changed

+189
-66
lines changed

.api-reports/api-report-cache.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ export abstract class EntityStore implements NormalizedCache {
389389
}
390390

391391
// @public (undocumented)
392-
export interface FieldFunctionOptions<TArgs = Record<string, any>, TVariables = Record<string, any>> {
392+
export interface FieldFunctionOptions<TArgs = Record<string, any>, TVariables extends OperationVariables = Record<string, any>> {
393393
// (undocumented)
394394
args: TArgs | null;
395395
// (undocumented)
@@ -947,8 +947,8 @@ interface WriteContext extends ReadMergeModifyContext {
947947

948948
// Warnings were encountered during analysis:
949949
//
950-
// src/cache/inmemory/policies.ts:166:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts
951-
// src/cache/inmemory/policies.ts:166:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts
950+
// src/cache/inmemory/policies.ts:167:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts
951+
// src/cache/inmemory/policies.ts:167:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts
952952
// src/cache/inmemory/types.ts:134:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
953953

954954
// (No @packageDocumentation comment for this package)

.api-reports/api-report-core.api.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ interface MutationStoreValue {
615615
}
616616

617617
// @public (undocumented)
618-
export type MutationUpdaterFunction<TData, TVariables, TCache extends ApolloCache> = (cache: TCache, result: FormattedExecutionResult<Unmasked<TData>>, options: {
618+
export type MutationUpdaterFunction<TData, TVariables extends OperationVariables, TCache extends ApolloCache> = (cache: TCache, result: FormattedExecutionResult<Unmasked<TData>>, options: {
619619
context?: DefaultContext;
620620
variables?: TVariables;
621621
}) => void;
@@ -883,7 +883,7 @@ class QueryManager {
883883
// (undocumented)
884884
getObservableQueries(include?: InternalRefetchQueriesInclude): Set<ObservableQuery<any, OperationVariables>>;
885885
// (undocumented)
886-
getVariables<TVariables>(document: DocumentNode_2, variables?: TVariables): TVariables;
886+
getVariables<TVariables extends OperationVariables>(document: DocumentNode_2, variables?: TVariables): TVariables;
887887
// (undocumented)
888888
readonly incrementalHandler: Incremental.Handler;
889889
// (undocumented)
@@ -1116,14 +1116,14 @@ export { UnconventionalError }
11161116
export { Unmasked }
11171117

11181118
// @public (undocumented)
1119-
export interface UpdateQueryMapFn<TData = unknown, TVariables = OperationVariables> {
1119+
export interface UpdateQueryMapFn<TData = unknown, TVariables extends OperationVariables = OperationVariables> {
11201120
// (undocumented)
11211121
(
11221122
unsafePreviousData: DeepPartial<Unmasked<TData>>, options: UpdateQueryOptions<TData, TVariables>): Unmasked<TData> | void;
11231123
}
11241124

11251125
// @public (undocumented)
1126-
export type UpdateQueryOptions<TData, TVariables> = {
1126+
export type UpdateQueryOptions<TData, TVariables extends OperationVariables> = {
11271127
variables?: TVariables;
11281128
} & ({
11291129
complete: true;
@@ -1149,7 +1149,7 @@ export type WatchQueryOptions<TVariables extends OperationVariables = OperationV
11491149
// Warnings were encountered during analysis:
11501150
//
11511151
// src/core/ApolloClient.ts:357:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
1152-
// src/core/ObservableQuery.ts:359:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
1152+
// src/core/ObservableQuery.ts:360:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
11531153
// src/core/QueryManager.ts:175:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
11541154

11551155
// (No @packageDocumentation comment for this package)

.api-reports/api-report-link.api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { FormattedExecutionResult } from 'graphql';
1111
import type { GraphQLFormattedError } from 'graphql';
1212
import type { Observable } from 'rxjs';
1313
import type { OperationTypeNode } from 'graphql';
14+
import type { OperationVariables } from '@apollo/client';
1415

1516
// @public (undocumented)
1617
export interface AdditionalFetchResultTypes<TData = Record<string, any>, TExtensions = Record<string, any>> {
@@ -75,7 +76,7 @@ export type FetchResult<TData = Record<string, any>, TExtensions = Record<string
7576
export const from: typeof ApolloLink.from;
7677

7778
// @public (undocumented)
78-
export interface GraphQLRequest<TVariables = Record<string, any>> {
79+
export interface GraphQLRequest<TVariables extends OperationVariables = Record<string, any>> {
7980
// (undocumented)
8081
context?: DefaultContext;
8182
// (undocumented)

.api-reports/api-report-react.api.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ interface MutationStoreValue {
576576
export type MutationTuple<TData, TVariables extends OperationVariables, _TContext = DefaultContext_2, TCache extends ApolloCache_2 = ApolloCache_2> = useMutation.ResultTuple<TData, TVariables, TCache>;
577577

578578
// @public (undocumented)
579-
type MutationUpdaterFunction<TData, TVariables, TCache extends ApolloCache> = (cache: TCache, result: FormattedExecutionResult<Unmasked<TData>>, options: {
579+
type MutationUpdaterFunction<TData, TVariables extends OperationVariables_2, TCache extends ApolloCache> = (cache: TCache, result: FormattedExecutionResult<Unmasked<TData>>, options: {
580580
context?: DefaultContext;
581581
variables?: TVariables;
582582
}) => void;
@@ -873,7 +873,7 @@ class QueryManager {
873873
// (undocumented)
874874
getObservableQueries(include?: InternalRefetchQueriesInclude): Set<ObservableQuery<any, OperationVariables_2>>;
875875
// (undocumented)
876-
getVariables<TVariables>(document: DocumentNode, variables?: TVariables): TVariables;
876+
getVariables<TVariables extends OperationVariables_2>(document: DocumentNode, variables?: TVariables): TVariables;
877877
// (undocumented)
878878
readonly incrementalHandler: Incremental.Handler;
879879
// (undocumented)
@@ -1067,14 +1067,14 @@ interface TransformCacheEntry {
10671067
}
10681068

10691069
// @public (undocumented)
1070-
interface UpdateQueryMapFn<TData = unknown, TVariables = OperationVariables_2> {
1070+
interface UpdateQueryMapFn<TData = unknown, TVariables extends OperationVariables_2 = OperationVariables_2> {
10711071
// (undocumented)
10721072
(
10731073
unsafePreviousData: DeepPartial<Unmasked<TData>>, options: UpdateQueryOptions<TData, TVariables>): Unmasked<TData> | void;
10741074
}
10751075

10761076
// @public (undocumented)
1077-
type UpdateQueryOptions<TData, TVariables> = {
1077+
type UpdateQueryOptions<TData, TVariables extends OperationVariables_2> = {
10781078
variables?: TVariables;
10791079
} & ({
10801080
complete: true;
@@ -1297,7 +1297,7 @@ export namespace useFragment {
12971297
export function useFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>({ fragment, from, fragmentName, variables, optimistic, client, }: useFragment.Options<TData, TVariables>): useFragment.Result<TData>;
12981298
}
12991299
// (undocumented)
1300-
export interface Options<TData, TVariables> {
1300+
export interface Options<TData, TVariables extends OperationVariables> {
13011301
client?: ApolloClient;
13021302
fragment: DocumentNode_2 | TypedDocumentNode_2<TData, TVariables>;
13031303
fragmentName?: string;
@@ -1316,7 +1316,7 @@ export namespace useFragment {
13161316
}
13171317

13181318
// @public @deprecated (undocumented)
1319-
export type UseFragmentOptions<TData, TVariables> = useFragment.Options<TData, TVariables>;
1319+
export type UseFragmentOptions<TData, TVariables extends OperationVariables> = useFragment.Options<TData, TVariables>;
13201320

13211321
// @public @deprecated (undocumented)
13221322
export type UseFragmentResult<TData> = useFragment.Result<TData>;
@@ -1962,8 +1962,8 @@ type WatchQueryFetchPolicy_2 = FetchPolicy | "cache-and-network" | "standby";
19621962
// src/core/ApolloClient.ts:354:5 - (ae-forgotten-export) The symbol "WatchQueryFetchPolicy_2" needs to be exported by the entry point index.d.ts
19631963
// src/core/ApolloClient.ts:357:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
19641964
// src/core/ApolloClient.ts:369:5 - (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts
1965-
// src/core/ObservableQuery.ts:236:5 - (ae-forgotten-export) The symbol "NetworkStatus" needs to be exported by the entry point index.d.ts
1966-
// src/core/ObservableQuery.ts:359:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
1965+
// src/core/ObservableQuery.ts:237:5 - (ae-forgotten-export) The symbol "NetworkStatus" needs to be exported by the entry point index.d.ts
1966+
// src/core/ObservableQuery.ts:360:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
19671967
// src/core/QueryManager.ts:175:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
19681968
// src/core/types.ts:270:7 - (ae-forgotten-export) The symbol "DataValue" needs to be exported by the entry point index.d.ts
19691969
// src/core/types.ts:320:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts

.api-reports/api-report-react_internal.api.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import type { useSuspenseQuery } from '@apollo/client/react';
2525
// Warning: (ae-forgotten-export) The symbol "WrappedQueryRef" needs to be exported by the entry point index.d.ts
2626
//
2727
// @public (undocumented)
28-
export function assertWrappedQueryRef<TData, TVariables, TStates extends DataState<TData>["dataState"]>(queryRef: QueryRef<TData, TVariables, TStates>): asserts queryRef is WrappedQueryRef<TData, TVariables, TStates>;
28+
export function assertWrappedQueryRef<TData, TVariables extends OperationVariables, TStates extends DataState<TData>["dataState"]>(queryRef: QueryRef<TData, TVariables, TStates>): asserts queryRef is WrappedQueryRef<TData, TVariables, TStates>;
2929

3030
// @public (undocumented)
31-
export function assertWrappedQueryRef<TData, TVariables, TStates extends DataState<TData>["dataState"]>(queryRef: QueryRef<TData, TVariables, TStates> | undefined | null): asserts queryRef is WrappedQueryRef<TData, TVariables, TStates> | undefined | null;
31+
export function assertWrappedQueryRef<TData, TVariables extends OperationVariables, TStates extends DataState<TData>["dataState"]>(queryRef: QueryRef<TData, TVariables, TStates> | undefined | null): asserts queryRef is WrappedQueryRef<TData, TVariables, TStates> | undefined | null;
3232

3333
// @public (undocumented)
3434
export type CacheKey = [
@@ -174,7 +174,7 @@ type ObservedOptions = Pick<ApolloClient.WatchQueryOptions, (typeof OBSERVED_CHA
174174
const PRELOADED_QUERY_REF_BRAND: unique symbol;
175175

176176
// @public
177-
export interface PreloadedQueryRef<TData = unknown, TVariables = unknown, TStates extends DataState<TData>["dataState"] = "complete" | "streaming"> extends QueryRef<TData, TVariables, TStates> {
177+
export interface PreloadedQueryRef<TData = unknown, TVariables extends OperationVariables = OperationVariables, TStates extends DataState<TData>["dataState"] = "complete" | "streaming"> extends QueryRef<TData, TVariables, TStates> {
178178
// @internal @deprecated (undocumented)
179179
[PRELOADED_QUERY_REF_BRAND]: typeof PRELOADED_QUERY_REF_BRAND;
180180
}
@@ -195,7 +195,7 @@ export interface QueryKey {
195195
}
196196

197197
// @public
198-
export interface QueryRef<TData = unknown, TVariables = unknown, TStates extends DataState<TData>["dataState"] = "complete" | "streaming"> {
198+
export interface QueryRef<TData = unknown, TVariables extends OperationVariables = OperationVariables, TStates extends DataState<TData>["dataState"] = "complete" | "streaming"> {
199199
// @internal @deprecated (undocumented)
200200
[QUERY_REF_BRAND]?(variables: TVariables): {
201201
data: TData;
@@ -265,7 +265,7 @@ interface WrappableHooks {
265265
}
266266

267267
// @internal @deprecated
268-
interface WrappedQueryRef<TData = unknown, TVariables = unknown, TStates extends DataState<TData>["dataState"] = "complete" | "streaming"> extends QueryRef<TData, TVariables, TStates> {
268+
interface WrappedQueryRef<TData = unknown, TVariables extends OperationVariables = OperationVariables, TStates extends DataState<TData>["dataState"] = "complete" | "streaming"> extends QueryRef<TData, TVariables, TStates> {
269269
// @deprecated (undocumented)
270270
[PROMISE_SYMBOL]: QueryRefPromise<TData, TStates>;
271271
// @deprecated (undocumented)

.api-reports/api-report-testing.api.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { DocumentNode } from 'graphql';
99
import type { FetchResult } from '@apollo/client/link';
1010
import { Observable } from 'rxjs';
1111
import type { Operation } from '@apollo/client/link';
12+
import type { OperationVariables } from '@apollo/client';
1213
import type { Unmasked } from '@apollo/client/masking';
1314

1415
// @internal @deprecated (undocumented)
@@ -17,10 +18,10 @@ type CovariantUnaryFunction<out Arg, out Ret> = {
1718
}["fn"];
1819

1920
// @public @deprecated (undocumented)
20-
export type MockedRequest<TVariables = Record<string, any>> = MockLink.MockedRequest<TVariables>;
21+
export type MockedRequest<TVariables extends OperationVariables = Record<string, any>> = MockLink.MockedRequest<TVariables>;
2122

2223
// @public @deprecated (undocumented)
23-
export type MockedResponse<TData = Record<string, any>, TVariables = Record<string, any>> = MockLink.MockedResponse<TData, TVariables>;
24+
export type MockedResponse<TData = Record<string, any>, TVariables extends OperationVariables = Record<string, any>> = MockLink.MockedResponse<TData, TVariables>;
2425

2526
// @public (undocumented)
2627
export namespace MockLink {
@@ -34,7 +35,7 @@ export namespace MockLink {
3435
// (undocumented)
3536
export type DelayFunction = (operation: Operation) => number;
3637
// (undocumented)
37-
export interface MockedRequest<TVariables = Record<string, any>> {
38+
export interface MockedRequest<TVariables extends OperationVariables = OperationVariables> {
3839
// (undocumented)
3940
query: DocumentNode;
4041
// Warning: (ae-forgotten-export) The symbol "VariableMatcher" needs to be exported by the entry point index.d.ts
@@ -43,7 +44,7 @@ export namespace MockLink {
4344
variables?: TVariables | VariableMatcher<TVariables>;
4445
}
4546
// (undocumented)
46-
export interface MockedResponse<out TData = Record<string, any>, out TVariables = Record<string, any>> {
47+
export interface MockedResponse<out TData = Record<string, any>, out TVariables extends OperationVariables = Record<string, any>> {
4748
// (undocumented)
4849
delay?: number | MockLink.DelayFunction;
4950
// (undocumented)

.api-reports/api-report.api.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ export type FetchPolicy = "cache-first" | "network-only" | "cache-only" | "no-ca
10181018
export type FetchResult<TData = Record<string, any>, TExtensions = Record<string, any>> = FormattedExecutionResult<TData, TExtensions> | AdditionalFetchResultTypes<TData, TExtensions>[keyof AdditionalFetchResultTypes<TData, TExtensions>];
10191019

10201020
// @public (undocumented)
1021-
export interface FieldFunctionOptions<TArgs = Record<string, any>, TVariables = Record<string, any>> {
1021+
export interface FieldFunctionOptions<TArgs = Record<string, any>, TVariables extends OperationVariables = Record<string, any>> {
10221022
// (undocumented)
10231023
args: TArgs | null;
10241024
// (undocumented)
@@ -1275,7 +1275,7 @@ namespace GraphQLCodegenDataMasking {
12751275
}
12761276

12771277
// @public (undocumented)
1278-
export interface GraphQLRequest<TVariables = Record<string, any>> {
1278+
export interface GraphQLRequest<TVariables extends OperationVariables = Record<string, any>> {
12791279
// (undocumented)
12801280
context?: DefaultContext;
12811281
// (undocumented)
@@ -1888,7 +1888,7 @@ interface MutationStoreValue {
18881888
}
18891889

18901890
// @public (undocumented)
1891-
export type MutationUpdaterFunction<TData, TVariables, TCache extends ApolloCache> = (cache: TCache, result: FormattedExecutionResult<Unmasked<TData>>, options: {
1891+
export type MutationUpdaterFunction<TData, TVariables extends OperationVariables, TCache extends ApolloCache> = (cache: TCache, result: FormattedExecutionResult<Unmasked<TData>>, options: {
18921892
context?: DefaultContext;
18931893
variables?: TVariables;
18941894
}) => void;
@@ -2286,7 +2286,7 @@ class QueryManager {
22862286
// (undocumented)
22872287
getObservableQueries(include?: InternalRefetchQueriesInclude): Set<ObservableQuery<any, OperationVariables>>;
22882288
// (undocumented)
2289-
getVariables<TVariables>(document: DocumentNode, variables?: TVariables): TVariables;
2289+
getVariables<TVariables extends OperationVariables>(document: DocumentNode, variables?: TVariables): TVariables;
22902290
// (undocumented)
22912291
readonly incrementalHandler: Incremental.Handler;
22922292
// (undocumented)
@@ -2727,14 +2727,14 @@ type UnwrapFragmentRefs<TData> = true extends IsAny<TData> ? TData : TData exten
27272727
} : TData : never;
27282728

27292729
// @public (undocumented)
2730-
export interface UpdateQueryMapFn<TData = unknown, TVariables = OperationVariables> {
2730+
export interface UpdateQueryMapFn<TData = unknown, TVariables extends OperationVariables = OperationVariables> {
27312731
// (undocumented)
27322732
(
27332733
unsafePreviousData: DeepPartial<Unmasked<TData>>, options: UpdateQueryOptions<TData, TVariables>): Unmasked<TData> | void;
27342734
}
27352735

27362736
// @public (undocumented)
2737-
export type UpdateQueryOptions<TData, TVariables> = {
2737+
export type UpdateQueryOptions<TData, TVariables extends OperationVariables> = {
27382738
variables?: TVariables;
27392739
} & ({
27402740
complete: true;
@@ -2809,13 +2809,13 @@ interface WriteContext extends ReadMergeModifyContext {
28092809
// Warnings were encountered during analysis:
28102810
//
28112811
// src/cache/core/cache.ts:94:9 - (ae-forgotten-export) The symbol "MissingTree" needs to be exported by the entry point index.d.ts
2812-
// src/cache/inmemory/policies.ts:97:3 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
2813-
// src/cache/inmemory/policies.ts:166:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts
2814-
// src/cache/inmemory/policies.ts:166:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts
2812+
// src/cache/inmemory/policies.ts:98:3 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
2813+
// src/cache/inmemory/policies.ts:167:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts
2814+
// src/cache/inmemory/policies.ts:167:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts
28152815
// src/cache/inmemory/types.ts:134:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
28162816
// src/core/ApolloClient.ts:163:5 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
28172817
// src/core/ApolloClient.ts:357:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
2818-
// src/core/ObservableQuery.ts:359:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
2818+
// src/core/ObservableQuery.ts:360:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
28192819
// src/core/QueryManager.ts:175:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
28202820
// src/local-state/LocalState.ts:140:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts
28212821
// src/local-state/LocalState.ts:174:7 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts

.changeset/five-crabs-remember.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": major
3+
---
4+
5+
`TVariables` now always `extends OperationVariables` in all interfaces.

0 commit comments

Comments
 (0)