
GraphQL is used as an easy way to connect to databases and easily query the data. You can get started connecting data using the adapter for GraphQL in Salesforce using 3 steps.
- Create a Named Credential for the adapter
- Create an External Data Source for the adapter
- Synchronize the data to allow it to map to your Salesforce External Objects
We will go through each of the steps below to show you how to setup and authenticate Salesforce with GraphQL.
Creating External and Named Credentials to Store the Authentication Information
Using the Named Credentials allows for the API authentication and keys needed to be stored in a secure manner where its not visible to many of the Salesforce users.
From Setup, in the Quick Find box, enter Named Credentials, then select Named Credentials and then select External Credentials and click the New button. The options of name and label in the External Credential are up to you but be sure to select the Custom Authentication Protocol.

Additionally, you will want to store your API key from the GraphQL API you are connecting to securely. Best option is to create a Principal under the external credentials. On the External Credential you just created, create a new Principal, add any Parameter Name and then add an Authentication Parameter. Set the name to any value and set API Key in the Value for the new Principal. You can then allow access for the profiles or permission sets you created for callouts.

Next we’ll create a header to use for your callout to your GraphQL API. In the same External Credentials we created initially, look for the Custom Headers section. Be sure to set the name to the name format needed for your GraphQL HTTP callout header. For example Amazon App Sync requires the name to be in the format of x-api-key. In the Value field enter the value for the API Key. However, a better method than using the full key would be using a merge field referencing the Name Credential created earlier.
With the merge field format as: {!$Credential.NameofExternalCredential.PrincipalName}
, where NameofExternalCredential is the name of the External Credential and the Principal created earlier. This prevents security risks with the API Key being visible in clear text.

Finally we will create the Name Credential to link the endpoint to the API Key. Create a new Named Credential.

Add the Label and Name as you would like but be sure to add the endpoint url of the GraphQL in the URL field, select the External Credential you just created in the External Credential field and then allow Formulas in the HTTP Header.
Creating an External Data Source and External Objects
The External objects in Salesforce allows users to fetch the data using the GraphQL connector and view the data retrieved. The external object and Graph QL tables need to have a similar naming convention to allow for readability.
Go to setup and External Data Sources then click New External Data Source and complete the fields in the External Data Source area. The External Data Source and Name fields can be set to whatever you want. Just be sure the Type field is set to GraphQL, Named Credential to the Named Credential you created earlier and select Writable External Objects.
Validating the Data
The final step is to actuall create the External objects through the validation process. In the External Data Sources area, select the name of the external data source that you created and then click Validate and Sync. The potential external objects should be listed. Then select all the table you wish to create a external objects, and click Sync.
Cost
There is an extra cost to have the Salesforce Connect adapter included in most Salesforce editions.
Skull and Crossbones: Feature Warnings ☠️
The Salesforce Connect adapter for GraphQL requires that the GraphQL schema adhere to a specific format. And to have pagination, the GraphQL schema must include the first field of type int
and after field of type string
. See Understand GraphQL Schema Requirements and GraphQL: Pagination.

Need help finding the Salesforce gems?
Let us help! Were seasoned Salesforce treasure hunters.