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

Method build

packages/query-core/src/queryCache.ts:147–178  ·  view source on GitHub ↗

* Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or * builds and adds a new one to the cache if none exists yet. Used by framework adapters and * plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing * the reactiv

(
    client: QueryClient,
    options: WithRequired<
      QueryOptions<TQueryFnData, TError, TData, TQueryKey>,
      'queryKey'
    >,
    state?: QueryState<TData, TError>,
  )

Source from the content-addressed store, hash-verified

145 * ```
146 */
147 build<
148 TQueryFnData = unknown,
149 TError = DefaultError,
150 TData = TQueryFnData,
151 TQueryKey extends QueryKey = QueryKey,
152 >(
153 client: QueryClient,
154 options: WithRequired<
155 QueryOptions<TQueryFnData, TError, TData, TQueryKey>,
156 'queryKey'
157 >,
158 state?: QueryState<TData, TError>,
159 ): Query<TQueryFnData, TError, TData, TQueryKey> {
160 const queryKey = options.queryKey
161 const queryHash =
162 options.queryHash ?? hashQueryKeyByOptions(queryKey, options)
163 let query = this.get<TQueryFnData, TError, TData, TQueryKey>(queryHash)
164
165 if (!query) {
166 query = new Query({
167 client,
168 queryKey,
169 queryHash,
170 options: client.defaultQueryOptions(options),
171 state,
172 defaultOptions: client.getQueryDefaults(queryKey),
173 })
174 this.add(query)
175 }
176
177 return query
178 }
179
180 /** @internal */
181 add(query: Query<any, any, any, any>): void {

Callers 15

buildQueryFunction · 0.45
buildMutationFunction · 0.45
makeStateFunction · 0.45
Devtools.test.tsxFile · 0.45
persist.test.tsFile · 0.45
ensureQueryDataMethod · 0.45
setQueryDataMethod · 0.45
queryMethod · 0.45
fetchQueryMethod · 0.45

Calls 5

getMethod · 0.95
addMethod · 0.95
hashQueryKeyByOptionsFunction · 0.90
defaultQueryOptionsMethod · 0.80
getQueryDefaultsMethod · 0.45

Tested by 4

buildQueryFunction · 0.36
buildMutationFunction · 0.36
makeStateFunction · 0.36
executeMutationFunction · 0.36