Update Cached Query Results

The GraphQL wire adapter automatically caches your query results to improve the loading performance of subsequent queries. You can trigger a refresh of the query results and update the cache by calling the refresh method on the emitted data from the GraphQL wire adapter.

If you use a wire function, you can assign data and errors to a result variable like this.

The graphqlRefresh component in the lwc-recipes repo demonstrates how to refresh a query using the refresh method.

Here's an example that adds a refresh button to the example in Make Your Variables Reactive.

If a record that's contained in a query result changes, Lightning Data Service emits a new value to the GraphQL wire adapter. However, Lightning Data Service doesn't reevaluate the query to see if the record still matches the query.

To ensure that Lightning Data Service reevaluates your query, use the refresh method. This example adds a button that enables you to trigger a refresh of the query results.