vuejs / apollo

🚀 Apollo/GraphQL integration for VueJS
http://apollo.vuejs.org
MIT License
6.01k stars 521 forks source link

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

Closed Zhuyi731 closed 1 month ago

Zhuyi731 commented 2 months ago

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 commented 2 months ago

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 commented 1 month ago

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