Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • 10 Salesforce Chrome Extensions to Boost Your Productivity
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Saturday, June 14
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Salesforce»Apex»Exploring GraphQL API in Salesforce

    Exploring GraphQL API in Salesforce

    Dhanik Lal SahniBy Dhanik Lal SahniJuly 25, 2023Updated:January 15, 2025No Comments5 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    GraphQL API in Salesforce
    Share
    Facebook Twitter LinkedIn Pinterest Email

    GraphQL is a query language for fetching required data using API. It allows clients to request precisely the data they need from the server, making it more efficient and flexible compared to traditional REST APIs. It was developed by Facebook in 2012 and later open-sourced in 2015. GraphQL provides a more efficient, powerful, and flexible alternative to traditional RESTful APIs. This post will explain GraphQL API, its benefits and will also test this API using a GraphQL client.

    GraphQL is a language for querying data from a number of different sources. It is not like SQL which queries data from one particular type of data source.

    Types of Operations in GraphQL

    Clients can perform mainly three types of operations: queries, mutations, and subscriptions. Each type has a distinct purpose and enables clients to interact with the GraphQL API in different ways.

    1. Query

    A query is used to fetch data from the GraphQL API. This is equivalent to REST’s GET calls. Clients can specify the exact data they need and its structure using a query language syntax. The query is submitted to the server, which processes it and provides the desired data in the exact form that the client requested. Queries are run synchronously, which means that the server processes the request and immediately sends the response.

    In below code example, all records are returned from the account object. Only the Id and Name fields will return as specified in the API call.

    2. Mutation

    A mutation is used to change or add data to the server, similar to REST’s POST, PUT or DELETE methods. Salesforce is not supporting mutation right now.

    In the below example, a new user creation request is sent and the server returns generated user-id after user creation.

    3. Subscription

    A subscription is used to get real-time server updates. Clients can subscribe to certain events and receive data when those events occur on the server. Subscriptions are frequently used to create features such as real-time messaging, live notifications, or any scenario in which clients must be notified of changes as they occur. This is also not supported yet in Salesforce.

    The following is an example of client code required to subscribe to the addedPost mutation

    Benefits of using GraphQL

    GraphQL provides a number of advantages to developers, customers, and API providers, making it a popular choice for modern online and mobile apps. Here are some of the main benefits of utilising GraphQL:

    Efficient Data Retrieval:

    GraphQL allows clients to request only the information they require. This addresses frequent REST API over-fetching and under-fetching difficulties, resulting in more efficient data retrieval and lower network traffic.

    Single Request, Multiple Resources

    Clients can use GraphQL to request data from numerous resources in a single query. This minimises the number of round trips between the client and server, resulting in improved speed and lower latency.

    Flexible Data Queries

    Clients are free to tailor their data queries to their individual requirements. They can request nested data, related items, and even numerous searches in a single request, giving them more flexibility and reducing the need for additional API calls.

    Strong Typing and Validation

    GraphQL schemas are strongly typed, which means that the types and fields are explicitly stated. This aids in the detection of problems early in the development process and improves validation and auto-completion assistance in IDEs.

    Security and Performance

    GraphQL enables fine-grained control over data access because clients can only request fields and data that they are authorised to view. This can improve security and lower the chance of data leakage.

    GraphQL API testing using Postman and Altair GraphQL Client

    GraphQL API is generally available in Winter23. It can be consumed in Apex and LWC for retrieving different objects’ data. Let us see how we can test GraphQL using Postman and Altair GraphQL Client.

    Steps for testing GraphQL

    • Create a Salesforce Connected App
    • Create a Salesforce User
    • Setup Postman to generate authentication Token
    • Use Altair GraphQL client to excute GraphQL query

    Get an Authentication Token for GraphQL API

    As mentioned above GraphQL API is secure and retrieves data based on user access. We need one Salesforce User and Connected App to test GraphQL API. Refer to our post Generate Salesforce Authentication Token using Postman to generate authentication token using Postman. Steps 1-3 are covered in this mentioned post.

    Salesforce Authentication Token from Postman

    We will need generated instance_url and access_token in below step.

    Use Altair GraphQL client to excute GraphQL query

    We need to download and install the Altair GraphQL client from its website. Once installation is complete we can use it for GraphQL API testing. This client needed an authentication token to execute the GraphQL query.

    Set the authentication token, generated from Postman from the above step, to Altair GraphQL client headers.

    Authentication Header -  GraphQL API Client

    This will set a access_token in the header and will be sent to the server on every request for secure access of API.

    Now we can run GraphQL query in this client. Currently, we can only use the POST method for query execution.

    URL : instance URL generated from Postman + /services/data/v57.0/graphql

    Query:

    You can use below query or your own query to test the GraphQL API.

    Based on the above query, it will return account records.

    GraphQL API Query Result

    References:

    GraphQL API (Generally Available)

    What is GraphQL API?

    Other Related Posts

    Displaying Tabular Data with GraphQL in Lightning Web Component

    GraphQL Query Generator in Salesforce Apex

    Other Useful Posts

    Generate Salesforce Authentication Token using Postman

    Low Code Integration for Text Translation using Systran API

    Extract Demographic Detail using Trestle Reverse Phone API

     Extract Driver License Detail from Image using Einstein API

    Verify Phone in Salesforce using VeriPhone API

    Named Entity Recognition using Salesforce Einstein API

    AWS Signature 4 Signing in Salesforce

    Altair GraphQL client apex authentication token using postman GraphQL API benefits graphql benefits integration mutation in graphql Query in graphQL API rest api salesforce salesforce apex Salesforce GraphQL Salesforce GraphQL API Subscription in GraphQL API
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleText translation in Salesforce Using Apex
    Next Article Integrate Slack in Salesforce for Real-Time Notifications
    Dhanik Lal Sahni
    • Website
    • Facebook
    • X (Twitter)

    With over 18 years of experience in web-based application development, I specialize in Salesforce technology and its ecosystem. My journey has equipped me with expertise in a diverse range of technologies including .NET, .NET Core, MS Dynamics CRM, Azure, Oracle, and SQL Server. I am dedicated to staying at the forefront of technological advancements and continuously researching new developments in the Salesforce realm. My focus remains on leveraging technology to create innovative solutions that drive business success.

    Related Posts

    By Dhanik Lal Sahni9 Mins Read

    10 Salesforce Chrome Extensions to Boost Your Productivity

    June 1, 2025
    By Dhanik Lal Sahni4 Mins Read

    How to Build a Generic Modal Window in Lightning Web Component

    May 26, 2025
    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • 10 Salesforce Chrome Extensions to Boost Your Productivity
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • Top 20 Salesforce Data Cloud Interview Questions & Answers for Admins June 5, 2025
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code analysis (3) code optimization (8) custom metadata types (5) design principle (9) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (65) lightning-combobox (5) lightning-datatable (10) lightning component (31) Lightning web component (63) lwc (52) named credential (8) news (4) optimize apex code (4) optimize apex trigger (3) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (142) salesforce apex (47) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.