Introduction: What is GraphQL?

GraphQL is a query language and runtime developed by Facebook to address the limitations and complexities of traditional REST APIs.

One of the main advantages of GraphQL is its flexibility and efficiency.

<aside> 💡 Unlike REST, which requires multiple endpoints for different resources and often returns more data than needed, GraphQL enables clients to request precisely the data they require, and nothing more, from a single endpoint.

</aside>

Benefits

You can tailor your queries to specify the exact fields and relationships required, reducing over-fetching and under-fetching of data.

Furthermore, GraphQL promotes strong typing and introspection. With its schema definition language, both the server and client can clearly understand the data's structure and types, facilitating better communication and documentation.

In addition, GraphQL:

Current status of the GraphQL Salesforce flavor

Salesforce does not offer all the capabilities available on the GraphQL standard, but instead, limited to queries and even with some limitations.

Updating data, known as mutations and many other capabilities are not yet offered, this following table summarized the state of the art:

Feature Salesforce GraphQL GraphQL Standard
Subscriptions No Yes
Mutations Beta All objects
Scalar types Limited set Full set
Interfaces No Yes
Unions No Yes
Naming convention Different Same
Additional features Field-level security None

What does a query look like?

Queries in GraphQL language are JSON-like queries that are straightforward to understand coming from a SQL or SOQL background.

The following query retrieves all book records with the fields title, and author.


query {
  book {
    title
    author
  }
}