Refetch query with new variables at runtime
See original GitHub issueHey @stubailo @jbaxleyiii
Relay provides an option in the component called setvariables to change the variables on runtime. Does apollo client support this yet? I see refetch
function, but it works like refresh button, which wouldn’t be helpful if someone wants to change the variables and then refetch the query. I think this option could be super useful for things like infinite scroll pagination or filtering - one can set the variable on runtime and fetch the updated data to update the store with new data.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:8
- Comments:15 (13 by maintainers)
Top Results From Across the Web
Queries - Apollo GraphQL Docs
This article assumes you're familiar with building basic GraphQL queries. ... You can optionally provide a new variables object to the refetch function....
Read more >refetch with different data react query - Stack Overflow
You can pass parameters to the query keys, because React Query will automatically trigger a refetch when the value in the query keys...
Read more >useQuery | TanStack Query Docs
useQuery · Optional · If set to true , queries that are set to continuously refetch with a refetchInterval will continue to refetch...
Read more >useRefetchableFragment - Relay
Calling refetch with a new set of variables will fetch the fragment again with the newly provided variables. Note that the variables you...
Read more >Manipulating Data in GraphQL Part 1 - Dynamic Variables
Dynamic variables, instead, have their values calculated at runtime, during the execution of the query. The implication is that we can ...
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 FreeTop 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
Top GitHub Comments
Hi @stubailo I did the same thing for passing variables for this demo app: https://github.com/gauravtiwari/apollo_on_rails/blob/master/app/assets/javascripts/components/posts/show.es6.js#L41, but I think to utilise
refetch()
with new variables would be much more clear and easy to use.For example:
In infinite scroll pagination, we could just change the number of new records to fetch and page offset and it would fetch the new data.Later for refetching:
However since we already have the
refetch
helper method, it would be pretty simple to have that take in a new set of variables.