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