Skip to content

useQuery onResult callback not being called on second query attempt in V4.0.0-Beta.2-4 #1472

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
garrlker opened this issue May 13, 2023 · 4 comments

Comments

@garrlker
Copy link

Describe the bug
Starting in V4.0.0-Beta.2, when using the onResult callback to receive data from useQuery function, you only receive data from onResult on the first call.

The 2nd call, and so on, never return data with the onResult callback.

V4.0.0-Beta.1 does call the hook every time useQuery is called.

To Reproduce
I've created a reproduction you can run on StackBlitz.

To see what I'm describing, click on the Catch Pikachu button and watch the data flow into the page.
Then click the button again.

You will see the page clear and the data never load back in while the loading text stays on screen indefinitely because onResult never sets it to false.

You'll also see where the console only has one onResult log no matter how many times you click.

Expected behavior

I expect that onResult will be called with response data every time useQuery is called.

Versions
vue: 3.3.2
vue-apollo: 4.0.0-Beta.2 - 4
@apollo/client: 3.7.14

Additional context

Unrelated question, why is it in my StackBlitz example that I have to call ProvideApolloClient in the fetchPikachuData function for useQuery to see the default client?

@garrlker
Copy link
Author

After looking at the changes that came into beta.2 I think the changes in either #1388 or ones related to #1432 may be what is causing this to fail.

@Akryum @ishitatsuyuki What is the expected behaviour for the onResult function on subsequent queries?

@Akryum
Copy link
Member

Akryum commented May 16, 2023

Unrelated question, why is it in my StackBlitz example that I have to call ProvideApolloClient in the fetchPikachuData function for useQuery to see the default client?

You are calling useQuery outside of the component setup context, so you vue-apollo doesn't have the component context whenever you click on the button. That's also probably why your code breaks.

@Akryum
Copy link
Member

Akryum commented May 16, 2023

@Akryum Akryum closed this as completed May 16, 2023
@garrlker
Copy link
Author

garrlker commented May 16, 2023

Awesome!

I see what you mean using it outside of script setup. I'm using vue-apollo inside of a pinia store in the main app I'm debugging.

Is there a better way to use Vue-Apollo composition inside a store without having to provide the client in every single store?

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

2 participants