Newer Version Available
Best Practices for Using GraphQL in LWC Offline
In addition to the general best practices detailed in GraphQL Wire Adapter Best Practices, we want to call your attention to two specific practices that are especially important for the Offline GraphQL implementation.
Provide Query and Variables via Getter Function
To make the results of a GraphQL query primable, you must use a specific structure in your code. This structure is specifically required for the GQL query to be discovered and processed by the static analyzer used by the priming subsystem. Do not inline the query with your wire adapter function definition.
For example, this code results in a query that can be analyzed and primed:
In contrast, this example behaves the same as the preceding code, as long as you’re online, but does not result in the wire adapter results being primed. If the required data and metadata isn’t primed by some other mechanism, it won’t function while you’re offline.
Delay Query Execution
This best practice is closely related to using getters to provide the GQL query string and variables, and uses the same code structures. It’s similarly essential to maximizing the completeness of priming activities performed by the mobile app prior to going offline. The details are described in Delay Query Execution in the GraphQL API Developer Guide.