refreshGraphQL(result) (Deprecated)

The lightning/uiGraphQLApi module is deprecated. Use the lightning/graphql module instead. The deprecated module continues to work. However, newer features, such as optional fields and dynamic query construction, require the lightning/graphql module.

Note

Triggers a query to re-run. This function updates the data provisioned by the GraphQL wire adapter imperatively.

refreshGraphql() enables you to control when you want the query to re-run, such as in response to a button click or via JavaScript. Call this function to send a GraphQL query request again to the server and update the client-side stored result set.

Syntax 

1import { LightningElement, api, wire } from "lwc";
2import { gql, graphql, refreshGraphQL } from "lightning/uiGraphQLApi";
3
4export default class MyGQLQuery extends LightningElement {
5  @wire(graphql, {
6    query: gql`
7            query [your_graphql_query]`,
8  })
9  graphqlQueryResult(result) {
10    this.graphqlData = result; // Store the result so refreshGraphql() can refresh it later
11  }
12
13  // Trigger this function via a refresh button on the UI, or via javascript
14  @api
15  async refresh() {
16    return refreshGraphQL(this.graphqlData);
17  }
18}

See the GraphQL query syntax.

The lwc-recipes repo has many GraphQL API examples. Look for components that start with graphql, such as graphqlRefresh.

Tip

Returns 

A Promise object. The Promise isn’t resolved until the wire has received the latest data. The wire function might not be invoked again if the data that’s returned from the server hasn’t changed. Instead, wait for the Promise to resolve if you need to know when the refresh has completed. The actual value to which the Promise resolves is meaningless.

Usage Considerations 

Don’t use refreshGraphQL() in a polling pattern with setTimeout() or setInterval(). Polling creates unnecessary server load and can degrade performance. Instead, refresh the data once after a mutating operation completes. If you can’t determine when a mutation finishes, provide an explicit user-driven refresh action, such as a refresh button, rather than polling automatically.

See Also