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 refetch of the query results and update the cache by calling the refreshGraphQL(result) function.

When calling refreshGraphQL, you must pass the exact object that was previously passed to your wire function or variable. The wire function or variable must preserve the original value from the wire adapter and can’t use a destructuring parameter assignment.

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 stores a reference to a query result and refreshes it with refreshGraphQL.

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

If a record that's contained in the 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 reavaluates your query, use the refreshGraphQL(result) function. This example adds a button that enables you to trigger a refetch of the query results.