Salesforce Developers, we have an exciting product announcement for you! The GraphQL Wire Adapter GA version is fresh out of the oven and ready for the Winter ’24 release. You may recall our launch of the GraphQL Wire Adapter Beta version a few months ago, well, this is its bigger, more mature sibling.

Wondering why we took on this project in the first place? It’s because we listened to you! A top request from our developer community has been the ability to query from LWCs natively. Now, not only can you do it, but you can do it with flair using query expressions that rival the richness of SOQL.

The GA release of the GraphQL Wire Adapter promises to make data management in LWCs not just possible, but a breeze. And guess what? Aggregate functions have joined the party. Coupled with updated LWC Recipes and a Best Practices Guide, the development landscape just got a whole lot greener. You don’t have to do anything to enable the adapter. All you have to do is make sure your org has the latest Salesforce build, import the GraphQL module into your component, and you’re all set.

Our solution comes with all the common functionality that you would expect in a GraphQL client:

  • Filtering, sorting, pagination? Check.
  • Fragments, aliasing, parent-child relationships? Double check.
  • Client-side caching? Courtesy of the Lightning Data Service.

Our GraphQL adapter interfaces seamlessly with the Salesforce GraphQL API, ensuring that your standard and custom objects (and a bit more) are at your fingertips, all while respecting user permissions during query execution.

GA Release Highlights

  1. Aggregate functions: Dive deeper into your data with functions like sum, count, and avg
  2. Updated LWC Recipes: Fresh examples that bring GraphQL scenarios to life
  3. Best Practices Guide: Maximize GraphQL’s potential in your LWC ventures

Next, let’s take a look at these in detail.

Aggregate functions

Aggregate functions, often termed as aggregate queries, enable you to extract meaningful insights from your query results. These functions, such as average, maximum, minimum, and sum, can be applied over specified fields.

For instance, if you wish to determine the average amount and the total sum of all opportunities, you can use the avg and sum functions as in the following query.

You can also group your results based on the values of a specific record field. For instance, opportunities can be grouped by their campaign ID.

Additionally, you can merge aggregate functions with grouping. For instance, you can determine the average amount of opportunities for each campaign.

Updated LWC Recipes

Our public GitHub repository, LWC Recipes, is more than just a collection of sample components — it’s a treasure trove. With GraphQL code additions, you can effortlessly bootstrap your next Salesforce app.

Follow the instructions to clone the repository to your local machine and deploy the app to your org. The source code can be imported into your Visual Studio Code as a project that you can customize to your needs.

Once you deploy the LWC Recipes app to your Salesforce org, you may see the following components that use GraphQL for data access.

LWC Recipes app deployed to a Salesforce org

Overview of LWC components using the GraphQL adapter:

  • graphqlAggregates: Shows aggregate information about accounts, such as account count, revenue ranges, and employee count ranges per account
  • graphqlContacts: Retrieves contacts based on criteria, sorted by name, showing the first five records
  • graphqlMultipleObjects: Grabs accounts and contacts in one query
  • graphqlPagination: Paginates through a contact list
  • graphqlRefresh: Shows an account’s employee count and refreshes on click
  • graphqlVariables: Takes user input from a search bar and fetches contacts with matching names

Variables are essential in GraphQL queries as they allow dynamic arguments. For instance, in the graphqlVariables component, users can input keywords in a search bar. This input, passed as the $searchKey variable, fetches contacts with names matching the input.

With variables, your queries become reactive, updating only with changed variable values. This enhances performance by informing the framework to skip parsing and revalidating unchanged queries.

Below is a screenshot of the LWC Recipes project in Visual Studio Code, showcasing variables code.

LWC Recipes project in Visual Studio Code

Best Practices Guide

There’s a method to the magic of GraphQL, and our guide is your compass. Navigate through the world of LWC development, armed with these best practices to get the most out of GraphQL.

In this guide, we outline when to use GraphQL and the alternative methods for accessing your CRM data. You’ll discover the most efficient querying techniques to retrieve the precise data you require. Additionally, we offer insights on delaying query execution, sending multiple queries in a single operation, and managing parent-child relationships. We hope these insights expedite your development process.

Catch the Dreamforce 2023 action

We had a blast presenting our GraphQL solution at the biggest technology event of the year, Dreamforce 2023. Did you miss our live session? No worries! Watch the session recording on demand.

A scene from the Dreamforce session recording

A scene from the Dreamforce session recording

Developer resources

Here are some resources to help you learn more about our solution and get started.

We would love for you to try out the GraphQL adapter! Please share your feedback and tips in the Trailblazer community group.

About the author

Suvda Myagmar is a Director of Product Management at Salesforce who’s passionate about data and AI platforms. On the side, she’s mastering the art of wilderness camping without sacrificing her zzz’s.

Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS