What is the GraphQL API?

The GraphQL API is a new paradigm of sending and receiving data, offering developers a single endpoint to call for all data needed in one request. This API allows developers to interact with the Salesforce Platform through GraphQL, a standard query language for APIs and a runtime for fulfilling those queries with your data.

To learn more about GraphQL, visit graphql.org. You can also experiment with GraphQL in a galaxy far, far away with the GraphQL SWAPI.

Apps that call GraphQL APIs are often much more performant than those that use traditional REST APIs. They are able to reduce round trips to the server through retrieval of all necessary data in just a single invocation.

GraphQL is a new way to address many pain points for application developers; all GraphQL servers adhere to a specification, which features patterns that make it easier to build complex experiences across a wide variety of platforms and devices.

Salesforce GraphQL API is available in Enterprise, Performance, Unlimited, and Developer Editions. It adheres to the June 2018 version of the spec.

The following benefits are available for Salesforce developers, including:

  • Field selection
  • Resource aggregation
  • Schema introspection

The first of these patterns is field selection, which requires the client generating the GraphQL query to explicitly declare which fields they would like to receive in the response. This technique reduces the size of the payload, as the client only receives fields that were included in the query.

The second pattern is aggregation, which allows the client to specify a traversal across the fields in the GraphQL schema. Aggregations reduce round trips between the client and server, returning a set of related resources within a single response.

The final pattern is introspection, which is the ability to send a query to the GraphQL server to ask questions about the types, fields, and their relationships within the schema. When all these patterns are combined, it results in more responsive, higher-quality applications.

The GraphQL API adds even more features:

For more information on getting started with the GraphQL API, we recommend the following resources in the Salesforce Developers' Blog.