Provide examples for useQuery with reactive values
See original GitHub issueAfter lots of debugging headaches https://github.com/SvelteStack/svelte-query/discussions/87 we discovered that we weren’t using useQuery
correctly when passing in reactive values.
We searched all sorts of different keywords online, and the only reference I could find to reactive values in queries was this one issue https://github.com/SvelteStack/svelte-query/issues/43
Could you please add examples for the docs using dependent queries with reactive values?
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:7
Top Results From Across the Web
Reactive variables - Apollo GraphQL Docs
A query "depends on" a reactive variable if any of the query's requested fields defines a read function that reads the variable's value....
Read more >Reactive Variables In GraphQL Apollo Client
We will be looking at how to query a reactive variable, how to update the value stored in a reactive variable, and how...
Read more >useQuery() - villus
The useQuery function allows you to execute GraphQL queries, it requires a Provider or useClient to be called in the component tree, so...
Read more >Build: Reactive variables with Apollo client - YouTube
Liz and Trevor level up with reactive variables in Apollo client, in order to manage local state in an app.Follow our example code...
Read more >Reactive Query | Vue Apollo
update(data) {return ...} to customize the value that is set in the vue property, for example if the field names don't match. result(ApolloQueryResult,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Part of it is documentation/examples. We couldn’t find any of either for updating queries with new values. Attempting to follow the react-query paradigms lead us to trying to write reactive queries like
$: query = useMyQuery(changingValue)
, which sort of worked but ended up causing a lot of other issues. We only stumbled up onsetOptions
/updateOptions
after some lucky search terms lead us to #43.Additionally we were having a lot of issues that seem to stem from #89/#91, but it doesn’t seem like anyone is looking at issues/PRs?
In general though, the svelte-query way of doing things involves us duplicating a lot of configuration at both the
useQuery
andsetOptions
/updateOptions
case. We created a bunch of query functions that hide away the implementation details of the query building, e.g.In an ideal world, we’d just have something like
$: query = useRoomQuery(site, building, floor, room)
and it’d just fetch/select/etc. as needed when the variables change. This even sort of works, but it sounds like it’s not supposed to be used this way? https://github.com/SvelteStack/svelte-query/issues/43#issuecomment-894770920Instead, we need to duplicate the query key logic and select function in
.updateOptions()
, like:I’m pretty sure you’re using this incorrectly and your fetch is only happening because
refetchOnWindowFocus
defaults totrue
.You change your
queryParams.page
, butconst queryResult = useQuery()
is not reactive so it only runs when the component is initialized and isn’t going to be re-run when parameters change. It seems the only reason yours is working is becausefetchPassengers
accessesqueryParams.page
directly and doesn’t parse it from the query parameters given touseQuery()
.