Use GraphQL While Mobile and Offline

GraphQL, often shortened to GQL, is a flexible, powerful query language for accessing record and other data. You can think of GraphQL as a modern equivalent of SQL, the query language for relational databases.

Developers like GraphQL for modern web applications because, in contrast to many REST and CRUD-oriented APIs, GraphQL allows for expressive queries, with features like filtering and scopes, ordering and aggregation, pagination, and relationship traversal to related records. A single query can retrieve many records, and even records of multiple types. Using fewer queries reduces the number of server requests required to load data, which can improve performance. A GQL query can specify precisely and only the fields required for a given component, reducing the amount of data that needs to be transmitted before a page can render.

Salesforce offers several different implementations of GraphQL for use in your apps. Each implementation has an intended context and purpose, and relevant use cases. Learning to use the appropriate implementation, or when you must use a specific implementation, is straightforward. See Understand Salesforce GraphQL Implementations.

For mobile developers building apps that work while offline, however, there is only one implementation that matters: Offline GraphQL. The rest of this chapter provides details of using Offline GraphQL, including important considerations and limitations.

Getting Started

  • The fastest way to get up to speed on GraphQL and learn how to use it with the Salesforce Platform is to read the GraphQL API Developer Guide.
  • The fastest way to get up to speed on using GraphQL in Lightning web components is to read the Use the GraphQL Wire Adapter chapter of the same developer guide. You’ll also want to refer to the lightning/uiGraphQLApi Wire Adapters and Functions reference in the Lightning Web Components Developer Guide.
  • The fastest way to learn how to build offline-ready LWCs with GraphQL is to keep reading this chapter.
 

If you’re new to GraphQL, you should plan to read and absorb all of these resources, in the order listed.