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

Function matchQuery

packages/query-core/src/utils.ts:205–251  ·  view source on GitHub ↗
(
  filters: QueryFilters,
  query: Query<any, any, any, any>,
)

Source from the content-addressed store, hash-verified

203 * ```
204 */
205export function matchQuery(
206 filters: QueryFilters,
207 query: Query<any, any, any, any>,
208): boolean {
209 const {
210 type = 'all',
211 exact,
212 fetchStatus,
213 predicate,
214 queryKey,
215 stale,
216 } = filters
217
218 if (queryKey) {
219 if (exact) {
220 if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {
221 return false
222 }
223 } else if (!partialMatchKey(query.queryKey, queryKey)) {
224 return false
225 }
226 }
227
228 if (type !== 'all') {
229 const isActive = query.isActive()
230 if (type === 'active' && !isActive) {
231 return false
232 }
233 if (type === 'inactive' && isActive) {
234 return false
235 }
236 }
237
238 if (typeof stale === 'boolean' && query.isStale() !== stale) {
239 return false
240 }
241
242 if (fetchStatus && fetchStatus !== query.state.fetchStatus) {
243 return false
244 }
245
246 if (predicate && !predicate(query)) {
247 return false
248 }
249
250 return true
251}
252
253/**
254 * Checks whether a mutation matches the given {@link MutationFilters}.

Callers 4

persisterFnFunction · 0.90
findMethod · 0.90
findAllMethod · 0.90
utils.test-d.tsxFile · 0.90

Calls 5

hashQueryKeyByOptionsFunction · 0.85
partialMatchKeyFunction · 0.85
isActiveMethod · 0.80
isStaleMethod · 0.80
predicateFunction · 0.50

Tested by

no test coverage detected