Skip to content

Expose queryClient in QueryFunctionContext #3151

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

Closed
GLabat opened this issue Dec 31, 2021 · 4 comments
Closed

Expose queryClient in QueryFunctionContext #3151

GLabat opened this issue Dec 31, 2021 · 4 comments

Comments

@GLabat
Copy link
Contributor

GLabat commented Dec 31, 2021

however, composing query functions from other queries of the same client seems useful. for example, you can currently do this via:

const queryClient = useQueryClient()
useQuery(key, () => queryClient.getQueryData(something) ?? axios.get(...))

if the query function is not inlined, passing the client is necessary, so I agree that having the client injected might be useful in some cases. I'll definitely think about it :)

Originally posted by @TkDodo in #2764 (comment)

This issue is a follow-up of the discussion above.
The idea is to have access to the queryClient in the queryFn, using QueryFunctionContext to simplify usage when the queryFn is defined outside of a useQuery/fetchQuery call.

@GLabat
Copy link
Contributor Author

GLabat commented Jan 2, 2022

Should consider #2548 which adds the ability to nest QueryClient contexts.
Once merged, if the queryClient is passed in someway to the queryFn, it should the "good" one, ie. the one from the query context.

@TkDodo
Copy link
Collaborator

TkDodo commented May 8, 2022

I've decided to not move along with this for now. The use-case is pretty narrow, and the custom context complicates that a bit more. There also doesn't seem to be an incredible need for this features.

@TkDodo TkDodo closed this as completed May 8, 2022
@Tirzono
Copy link

Tirzono commented Jul 18, 2023

I would be interested in having this feature. Is the reason why this is not considered the fact that it is too much work or is it that this functionality is not wanted? If it's the first then I might be able to look into it. What are the things to consider that could make the implementation difficult?

@TkDodo
Copy link
Collaborator

TkDodo commented Jul 18, 2023

you can use the same query from within multiple providers, but there is only one Query instance. Only observers have access to the QueryClient, the query itself (which also runs the queryFn) does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants