Rax Wunter
Rax Wunter

Reputation: 2767

Avoid caching in Relay

There is a detailed explanation in https://facebook.github.io/relay/docs/thinking-in-graphql.html article how Relays caching works.

But it doesn't described what to do if I'd like to refresh my local storage from server data with the same query. According to Relay logic it will look at the query, find it fullfilled locally and returns data from local storage.

But how to avoid caching and force Relay to send a new request to server?

Upvotes: 1

Views: 1579

Answers (1)

Ahmad Ferdous
Ahmad Ferdous

Reputation: 3399

You can have Relay send a request to refetch all data by using forceFetch API.

For example, if you have a button in your React component to refresh data and if the handler function is refreshData, call forceFetch in that function:

refreshData() {
    this.props.relay.forceFetch();
}

Upvotes: 5

Related Questions