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

Function matchQuery

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

Source from the content-addressed store, hash-verified

141}
142
143export function matchQuery(
144 filters: QueryFilters,
145 query: Query<any, any, any, any>,
146): boolean {
147 const {
148 type = 'all',
149 exact,
150 fetchStatus,
151 predicate,
152 queryKey,
153 stale,
154 } = filters
155
156 if (queryKey) {
157 if (exact) {
158 if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {
159 return false
160 }
161 } else if (!partialMatchKey(query.queryKey, queryKey)) {
162 return false
163 }
164 }
165
166 if (type !== 'all') {
167 const isActive = query.isActive()
168 if (type === 'active' && !isActive) {
169 return false
170 }
171 if (type === 'inactive' && isActive) {
172 return false
173 }
174 }
175
176 if (typeof stale === 'boolean' && query.isStale() !== stale) {
177 return false
178 }
179
180 if (fetchStatus && fetchStatus !== query.state.fetchStatus) {
181 return false
182 }
183
184 if (predicate && !predicate(query)) {
185 return false
186 }
187
188 return true
189}
190
191export function matchMutation(
192 filters: MutationFilters,

Callers 3

persisterFnFunction · 0.90
findMethod · 0.90
findAllMethod · 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