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

Function matchQuery

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

Source from the content-addressed store, hash-verified

132}
133
134export function matchQuery(
135 filters: QueryFilters,
136 query: Query<any, any, any, any>,
137): boolean {
138 const {
139 type = 'all',
140 exact,
141 fetchStatus,
142 predicate,
143 queryKey,
144 stale,
145 } = filters
146
147 if (queryKey) {
148 if (exact) {
149 if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {
150 return false
151 }
152 } else if (!partialMatchKey(query.queryKey, queryKey)) {
153 return false
154 }
155 }
156
157 if (type !== 'all') {
158 const isActive = query.isActive()
159 if (type === 'active' && !isActive) {
160 return false
161 }
162 if (type === 'inactive' && isActive) {
163 return false
164 }
165 }
166
167 if (typeof stale === 'boolean' && query.isStale() !== stale) {
168 return false
169 }
170
171 if (fetchStatus && fetchStatus !== query.state.fetchStatus) {
172 return false
173 }
174
175 if (predicate && !predicate(query)) {
176 return false
177 }
178
179 return true
180}
181
182export function matchMutation(
183 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