Salesforce GraphQL API Reference

Overview

Salesforce GraphQL requests are sent to a single endpoint:

The request body includes query, optional operationName, and optional variables. Responses use the standard GraphQL shape with data and errors.

Consensus Best Practices

Request Contract

Endpoint

Request Body Fields

Example Request

{
  "query": "query accountSearch($name: String!) { uiapi { query { Account(first: 10, where: { Name: { like: $name } }) { edges { node { Id Name { value } Industry { value } } } } } } }",
  "operationName": "accountSearch",
  "variables": {
    "name": "Acme%"
  }
}

Response Shape

LWC Integration

Preferred Adapter: lightning/graphql

Use lightning/graphql for most new implementations. It supports optional fields and dynamic query construction (API-version dependent).

import { LightningElement, wire } from 'lwc';
import { gql, graphql } from 'lightning/graphql';

const ACCOUNT_QUERY = gql`
  query accountSearch($name: String!) {
    uiapi {
      query {
        Account(first: 10, where: { Name: { like: $name } }) {
          edges {
            node {
              Id
              Name { value }
            }
          }
        }
      }
    }
  }
`;

export default class AccountSearch extends LightningElement {
  searchTerm = 'Acme%';

  get variables() {
    return { name: this.searchTerm };
  }

  @wire(graphql, {
    query: ACCOUNT_QUERY,
    variables: '$variables'
  })
  result;
}

lightning/uiGraphQLApi Usage

Use lightning/uiGraphQLApi only when Mobile Offline compatibility is required. Salesforce recommends lightning/graphql for general use.

Design Notes

GraphQL vs REST/Composite

Versioning

Common Failure Modes

Q&A

Q: What is the Salesforce GraphQL endpoint?

A: Use POST /services/data/vXX.X/graphql, where vXX.X is your target API version.

Q: What fields are required in a GraphQL request body?

A: query is required. operationName is needed when multiple operations exist in one document. variables should hold runtime parameters.

Q: How should I pass dynamic values safely?

A: Use GraphQL variables (variables map) and keep the query text static.

Q: Which LWC GraphQL adapter should I choose?

A: Use lightning/graphql by default. Use lightning/uiGraphQLApi only when Mobile Offline support is required.

Q: Does Salesforce GraphQL support mutations?

A: Salesforce documentation states mutation support is available from newer API versions; validate exact behavior against your org and release version before production rollout.

Sources Used