@@ -9,14 +9,15 @@ import type {
9
9
BaseQueryResult ,
10
10
QueryReturnValue ,
11
11
} from './baseQueryTypes'
12
+ import type { QuerySubState , RootState } from './core'
12
13
import type {
13
- MutationCacheLifecycleApi ,
14
- MutationLifecycleApi ,
15
- QuerySubState ,
16
- RootState ,
17
- } from './core'
18
- import type { CacheLifecycleQueryExtraOptions } from './core/buildMiddleware/cacheLifecycle'
19
- import type { QueryLifecycleQueryExtraOptions } from './core/buildMiddleware/queryLifecycle'
14
+ CacheLifecycleMutationExtraOptions ,
15
+ CacheLifecycleQueryExtraOptions ,
16
+ } from './core/buildMiddleware/cacheLifecycle'
17
+ import type {
18
+ QueryLifecycleMutationExtraOptions ,
19
+ QueryLifecycleQueryExtraOptions ,
20
+ } from './core/buildMiddleware/queryLifecycle'
20
21
import type { SerializeQueryArgs } from './defaultSerializeQueryArgs'
21
22
import type { NEVER } from './fakeBaseQuery'
22
23
import type {
@@ -563,71 +564,19 @@ export interface MutationExtraOptions<
563
564
QueryArg ,
564
565
BaseQuery extends BaseQueryFn ,
565
566
ReducerPath extends string = string ,
566
- > {
567
- type : DefinitionType . mutation
568
-
569
- onCacheEntryAdded ?(
570
- arg : QueryArg ,
571
- api : MutationCacheLifecycleApi <
567
+ > extends CacheLifecycleMutationExtraOptions <
568
+ ResultType ,
572
569
QueryArg ,
573
570
BaseQuery ,
574
- ResultType ,
575
571
ReducerPath
576
572
> ,
577
- ) : Promise < void > | void
578
-
579
- /**
580
- * A function that is called when the individual mutation is started. The function is called with a lifecycle api object containing properties such as `queryFulfilled`, allowing code to be run when a query is started, when it succeeds, and when it fails (i.e. throughout the lifecycle of an individual query/mutation call).
581
- *
582
- * Can be used for `optimistic updates`.
583
- *
584
- * @example
585
- *
586
- * ```ts
587
- * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query'
588
- * export interface Post {
589
- * id: number
590
- * name: string
591
- * }
592
- *
593
- * const api = createApi({
594
- * baseQuery: fetchBaseQuery({
595
- * baseUrl: '/',
596
- * }),
597
- * tagTypes: ['Post'],
598
- * endpoints: (build) => ({
599
- * getPost: build.query<Post, number>({
600
- * query: (id) => `post/${id}`,
601
- * providesTags: ['Post'],
602
- * }),
603
- * updatePost: build.mutation<void, Pick<Post, 'id'> & Partial<Post>>({
604
- * query: ({ id, ...patch }) => ({
605
- * url: `post/${id}`,
606
- * method: 'PATCH',
607
- * body: patch,
608
- * }),
609
- * invalidatesTags: ['Post'],
610
- * async onQueryStarted({ id, ...patch }, { dispatch, queryFulfilled }) {
611
- * const patchResult = dispatch(
612
- * api.util.updateQueryData('getPost', id, (draft) => {
613
- * Object.assign(draft, patch)
614
- * })
615
- * )
616
- * try {
617
- * await queryFulfilled
618
- * } catch {
619
- * patchResult.undo()
620
- * }
621
- * },
622
- * }),
623
- * }),
624
- * })
625
- * ```
626
- */
627
- onQueryStarted ?(
628
- arg : QueryArg ,
629
- api : MutationLifecycleApi < QueryArg , BaseQuery , ResultType , ReducerPath > ,
630
- ) : Promise < void > | void
573
+ QueryLifecycleMutationExtraOptions <
574
+ ResultType ,
575
+ QueryArg ,
576
+ BaseQuery ,
577
+ ReducerPath
578
+ > {
579
+ type : DefinitionType . mutation
631
580
632
581
/**
633
582
* Used by `mutation` endpoints. Determines which cached data should be either re-fetched or removed from the cache.
0 commit comments