Skip to content
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

refetch in useQuery will auto merge the previous variable with current variable #1561

Closed
Zhuyi731 opened this issue Jul 1, 2024 · 2 comments · Fixed by #1564
Closed

refetch in useQuery will auto merge the previous variable with current variable #1561

Zhuyi731 opened this issue Jul 1, 2024 · 2 comments · Fixed by #1564

Comments

@Zhuyi731
Copy link

Zhuyi731 commented Jul 1, 2024

Describe the bug
refetch in useQuery will auto merge the previous variable with current variable

To Reproduce
Steps to reproduce the behavior:

see the code below

const testGql = gql`
  query lossList($query: String){
  }   
`
const { refetch } = useQuery(testGql, params, options)
refetch({ query:"first time" })    // the first time with variable  query: first time
refetch({})    //  the second time, I don't want to pass any variable to backend, but it will still merge the privious variable into the current varible

** Reason **
it is caused by the code this line. I think this is a bug, sometimes the server do need a empty request variable.
image

Expected behavior
the second time's request should request with no varibale

Versions
vue: 3.4.21
vue-apollo: 4.0.2
@apollo/client: 3.9.9

@tristandubbeld
Copy link

I think this is a feature rather than a bug, I've recently encountered this too. It's a bit hidden but the docs state the following:

If you provide new values for some of your original query's variables but not all of them, refetch uses each omitted variable's original value.

What fixed it for me was explicitly setting the property value to null.

@nickmessing
Copy link
Member

@tristandubbeld that is correct, we should probably try to be more explicit in the docs about it.

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

Successfully merging a pull request may close this issue.

4 participants