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

Function matchQuery

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

Source from the content-addressed store, hash-verified

173 * ```
174 */
175export function matchQuery(
176 filters: QueryFilters,
177 query: Query<any, any, any, any>,
178): boolean {
179 const {
180 type = 'all',
181 exact,
182 fetchStatus,
183 predicate,
184 queryKey,
185 stale,
186 } = filters
187
188 if (queryKey) {
189 if (exact) {
190 if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {
191 return false
192 }
193 } else if (!partialMatchKey(query.queryKey, queryKey)) {
194 return false
195 }
196 }
197
198 if (type !== 'all') {
199 const isActive = query.isActive()
200 if (type === 'active' && !isActive) {
201 return false
202 }
203 if (type === 'inactive' && isActive) {
204 return false
205 }
206 }
207
208 if (typeof stale === 'boolean' && query.isStale() !== stale) {
209 return false
210 }
211
212 if (fetchStatus && fetchStatus !== query.state.fetchStatus) {
213 return false
214 }
215
216 if (predicate && !predicate(query)) {
217 return false
218 }
219
220 return true
221}
222
223/**
224 * 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