Overview
ThegraphqlContacts component demonstrates how to fetch Salesforce records using GraphQL with the @wire decorator. It queries Contact records with filtering, ordering, and field selection.
Source
force-app/main/default/lwc/graphqlContacts
Key Features
- GraphQL query with
@wireadapter - Field filtering using
whereclause - Ordering results with
orderBy - Field aliases for custom fields
- Data transformation in getters
GraphQL Query Syntax
Importing GraphQL
Thegql tag function and graphql adapter must be imported from lightning/graphql:
gql: Template tag for defining GraphQL queriesgraphql: Wire adapter for executing queries
Query Parameters
where
Filter records based on field criteria:first
Limit the number of records returned:orderBy
Sort results by field:Field Aliases
Use aliases for custom fields to ensure stable field names even if Salesforce updates the API name:Picture__c: ensures consistent access to the field value in your code.
