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

Function useBaseQuery

packages/solid-query/src/useBaseQuery.ts:103–387  ·  view source on GitHub ↗
(
  options: Accessor<
    UseBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>
  >,
  Observer: typeof QueryObserver,
  queryClient?: Accessor<QueryClient>,
)

Source from the content-addressed store, hash-verified

101
102// Base Query Function that is used to create the query.
103export function useBaseQuery<
104 TQueryFnData,
105 TError,
106 TData,
107 TQueryData,
108 TQueryKey extends QueryKey,
109>(
110 options: Accessor<
111 UseBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>
112 >,
113 Observer: typeof QueryObserver,
114 queryClient?: Accessor<QueryClient>,
115) {
116 type ResourceData = QueryObserverResult<TData, TError>
117
118 const resolveClient = useQueryClientResolver(queryClient)
119 const client = createMemo(() => resolveClient())
120 const isRestoring = useIsRestoring()
121 // There are times when we run a query on the server but the resource is never read
122 // This could lead to times when the queryObserver is unsubscribed before the resource has loaded
123 // Causing a time out error. To prevent this we will queue the unsubscribe if the cleanup is called
124 // before the resource has loaded
125 let unsubscribeQueued = false
126
127 const defaultedOptions = createMemo(() => {
128 const defaultOptions = client().defaultQueryOptions(options())
129 defaultOptions._optimisticResults = isRestoring()
130 ? 'isRestoring'
131 : 'optimistic'
132 defaultOptions.structuralSharing = false
133 if (isServer) {
134 defaultOptions.retry = false
135 defaultOptions.throwOnError = true
136 }
137 return defaultOptions
138 })
139 const initialOptions = defaultedOptions()
140
141 const [observer, setObserver] = createSignal(
142 new Observer(client(), defaultedOptions()),
143 )
144
145 let observerResult = observer().getOptimisticResult(defaultedOptions())
146 const [state, setState] =
147 createStore<QueryObserverResult<TData, TError>>(observerResult)
148
149 const createServerSubscriber = (
150 resolve: (
151 data: ResourceData | PromiseLike<ResourceData | undefined> | undefined,
152 ) => void,
153 reject: (reason?: any) => void,
154 ) => {
155 return observer().subscribe((result) => {
156 notifyManager.batchCalls(() => {
157 const query = observer().getCurrentQuery()
158 const unwrappedResult = hydratableObserverResult(query, result)
159
160 if (result.data !== undefined && unwrappedResult.isError) {

Callers 2

useQueryFunction · 0.90
useInfiniteQueryFunction · 0.90

Calls 15

useQueryClientResolverFunction · 0.90
useIsRestoringFunction · 0.90
shouldThrowErrorFunction · 0.90
clientFunction · 0.85
createServerSubscriberFunction · 0.85
createClientSubscriberFunction · 0.85
rejectFunction · 0.85
resolveFunction · 0.85
hydratableObserverResultFunction · 0.85
refetchFunction · 0.85
defaultQueryOptionsMethod · 0.80

Tested by

no test coverage detected