Skip to content

Commit 12c48af

Browse files
committed
add tests
1 parent 003433e commit 12c48af

File tree

3 files changed

+410
-6
lines changed

3 files changed

+410
-6
lines changed

packages/toolkit/src/query/core/buildThunks.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,6 @@ export function buildThunks<
278278
api.util.patchQueryData(endpointName, args, ret.inversePatches)
279279
),
280280
}
281-
if (currentState.status === QueryStatus.uninitialized) {
282-
return ret
283-
}
284281
if ('data' in currentState) {
285282
if (isDraftable(currentState.data)) {
286283
const [, patches, inversePatches] = produceWithPatches(
@@ -305,10 +302,22 @@ export function buildThunks<
305302
path: [],
306303
value: undefined,
307304
})
308-
dispatch(api.endpoints[endpointName].initiate(args, {subscribe: false, forceRefetch: true, }))
305+
dispatch(
306+
(
307+
api.endpoints[endpointName] as ApiEndpointQuery<
308+
QueryDefinition<any, any, any, any, any>,
309+
Definitions
310+
>
311+
).initiate(args, {
312+
subscribe: false,
313+
forceRefetch: true,
314+
forceQueryFn: () => ({
315+
data: upsertRecipe(undefined),
316+
}),
317+
})
318+
)
309319
}
310320

311-
312321
return ret
313322
}
314323

packages/toolkit/src/query/core/module.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
/**
22
* Note: this file should import all other files for type discovery and declaration merging
33
*/
4-
import type { PatchQueryDataThunk, UpdateQueryDataThunk } from './buildThunks'
4+
import type {
5+
PatchQueryDataThunk,
6+
UpdateQueryDataThunk,
7+
UpsertQueryDataThunk,
8+
} from './buildThunks'
59
import { buildThunks } from './buildThunks'
610
import type {
711
ActionCreatorWithPayload,
@@ -210,6 +214,10 @@ declare module '../apiTypes' {
210214
Definitions,
211215
RootState<Definitions, string, ReducerPath>
212216
>
217+
upsertQueryData: UpsertQueryDataThunk<
218+
Definitions,
219+
RootState<Definitions, string, ReducerPath>
220+
>
213221
/**
214222
* A Redux thunk that applies a JSON diff/patch array to the cached data for a given query result. This immediately updates the Redux state with those changes.
215223
*
@@ -406,6 +414,7 @@ export const coreModule = (): Module<CoreModule> => ({
406414
mutationThunk,
407415
patchQueryData,
408416
updateQueryData,
417+
upsertQueryData,
409418
prefetch,
410419
buildMatchThunkActions,
411420
} = buildThunks({
@@ -434,6 +443,7 @@ export const coreModule = (): Module<CoreModule> => ({
434443
safeAssign(api.util, {
435444
patchQueryData,
436445
updateQueryData,
446+
upsertQueryData,
437447
prefetch,
438448
resetApiState: sliceActions.resetApiState,
439449
})

0 commit comments

Comments
 (0)