vuejs / apollo

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

Usage of debounce triggers query twice #1417

Open dominikklein opened 2 years ago

dominikklein commented 2 years ago

Describe the bug When I use the debounce for my query, it triggered twice, once directly when I call the composable and then a second time after the debounce time is over.

Expected behavior The query should not be triggered twice. For me it should be triggered directly when I call the composable and then the debounce should be used when some update is happening.

Versions vue: 3.2.40 @vue/apollo-composable: "^4.0.0-beta.1", @apollo/client: ^3.6.9

vhatsura commented 1 year ago

I experience the same behavior, but in my case a reason a little bit different. I use debounce with enabled option.

const { result, loading } = useQuery<{ items: ItemsConnection }>(
  SEARCH_ITEMS,
  () => ({ where: { name: { contains: toValue(searchTerm) } }, first }),
  () => ({ debounce: 500, enabled: toValue(searchTerm) !== '' }),
);

The query triggers twice, the 1st time when it enables and then after the debounce period