GraphQL wire adapter

 


GraphQL wire adapter

In this topic, we will get to know about how to use GraphQL wire adapter to get data.

With the help of GraphQL we can extract data from org without writing single line of code in Apex.

When working with a large number of records, the wire adapter’s pagination functionality can also help you present your data with ease and efficiency.

Feature

  • Send multiple queries in one operation
  • Request record data for multiple objects
  • Query records with parent and child relationships
  • Filter by criteria and order query results
  • Work with dynamic record IDs

To work with GraphQL, first we need to import two module function gql and graphql from ‘lightning/uiGraphQLApi’.

import { gql, graphql} from 'lightning/uiGraphQLApi';

Syntax ⬇️

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

export default class MyGQLQuery extends LightningElement {
@wire(graphql, {
query: gql`
query AccountInfo {
uiapi {
query {
Account(where: { Name: { like: "Account1" } }) {
edges {
node {
Name {
value
displayValue
}
}
}
}
}
}
}
}`,
})
propertyOrFunction;
}


Things you can do with GraphQL wire adapter

  1. You can aggregate (sum, min, max etc) your result — See here
  2. Make your variable reactive with $ sign — See here
  3. Query multiple Objects — See here
  4. Pagination your result — See here
  5. Display data using base component — See here 


Demonstration

In this demonstration, I am fetching Account object record whose Rating = ’Hot’, see image below ⬇️.

Output



Follow me on linkedIn and Twitter for such more related post

Comments