question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refetch query with new variables at runtime

See original GitHub issue

Hey @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:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:15 (13 by maintainers)

github_iconTop GitHub Comments

16reactions
gauravtiwaricommented, Apr 20, 2016

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.

variables: {
  first: 20,
}

Later for refetching:

this.refetch({
  variables: {first: 40, page: 2}
});
5reactions
stubailocommented, Apr 20, 2016

However since we already have the refetch helper method, it would be pretty simple to have that take in a new set of variables.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found