Skip to content

Commit f395ea6

Browse files
committed
enforce extends OperationVariables for TVariables generics
1 parent 2f1dacf commit f395ea6

27 files changed

+180
-59
lines changed

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

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

394394
// @public (undocumented)
395-
export interface FieldFunctionOptions<TArgs = Record<string, any>, TVariables = Record<string, any>> {
395+
export interface FieldFunctionOptions<TArgs = Record<string, any>, TVariables extends OperationVariables = Record<string, any>> {
396396
// (undocumented)
397397
args: TArgs | null;
398398
// (undocumented)
@@ -950,8 +950,8 @@ interface WriteContext extends ReadMergeModifyContext {
950950

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

957957
// (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
@@ -617,7 +617,7 @@ interface MutationStoreValue {
617617
}
618618

619619
// @public (undocumented)
620-
export type MutationUpdaterFunction<TData, TVariables, TCache extends ApolloCache> = (cache: TCache, result: FormattedExecutionResult<Unmasked<TData>>, options: {
620+
export type MutationUpdaterFunction<TData, TVariables extends OperationVariables, TCache extends ApolloCache> = (cache: TCache, result: FormattedExecutionResult<Unmasked<TData>>, options: {
621621
context?: DefaultContext;
622622
variables?: TVariables;
623623
}) => void;
@@ -885,7 +885,7 @@ class QueryManager {
885885
// (undocumented)
886886
getObservableQueries(include?: InternalRefetchQueriesInclude): Set<ObservableQuery<any, OperationVariables>>;
887887
// (undocumented)
888-
getVariables<TVariables>(document: DocumentNode_2, variables?: TVariables): TVariables;
888+
getVariables<TVariables extends OperationVariables>(document: DocumentNode_2, variables?: TVariables): TVariables;
889889
// (undocumented)
890890
readonly incrementalHandler: Incremental.Handler;
891891
// (undocumented)
@@ -1118,14 +1118,14 @@ export { UnconventionalError }
11181118
export { Unmasked }
11191119

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

11271127
// @public (undocumented)
1128-
export type UpdateQueryOptions<TData, TVariables> = {
1128+
export type UpdateQueryOptions<TData, TVariables extends OperationVariables> = {
11291129
variables?: TVariables;
11301130
} & ({
11311131
complete: true;
@@ -1151,7 +1151,7 @@ export type WatchQueryOptions<TVariables extends OperationVariables = OperationV
11511151
// Warnings were encountered during analysis:
11521152
//
11531153
// src/core/ApolloClient.ts:326:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
1154-
// src/core/ObservableQuery.ts:359:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
1154+
// src/core/ObservableQuery.ts:360:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
11551155
// src/core/QueryManager.ts:175:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
11561156

11571157
// (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
@@ -582,7 +582,7 @@ interface MutationStoreValue {
582582
export type MutationTuple<TData, TVariables extends OperationVariables, _TContext = DefaultContext_2, TCache extends ApolloCache_2 = ApolloCache_2> = useMutation.ResultTuple<TData, TVariables, TCache>;
583583

584584
// @public (undocumented)
585-
type MutationUpdaterFunction<TData, TVariables, TCache extends ApolloCache> = (cache: TCache, result: FormattedExecutionResult<Unmasked<TData>>, options: {
585+
type MutationUpdaterFunction<TData, TVariables extends OperationVariables_2, TCache extends ApolloCache> = (cache: TCache, result: FormattedExecutionResult<Unmasked<TData>>, options: {
586586
context?: DefaultContext;
587587
variables?: TVariables;
588588
}) => void;
@@ -879,7 +879,7 @@ class QueryManager {
879879
// (undocumented)
880880
getObservableQueries(include?: InternalRefetchQueriesInclude): Set<ObservableQuery<any, OperationVariables_2>>;
881881
// (undocumented)
882-
getVariables<TVariables>(document: DocumentNode, variables?: TVariables): TVariables;
882+
getVariables<TVariables extends OperationVariables_2>(document: DocumentNode, variables?: TVariables): TVariables;
883883
// (undocumented)
884884
readonly incrementalHandler: Incremental.Handler;
885885
// (undocumented)
@@ -1073,14 +1073,14 @@ interface TransformCacheEntry {
10731073
}
10741074

10751075
// @public (undocumented)
1076-
interface UpdateQueryMapFn<TData = unknown, TVariables = OperationVariables_2> {
1076+
interface UpdateQueryMapFn<TData = unknown, TVariables extends OperationVariables_2 = OperationVariables_2> {
10771077
// (undocumented)
10781078
(
10791079
unsafePreviousData: DeepPartial<Unmasked<TData>>, options: UpdateQueryOptions<TData, TVariables>): Unmasked<TData> | void;
10801080
}
10811081

10821082
// @public (undocumented)
1083-
type UpdateQueryOptions<TData, TVariables> = {
1083+
type UpdateQueryOptions<TData, TVariables extends OperationVariables_2> = {
10841084
variables?: TVariables;
10851085
} & ({
10861086
complete: true;
@@ -1243,7 +1243,7 @@ export function useFragment<TData = unknown, TVariables extends OperationVariabl
12431243
// @public (undocumented)
12441244
export namespace useFragment {
12451245
// (undocumented)
1246-
export interface Options<TData, TVariables> {
1246+
export interface Options<TData, TVariables extends OperationVariables> {
12471247
client?: ApolloClient;
12481248
fragment: DocumentNode_2 | TypedDocumentNode_2<TData, TVariables>;
12491249
fragmentName?: string;
@@ -1263,7 +1263,7 @@ export namespace useFragment {
12631263
}
12641264

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

12681268
// @public @deprecated (undocumented)
12691269
export type UseFragmentResult<TData> = useFragment.Result<TData>;
@@ -1774,8 +1774,8 @@ type WatchQueryFetchPolicy_2 = FetchPolicy | "cache-and-network" | "standby";
17741774
// src/core/ApolloClient.ts:323:5 - (ae-forgotten-export) The symbol "WatchQueryFetchPolicy_2" needs to be exported by the entry point index.d.ts
17751775
// src/core/ApolloClient.ts:326:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
17761776
// src/core/ApolloClient.ts:338:5 - (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts
1777-
// src/core/ObservableQuery.ts:236:5 - (ae-forgotten-export) The symbol "NetworkStatus" needs to be exported by the entry point index.d.ts
1778-
// src/core/ObservableQuery.ts:359:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
1777+
// src/core/ObservableQuery.ts:237:5 - (ae-forgotten-export) The symbol "NetworkStatus" needs to be exported by the entry point index.d.ts
1778+
// src/core/ObservableQuery.ts:360:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
17791779
// src/core/QueryManager.ts:175:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
17801780
// src/core/types.ts:270:7 - (ae-forgotten-export) The symbol "DataValue" needs to be exported by the entry point index.d.ts
17811781
// 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
@@ -1023,7 +1023,7 @@ export type FetchPolicy = "cache-first" | "network-only" | "cache-only" | "no-ca
10231023
export type FetchResult<TData = Record<string, any>, TExtensions = Record<string, any>> = FormattedExecutionResult<TData, TExtensions> | AdditionalFetchResultTypes<TData, TExtensions>[keyof AdditionalFetchResultTypes<TData, TExtensions>];
10241024

10251025
// @public (undocumented)
1026-
export interface FieldFunctionOptions<TArgs = Record<string, any>, TVariables = Record<string, any>> {
1026+
export interface FieldFunctionOptions<TArgs = Record<string, any>, TVariables extends OperationVariables = Record<string, any>> {
10271027
// (undocumented)
10281028
args: TArgs | null;
10291029
// (undocumented)
@@ -1280,7 +1280,7 @@ namespace GraphQLCodegenDataMasking {
12801280
}
12811281

12821282
// @public (undocumented)
1283-
export interface GraphQLRequest<TVariables = Record<string, any>> {
1283+
export interface GraphQLRequest<TVariables extends OperationVariables = Record<string, any>> {
12841284
// (undocumented)
12851285
context?: DefaultContext;
12861286
// (undocumented)
@@ -1893,7 +1893,7 @@ interface MutationStoreValue {
18931893
}
18941894

18951895
// @public (undocumented)
1896-
export type MutationUpdaterFunction<TData, TVariables, TCache extends ApolloCache> = (cache: TCache, result: FormattedExecutionResult<Unmasked<TData>>, options: {
1896+
export type MutationUpdaterFunction<TData, TVariables extends OperationVariables, TCache extends ApolloCache> = (cache: TCache, result: FormattedExecutionResult<Unmasked<TData>>, options: {
18971897
context?: DefaultContext;
18981898
variables?: TVariables;
18991899
}) => void;
@@ -2291,7 +2291,7 @@ class QueryManager {
22912291
// (undocumented)
22922292
getObservableQueries(include?: InternalRefetchQueriesInclude): Set<ObservableQuery<any, OperationVariables>>;
22932293
// (undocumented)
2294-
getVariables<TVariables>(document: DocumentNode, variables?: TVariables): TVariables;
2294+
getVariables<TVariables extends OperationVariables>(document: DocumentNode, variables?: TVariables): TVariables;
22952295
// (undocumented)
22962296
readonly incrementalHandler: Incremental.Handler;
22972297
// (undocumented)
@@ -2732,14 +2732,14 @@ type UnwrapFragmentRefs<TData> = true extends IsAny<TData> ? TData : TData exten
27322732
} : TData : never;
27332733

27342734
// @public (undocumented)
2735-
export interface UpdateQueryMapFn<TData = unknown, TVariables = OperationVariables> {
2735+
export interface UpdateQueryMapFn<TData = unknown, TVariables extends OperationVariables = OperationVariables> {
27362736
// (undocumented)
27372737
(
27382738
unsafePreviousData: DeepPartial<Unmasked<TData>>, options: UpdateQueryOptions<TData, TVariables>): Unmasked<TData> | void;
27392739
}
27402740

27412741
// @public (undocumented)
2742-
export type UpdateQueryOptions<TData, TVariables> = {
2742+
export type UpdateQueryOptions<TData, TVariables extends OperationVariables> = {
27432743
variables?: TVariables;
27442744
} & ({
27452745
complete: true;
@@ -2814,13 +2814,13 @@ interface WriteContext extends ReadMergeModifyContext {
28142814
// Warnings were encountered during analysis:
28152815
//
28162816
// src/cache/core/cache.ts:94:9 - (ae-forgotten-export) The symbol "MissingTree" needs to be exported by the entry point index.d.ts
2817-
// src/cache/inmemory/policies.ts:97:3 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
2818-
// src/cache/inmemory/policies.ts:166:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts
2819-
// src/cache/inmemory/policies.ts:166:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts
2817+
// src/cache/inmemory/policies.ts:98:3 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
2818+
// src/cache/inmemory/policies.ts:167:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts
2819+
// src/cache/inmemory/policies.ts:167:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts
28202820
// src/cache/inmemory/types.ts:134:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
28212821
// src/core/ApolloClient.ts:163:5 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
28222822
// src/core/ApolloClient.ts:326:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
2823-
// src/core/ObservableQuery.ts:359:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
2823+
// src/core/ObservableQuery.ts:360:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
28242824
// src/core/QueryManager.ts:175:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
28252825
// src/local-state/LocalState.ts:140:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts
28262826
// 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)