1//refreshAccountsGQL.js
2import { LightningElement, wire } from "lwc";
3import { gql, graphql } from "lightning/graphql";
4
5export default class AccountsGQL extends LightningElement {
6 records;
7 errors;
8 graphqlRefresh;
9
10 minAmount = "5000000";
11
12 minAmounts = [
13 { label: "All", value: "0" },
14 { label: "$5,000,000", value: "5000000" },
15 { label: "$50,000,000", value: "50000000" },
16 { label: "$500,000,000", value: "500000000" },
17 ];
18
19 @wire(graphql, {
20 query: gql`
21 query bigAccounts($minAmount: Currency) {
22 uiapi {
23 query {
24 Account(where: { AnnualRevenue: { gte: $minAmount } }) {
25 edges {
26 node {
27 Id
28 Name {
29 value
30 }
31 AnnualRevenue {
32 displayValue
33 }
34 }
35 }
36 }
37 }
38 }
39 }
40 `,
41 variables: "$variables",
42 })
43 graphqlQueryResult({ data, errors, refresh }) {
44 if (data) {
45 this.records = data.uiapi.query.Account.edges.map((edge) => edge.node);
46 }
47 this.errors = errors;
48 // Store the refresh method to call later
49 this.graphqlRefresh = refresh;
50 }
51
52 async handleRefresh() {
53 return this.graphqlRefresh();
54 }
55
56 get variables() {
57 return {
58 minAmount: this.minAmount,
59 };
60 }
61
62 // Called when the user selects a new minimum amount
63 handleMinAmountChange(event) {
64 this.minAmount = event.detail.value;
65 }
66}