MCPcopy Create free account
hub / github.com/TanStack/query / execute

Method execute

packages/query-core/src/mutation.ts:173–329  ·  view source on GitHub ↗
(variables: TVariables)

Source from the content-addressed store, hash-verified

171 }
172
173 async execute(variables: TVariables): Promise<TData> {
174 const onContinue = () => {
175 this.#dispatch({ type: 'continue' })
176 }
177
178 const mutationFnContext = {
179 client: this.#client,
180 meta: this.options.meta,
181 mutationKey: this.options.mutationKey,
182 } satisfies MutationFunctionContext
183
184 this.#retryer = createRetryer({
185 fn: () => {
186 if (!this.options.mutationFn) {
187 return Promise.reject(new Error('No mutationFn found'))
188 }
189
190 return this.options.mutationFn(variables, mutationFnContext)
191 },
192 onFail: (failureCount, error) => {
193 this.#dispatch({ type: 'failed', failureCount, error })
194 },
195 onPause: () => {
196 this.#dispatch({ type: 'pause' })
197 },
198 onContinue,
199 retry: this.options.retry ?? 0,
200 retryDelay: this.options.retryDelay,
201 networkMode: this.options.networkMode,
202 canRun: () => this.#mutationCache.canRun(this),
203 })
204
205 const restored = this.state.status === 'pending'
206 const isPaused = !this.#retryer.canStart()
207
208 try {
209 if (restored) {
210 // Dispatch continue action to unpause restored mutation
211 onContinue()
212 } else {
213 this.#dispatch({ type: 'pending', variables, isPaused })
214 // Notify cache callback
215 if (this.#mutationCache.config.onMutate) {
216 await this.#mutationCache.config.onMutate(
217 variables,
218 this as Mutation<unknown, unknown, unknown, unknown>,
219 mutationFnContext,
220 )
221 }
222 const context = await this.options.onMutate?.(
223 variables,
224 mutationFnContext,
225 )
226 if (context !== this.state.context) {
227 this.#dispatch({
228 type: 'pending',
229 context,
230 variables,

Callers 12

continueMethod · 0.95
transformUsagesFunction · 0.80
transformUsagesFunction · 0.80
Devtools.test.tsxFile · 0.80
mutateMethod · 0.80
executeMutationFunction · 0.80

Calls 4

#dispatchMethod · 0.95
createRetryerFunction · 0.90
canRunMethod · 0.80
runNextMethod · 0.80

Tested by 1

executeMutationFunction · 0.64