MCPcopy Create free account
hub / github.com/SvelteStack/svelte-query / execute

Method execute

src/queryCore/core/mutation.ts:136–229  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

134 }
135
136 execute(): Promise<TData> {
137 let data: TData
138
139 const restored = this.state.status === 'loading'
140
141 let promise = Promise.resolve()
142
143 if (!restored) {
144 this.dispatch({ type: 'loading', variables: this.options.variables! })
145 promise = promise
146 .then(() => {
147 // Notify cache callback
148 this.mutationCache.config.onMutate?.(
149 this.state.variables,
150 this as Mutation<unknown, unknown, unknown, unknown>
151 )
152 })
153 .then(() => this.options.onMutate?.(this.state.variables!))
154 .then(context => {
155 if (context !== this.state.context) {
156 this.dispatch({
157 type: 'loading',
158 context,
159 variables: this.state.variables,
160 })
161 }
162 })
163 }
164
165 return promise
166 .then(() => this.executeMutation())
167 .then(result => {
168 data = result
169 // Notify cache callback
170 this.mutationCache.config.onSuccess?.(
171 data,
172 this.state.variables,
173 this.state.context,
174 this as Mutation<unknown, unknown, unknown, unknown>
175 )
176 })
177 .then(() =>
178 this.options.onSuccess?.(
179 data,
180 this.state.variables!,
181 this.state.context!
182 )
183 )
184 .then(() =>
185 this.options.onSettled?.(
186 data,
187 null,
188 this.state.variables!,
189 this.state.context
190 )
191 )
192 .then(() => {
193 this.dispatch({ type: 'success', data })

Callers 3

continueMethod · 0.95
executeMutationMethod · 0.80
mutateMethod · 0.80

Calls 4

dispatchMethod · 0.95
executeMutationMethod · 0.95
getLoggerFunction · 0.90
resolveMethod · 0.80

Tested by

no test coverage detected