Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[YeurDreamin 2023] Bring data to your LWC witho...

[YeurDreamin 2023] Bring data to your LWC without Apex using the GraphQL Wire Adapter

Using Lightning Data Service is great in LWC, getting record data in just a few lines of code without having to write Apex, Test Class, be sure that Field Level Security is checked etc… But you quickly hit a limit, as soon as you want to get more specific data, applying filters or getting relationships, you need to go back to Apex. Not anymore! With the GraphQL Wire Adapter you’ll be able to query Salesforce data right from your LWC without writing a single line of Apex. Let’s have a look!

Fabien Taillon

June 16, 2023
Tweet

More Decks by Fabien Taillon

Other Decks in Programming

Transcript

  1. Bring data to your LWC without Apex using the GraphQL

    Wire Adapter Fabien Taillon CTO at Texeï - Salesforce MVP @FabienTaillon
  2. Fabien Taillon • Salesforce MVP Hall of Fame • CTO

    at Texeï • Paris Developer Group Leader • French Touch Dreamin team • Serial speaker @FabienTaillon https://texei.com/blog Who am I
  3. - Created by Facebook in 2012 - No need to

    call several APIs - Get many resources in a single request - Ask for what you need, get exactly that - Self documented - With a type system A query language for your API source: Michael Poirier-Ginter What is GraphQL
  4. • a read only stream of data • shared cache

    between components (standard & custom) • reactive to changes outside of the component’s scope • no Apex with standard Lightning Data Service Wire Adapters • just import it and use it 🎉 What is a Wire Adapter
  5. Query any list of records you want - Order them

    - Group them - … Easy to use because - you don’t need to write any Apex - respects user Field Level Security - use the same shared Lightning Data Service cache Get for a custom component - a list of all contacts for a given account - a search page - a hierarchy of records - one specific record with filters, without knowing its Id at first - … What is the GraphQL Wire Adapter
  6. - An easy to use local client to test your

    queries - Get an access token - for instance use sf org display - Use the following url: - https://{MyDomainName}.my.salesforce.com/services/data/v{version}/graphql - Then you can: - query - autocomplete - look at API documentation (display existing fields, available formatting etc) https://ww.altairgraphql.dev Connect to GraphQL API Altair GraphQL Client
  7. - Backward pagination - Filter with no value - Actually

    more GraphQL than Salesforce “issue” - No mutation (on the roadmap) What’s not available (yet ?)
  8. Demo source code: https://github.com/FabienTaillon/graphql-wire-adapter-demo Developer Guide: https://developer.salesforce.com/docs/platform/graphql/guide/graphql-wire-lwc.html GraphQL Wire Adapter

    for LWC Blog Post: https://developer.salesforce.com/blogs/2023/02/now-in-pilot-graphql-wire-adapter-for-lwc GraphQL API & LWC Wire Adapter Trailblazer Community Group: https://trailhead.salesforce.com/trailblazer-community/groups/0F94S000000kRExSAM Resources