Skip to content

Commit bfd8de6

Browse files
committed
Pass through infinite query options
1 parent 03833a4 commit bfd8de6

File tree

3 files changed

+55
-35
lines changed

3 files changed

+55
-35
lines changed

packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,12 @@ export type CacheLifecycleQueryExtraOptions<
143143
}
144144

145145
// copying QueryDefinition to get past initial build
146-
interface InfiniteQueryExtraOptions<
147-
TagTypes extends string,
146+
export type CacheLifecycleInfiniteQueryExtraOptions<
148147
ResultType,
149148
QueryArg,
150149
BaseQuery extends BaseQueryFn,
151150
ReducerPath extends string = string,
152-
> {
151+
> = {
153152
onCacheEntryAdded?(
154153
arg: QueryArg,
155154
api: QueryCacheLifecycleApi<QueryArg, BaseQuery, ResultType, ReducerPath>,

packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,12 @@ export type QueryLifecycleQueryExtraOptions<
117117
}
118118

119119
// temporarily cloned QueryOptions again to just get the definition to build for now
120-
interface InfiniteQueryExtraOptions<
121-
TagTypes extends string,
120+
export type QueryLifecycleInfiniteQueryExtraOptions<
122121
ResultType,
123122
QueryArg,
124123
BaseQuery extends BaseQueryFn,
125124
ReducerPath extends string = string,
126-
> {
125+
> = {
127126
onQueryStarted?(
128127
arg: QueryArg,
129128
api: QueryLifecycleApi<QueryArg, BaseQuery, ResultType, ReducerPath>,

packages/toolkit/src/query/endpointDefinitions.ts

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import type {
1616
} from './baseQueryTypes'
1717
import type { CacheCollectionQueryExtraOptions } from './core/buildMiddleware/cacheCollection'
1818
import type {
19+
CacheLifecycleInfiniteQueryExtraOptions,
1920
CacheLifecycleMutationExtraOptions,
2021
CacheLifecycleQueryExtraOptions,
2122
} from './core/buildMiddleware/cacheLifecycle'
2223
import type {
24+
QueryLifecycleInfiniteQueryExtraOptions,
2325
QueryLifecycleMutationExtraOptions,
2426
QueryLifecycleQueryExtraOptions,
2527
} from './core/buildMiddleware/queryLifecycle'
@@ -261,13 +263,15 @@ type QueryTypes<
261263
* const useMyWrappedHook: UseQuery<typeof api.endpoints.query.Types.QueryDefinition> = ...
262264
* ```
263265
*/
264-
QueryDefinition: QueryDefinition<
265-
QueryArg,
266-
BaseQuery,
267-
TagTypes,
268-
ResultType,
269-
ReducerPath
270-
> | InfiniteQueryDefinition<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>
266+
QueryDefinition:
267+
| QueryDefinition<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>
268+
| InfiniteQueryDefinition<
269+
QueryArg,
270+
BaseQuery,
271+
TagTypes,
272+
ResultType,
273+
ReducerPath
274+
>
271275
TagTypes: TagTypes
272276
ReducerPath: ReducerPath
273277
}
@@ -569,7 +573,19 @@ export interface InfiniteQueryExtraOptions<
569573
QueryArg,
570574
BaseQuery extends BaseQueryFn,
571575
ReducerPath extends string = string,
572-
> {
576+
> extends CacheLifecycleInfiniteQueryExtraOptions<
577+
ResultType,
578+
QueryArg,
579+
BaseQuery,
580+
ReducerPath
581+
>,
582+
QueryLifecycleInfiniteQueryExtraOptions<
583+
ResultType,
584+
QueryArg,
585+
BaseQuery,
586+
ReducerPath
587+
>,
588+
CacheCollectionQueryExtraOptions {
573589
type: DefinitionType.infinitequery
574590

575591
providesTags?: never
@@ -955,14 +971,20 @@ export type OverrideResultType<Definition, NewResultType> =
955971
ReducerPath
956972
>
957973
: Definition extends InfiniteQueryDefinition<
958-
infer QueryArg,
959-
infer BaseQuery,
960-
infer TagTypes,
961-
any,
962-
infer ReducerPath
963-
>
964-
? InfiniteQueryDefinition<QueryArg, BaseQuery, TagTypes, NewResultType, ReducerPath>
965-
: never
974+
infer QueryArg,
975+
infer BaseQuery,
976+
infer TagTypes,
977+
any,
978+
infer ReducerPath
979+
>
980+
? InfiniteQueryDefinition<
981+
QueryArg,
982+
BaseQuery,
983+
TagTypes,
984+
NewResultType,
985+
ReducerPath
986+
>
987+
: never
966988

967989
export type UpdateDefinitions<
968990
Definitions extends EndpointDefinitions,
@@ -998,18 +1020,18 @@ export type UpdateDefinitions<
9981020
ReducerPath
9991021
>
10001022
: Definitions[K] extends InfiniteQueryDefinition<
1001-
infer QueryArg,
1002-
infer BaseQuery,
1003-
any,
1004-
infer ResultType,
1005-
infer ReducerPath
1006-
>
1007-
? InfiniteQueryDefinition<
1008-
QueryArg,
1009-
BaseQuery,
1010-
NewTagTypes,
1011-
TransformedResponse<NewDefinitions, K, ResultType>,
1012-
ReducerPath
1013-
>
1023+
infer QueryArg,
1024+
infer BaseQuery,
1025+
any,
1026+
infer ResultType,
1027+
infer ReducerPath
1028+
>
1029+
? InfiniteQueryDefinition<
1030+
QueryArg,
1031+
BaseQuery,
1032+
NewTagTypes,
1033+
TransformedResponse<NewDefinitions, K, ResultType>,
1034+
ReducerPath
1035+
>
10141036
: never
10151037
}

0 commit comments

Comments
 (0)