MCPcopy
hub / github.com/TanStack/query / setOptions

Method setOptions

packages/query-core/src/queryObserver.ts:139–221  ·  view source on GitHub ↗
(
    options: QueryObserverOptions<
      TQueryFnData,
      TError,
      TData,
      TQueryData,
      TQueryKey
    >,
  )

Source from the content-addressed store, hash-verified

137 }
138
139 setOptions(
140 options: QueryObserverOptions<
141 TQueryFnData,
142 TError,
143 TData,
144 TQueryData,
145 TQueryKey
146 >,
147 ): void {
148 const prevOptions = this.options
149 const prevQuery = this.#currentQuery
150
151 this.options = this.#client.defaultQueryOptions(options)
152
153 if (
154 this.options.enabled !== undefined &&
155 typeof this.options.enabled !== 'boolean' &&
156 typeof this.options.enabled !== 'function' &&
157 typeof resolveEnabled(this.options.enabled, this.#currentQuery) !==
158 'boolean'
159 ) {
160 throw new Error(
161 'Expected enabled to be a boolean or a callback that returns a boolean',
162 )
163 }
164
165 this.#updateQuery()
166 this.#currentQuery.setOptions(this.options)
167
168 if (
169 prevOptions._defaulted &&
170 !shallowEqualObjects(this.options, prevOptions)
171 ) {
172 this.#client.getQueryCache().notify({
173 type: 'observerOptionsUpdated',
174 query: this.#currentQuery,
175 observer: this,
176 })
177 }
178
179 const mounted = this.hasListeners()
180
181 // Fetch if there are subscribers
182 if (
183 mounted &&
184 shouldFetchOptionally(
185 this.#currentQuery,
186 prevQuery,
187 this.options,
188 prevOptions,
189 )
190 ) {
191 this.#executeFetch()
192 }
193
194 // Update result
195 this.updateResult()
196

Callers 1

constructorMethod · 0.95

Calls 14

#updateQueryMethod · 0.95
#executeFetchMethod · 0.95
updateResultMethod · 0.95
#updateStaleTimeoutMethod · 0.95
resolveEnabledFunction · 0.90
shallowEqualObjectsFunction · 0.90
resolveStaleTimeFunction · 0.90
shouldFetchOptionallyFunction · 0.85
defaultQueryOptionsMethod · 0.80
getQueryCacheMethod · 0.80

Tested by

no test coverage detected