Skip to content

Commit 8c3f5dd

Browse files
barnabasJmarkerikson
authored andcommitted
add tests
1 parent e502bc8 commit 8c3f5dd

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
*
@@ -416,6 +424,7 @@ export const coreModule = (): Module<CoreModule> => ({
416424
mutationThunk,
417425
patchQueryData,
418426
updateQueryData,
427+
upsertQueryData,
419428
prefetch,
420429
buildMatchThunkActions,
421430
} = buildThunks({
@@ -444,6 +453,7 @@ export const coreModule = (): Module<CoreModule> => ({
444453
safeAssign(api.util, {
445454
patchQueryData,
446455
updateQueryData,
456+
upsertQueryData,
447457
prefetch,
448458
resetApiState: sliceActions.resetApiState,
449459
})

0 commit comments

Comments
 (0)