Skip to content

Commit a59476e

Browse files
committed
call initiate to refetch queries from middleware
1 parent 8178e7f commit a59476e

File tree

5 files changed

+9
-15
lines changed

5 files changed

+9
-15
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424
InternalMiddlewareState,
2525
} from './types'
2626
import { buildWindowEventHandler } from './windowEventHandling'
27+
import type { ApiEndpointQuery } from '../module'
2728
export type { ReferenceCacheCollection } from './cacheCollection'
2829
export type {
2930
MutationCacheLifecycleApi,
@@ -146,17 +147,10 @@ export function buildMiddleware<
146147
QuerySubState<any>,
147148
{ status: QueryStatus.uninitialized }
148149
>,
149-
queryCacheKey: string,
150-
override: Partial<QueryThunkArg> = {},
151150
) {
152-
return queryThunk({
153-
type: 'query',
154-
endpointName: querySubState.endpointName,
155-
originalArgs: querySubState.originalArgs,
151+
return (input.api.endpoints[querySubState.endpointName] as ApiEndpointQuery<any, any>).initiate(querySubState.originalArgs as any, {
156152
subscribe: false,
157153
forceRefetch: true,
158-
queryCacheKey: queryCacheKey as any,
159-
...override,
160154
})
161155
}
162156
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export const buildInvalidationByTagsHandler: InternalHandlerBuilder = ({
122122
}),
123123
)
124124
} else if (querySubState.status !== QueryStatus.uninitialized) {
125-
mwApi.dispatch(refetchQuery(querySubState, queryCacheKey))
125+
mwApi.dispatch(refetchQuery(querySubState))
126126
}
127127
}
128128
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const buildPollingHandler: InternalHandlerBuilder = ({
7878
pollingInterval: lowestPollingInterval,
7979
timeout: setTimeout(() => {
8080
if (state.config.focused || !skipPollingIfUnfocused) {
81-
api.dispatch(refetchQuery(querySubState, queryCacheKey))
81+
api.dispatch(refetchQuery(querySubState))
8282
}
8383
startNextPoll({ queryCacheKey }, api)
8484
}, lowestPollingInterval),

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
AsyncThunkAction,
44
Middleware,
55
MiddlewareAPI,
6+
ThunkAction,
67
ThunkDispatch,
78
UnknownAction,
89
} from '@reduxjs/toolkit'
@@ -23,6 +24,7 @@ import type {
2324
QueryThunkArg,
2425
ThunkResult,
2526
} from '../buildThunks'
27+
import type { QueryActionCreatorResult } from '../buildInitiate'
2628

2729
export type QueryStateMeta<T> = Record<string, undefined | T>
2830
export type TimeoutId = ReturnType<typeof setTimeout>
@@ -62,10 +64,8 @@ export interface BuildSubMiddlewareInput
6264
querySubState: Exclude<
6365
QuerySubState<any>,
6466
{ status: QueryStatus.uninitialized }
65-
>,
66-
queryCacheKey: string,
67-
override?: Partial<QueryThunkArg>,
68-
): AsyncThunkAction<ThunkResult, QueryThunkArg, {}>
67+
>
68+
): ThunkAction<QueryActionCreatorResult<any>, any, any, UnknownAction>
6969
isThisApiSliceAction: (action: Action) => boolean
7070
}
7171

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const buildWindowEventHandler: InternalHandlerBuilder = ({
5858
}),
5959
)
6060
} else if (querySubState.status !== QueryStatus.uninitialized) {
61-
api.dispatch(refetchQuery(querySubState, queryCacheKey))
61+
api.dispatch(refetchQuery(querySubState))
6262
}
6363
}
6464
}

0 commit comments

Comments
 (0)