-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/query client on context #8599
Changes from all commits
aa2eaab
1f321e7
88e80d1
c868928
6871408
2695d80
825d9aa
94ef54d
67a405a
1a00f3f
4f43f79
840b47f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ import { | |
import { notifyManager } from './notifyManager' | ||
import { canFetch, createRetryer, isCancelledError } from './retryer' | ||
import { Removable } from './removable' | ||
import type { QueryCache } from './queryCache' | ||
import type { QueryClient } from './queryClient' | ||
import type { | ||
CancelOptions, | ||
DefaultError, | ||
|
@@ -23,7 +25,6 @@ import type { | |
QueryStatus, | ||
SetDataOptions, | ||
} from './types' | ||
import type { QueryCache } from './queryCache' | ||
import type { QueryObserver } from './queryObserver' | ||
import type { Retryer } from './retryer' | ||
|
||
|
@@ -35,7 +36,7 @@ interface QueryConfig< | |
TData, | ||
TQueryKey extends QueryKey = QueryKey, | ||
> { | ||
cache: QueryCache | ||
client: QueryClient | ||
queryKey: TQueryKey | ||
queryHash: string | ||
options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey> | ||
|
@@ -68,6 +69,7 @@ export interface FetchContext< | |
fetchOptions?: FetchOptions | ||
signal: AbortSignal | ||
options: QueryOptions<TQueryFnData, TError, TData, any> | ||
client: QueryClient | ||
queryKey: TQueryKey | ||
state: QueryState<TData, TError> | ||
} | ||
|
@@ -167,6 +169,7 @@ export class Query< | |
#initialState: QueryState<TData, TError> | ||
#revertState?: QueryState<TData, TError> | ||
#cache: QueryCache | ||
#client: QueryClient | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to get a getter for QueryClient from the instance of Query. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you probably don’t need that now that it’s passed to the |
||
#retryer?: Retryer<TData> | ||
observers: Array<QueryObserver<any, any, any, any, any>> | ||
#defaultOptions?: QueryOptions<TQueryFnData, TError, TData, TQueryKey> | ||
|
@@ -179,7 +182,8 @@ export class Query< | |
this.#defaultOptions = config.defaultOptions | ||
this.setOptions(config.options) | ||
this.observers = [] | ||
this.#cache = config.cache | ||
this.#client = config.client | ||
this.#cache = this.#client.getQueryCache() | ||
this.queryKey = config.queryKey | ||
this.queryHash = config.queryHash | ||
this.#initialState = getDefaultState(this.options) | ||
|
@@ -411,6 +415,7 @@ export class Query< | |
QueryFunctionContext<TQueryKey>, | ||
'signal' | ||
> = { | ||
client: this.#client, | ||
queryKey: this.queryKey, | ||
meta: this.meta, | ||
} | ||
|
@@ -437,6 +442,7 @@ export class Query< | |
fetchOptions, | ||
options: this.options, | ||
queryKey: this.queryKey, | ||
client: this.#client, | ||
state: this.state, | ||
fetchFn, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: we don’t need an exception for closing over the
queryClient
anymore if we inject it into thequeryFn
. @Newbie012 would you agree?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess so. I never had to deal with more than one query client in a single app. Is it a valid use case to reference a foreign query client inside queryFn?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, this is something the linter should definitely catch!