experience-lds-graphql-generate
forcedotcom/sf-skills
Generate schema-validated Salesforce LDS GraphQL queries and wire them into Lightning Web Components.
What is experience-lds-graphql-generate?
This skill handles the complete GraphQL workflow for Salesforce LDS: introspect your org's schema, construct validated queries or mutations, and integrate them into LWCs via lightning/graphql adapters. Use it whenever a prompt mentions GraphQL, @wire(graphql), or gql template tags in an LWC context.
- Introspect org's LDS GraphQL schema (uiapi or setup namespace) without exposing it to chat
- Identify entities and fields from schema, respecting polymorphic and reference relationships
- Generate schema-validated read queries and mutations with filters, ordering, and pagination
- Wire queries into LWCs using lightning/graphql adapters and gql tagged templates
- Validate generated queries end-to-end against a connected org
- Generate complete .html and .js LWC scaffolding when output format is LWC integration
How to install experience-lds-graphql-generate
npx skills add https://github.com/forcedotcom/sf-skills --skill experience-lds-graphql-generate- Connected Salesforce org (username or alias) with schema introspection access
- Salesforce CLI (sf) version ≥2.0.0
- Python 3 ≥3.8 (for schema processing)
- Decision on namespace (uiapi for standard/custom objects, setup for setup objects)
- Decision on query type (read or mutation) and output format (standalone or LWC integration)
How to use experience-lds-graphql-generate
- 1.Confirm query type (read or mutation), namespace (uiapi or setup), and output format (standalone or LWC integration)
- 2.Provide your org's username or alias for schema introspection
- 3.Run the schema fetch script to introspect your org's LDS GraphQL schema into schema.graphql
- 4.Identify the entities and fields you need from the schema using targeted grep queries
- 5.Iteratively introspect entity fields, references, and child relationships (max 3 cycles)
- 6.Generate the GraphQL query or mutation using the schema introspection data
- 7.If LWC integration format: generate complete .html and .js component with wire adapter and gql template
- 8.Validate the query end-to-end against your connected org using the test script
Use cases
- Build an LWC that lists Accounts with filtering and pagination via GraphQL
- Create a GraphQL mutation to update Contact records from an LWC form
- Introspect a custom object schema and generate a read query with related-record inline fragments
- Validate a generated query against your org before deploying the LWC
- Generate a standalone GraphQL query for setup objects (e.g., permission sets) in the setup namespace
- Salesforce developers building LWCs that consume LDS data via GraphQL
- Teams migrating from REST UI API wire adapters to GraphQL
- Developers working with custom objects and polymorphic relationships in GraphQL
experience-lds-graphql-generate FAQ
Use this skill whenever the prompt mentions GraphQL, @wire(graphql), or gql template tags. experience-lwc-generate has no GraphQL schema introspection and defaults to getRecord/getRelatedListRecords, which won't satisfy GraphQL requirements.
The skill handles polymorphic fields and relationships through iterative introspection (up to 3 cycles). Use inline fragments (`... on TypeA`, `... on TypeB`) in the generated query to select type-specific fields.
No. This skill is LDS-scoped only. For REST UI API, use experience-lds-best-practices-apply. For Apex callouts or custom endpoints, use a different approach.
The schema is fetched into schema.graphql (265,000+ lines) and never enters chat context. The skill uses targeted grep queries to extract only the entities and fields you need.
The skill hard-stops at Step 2 and asks you to resolve org access issues. Once resolved, retry the schema fetch. You can force a re-fetch by setting LDS_FETCH_FORCE=1.
Full instructions (SKILL.md)
Source of truth, from forcedotcom/sf-skills.
name: experience-lds-graphql-generate description: "Use ALWAYS when a prompt mentions GraphQL, lightning/uiGraphQLApi, @wire(graphql, ...), or gql template tags in an LWC context — even if the surface ask is "build an LWC". Owns the ENTIRE flow: introspect the org's LDS GraphQL schema, identify entities/fields, construct the schema-validated gql query or mutation, wire it into the LWC via lightning/uiGraphQLApi, verify against a connected org. REQUIRED whenever a prompt asks to render, list, or edit Salesforce records (Account, Contact, Case, custom objects) via GraphQL — the .html and .js scaffolding IS in scope. DO NOT delegate to experience-lwc-generate: that skill has NO GraphQL schema introspection, NO create_lds_graphql_read_query binding, and defaults to getRecord/getRelatedListRecords wire adapters which will not satisfy a GraphQL prompt. DO NOT TRIGGER only if the prompt forbids GraphQL, chooses UIAPI/Apex (use experience-lds-best-practices-apply), or asks for data requirements (use experience-lds-data-requirements-generate)." metadata: relatedSkills: - "experience-lds-best-practices-apply" - "experience-lds-data-requirements-generate" - "experience-lwc-generate" version: "1.0" domains: ["Experience", "Platform"] cliTools: - tool: ["python3"] semver: ">=3.8" - tool: ["sf"] semver: ">=2.0.0"
<!-- adk-managed-skill -->Building LDS GraphQL
Generate schema-validated Salesforce LDS GraphQL queries (read or mutation), either as standalone queries or wired into a Lightning Web Component via the lightning/graphql adapters. The skill encodes the schema-as-source-of-truth workflow end-to-end. Two bundled bash scripts handle the org-aware steps — scripts/fetch-lds-graphql-schema.sh for schema introspection and scripts/test-lds-graphql-query.sh for live-org validation.
When to Use
- User wants to create, modify, or integrate a Salesforce GraphQL query (standard objects, custom objects, or setup objects).
- Building or updating an LWC that consumes/mutates LDS data through GraphQL.
- Introspecting an org's schema before writing a query.
- Validating a generated query end-to-end against a connected org.
Do NOT use this skill for:
- REST-based UI API (use LDS wire adapters; see
experience-lds-best-practices-apply). - Apex callouts or custom GraphQL endpoints — this skill is LDS-scoped.
- Data-requirements discovery — that's
experience-lds-data-requirements-generate.
Prerequisites
- A connected Salesforce org (username or alias). User must confirm it before schema fetch — never assume.
- Salesforce CLI /
sfavailable in the shell for the schema fetch. - Decision on:
- Namespace —
uiapi(default: standard + custom objects) orsetup(setup objects like permission sets, profiles). - Query type —
read(default) ormutation. - Output format —
standalone(raw GraphQL + variables) orLWC integration(full component wiring).
- Namespace —
Core Rules
These apply to every step — they are the rules this skill enforces:
- Sequential execution — Steps 1→6 run in order. Every step is mandatory unless its triggering conditions are not met.
- Hard stop on failure — A failed step blocks subsequent steps until remediation is complete.
- Schema is the single source of truth — Every entity name, field name, field type, and relationship must come from
schema.graphqlintrospection. Never use common Salesforce knowledge (e.g., do not assumeOwneris aUser— it may be polymorphic). - Report each step — Use the provided templates before advancing.
- Error reporting — Categorize errors; never echo raw tool output into the chat.
Workflow
The full normative workflow lives in references/generation-guide.md. Read it before starting. Read-query specifics are in references/generation-query.md; mutation specifics are in references/generation-mutation.md.
Step 1 — General query information
Collect and echo back:
Query type: [read | mutation]
Namespace: [uiapi | setup]
Output format: [standalone | LWC integration]
If any is unclear, ask once and wait.
Step 2 — Acquire the schema
- Ask for the
usernameOrAlias. If a default is inferred from context, present it and wait for explicit confirmation. - Run
scripts/fetch-lds-graphql-schema.sh USERNAME_OR_ALIAS [OUTPUT_PATH] [API_VERSION]with the confirmed alias. The script writes the SDL toschema.graphql(or the path you pass) so the schema never enters the chat context. If a non-emptyschema.graphqlalready exists atOUTPUT_PATH, the script exits early (setLDS_FETCH_FORCE=1to re-fetch). - On failure: hard stop, report category, ask user to resolve org access, then retry.
Using the schema file
The schema is 265,000+ lines. NEVER read the whole file — use targeted grep calls only.
- Object type:
^type <ObjectName> implements Recordwith-A 100. - Filter:
^input <ObjectName>_Filterwith-A 50. - OrderBy:
^input <ObjectName>_OrderBywith-A 30. - Mutation input:
^input <ObjectName>(Create|Update)Inputwith-A 50.
Search budget: max 4–5 grep calls per entity. Plan before executing.
Step 3 — Entity identification
- Entity names are PascalCase.
- If names aren't given, extract candidates from
^type <Name> implements Recordmatches. - If any entity is still unresolved, ask the user and wait.
- Report:
Identified entities: - EntityName (Field1, Field2, ...) Unknown entities: - <textual name> Step 3 status: SUCCESS | FAILED - If
Unknown entitiesis non-empty → statusFAILED→ ask for clarification → restart Step 3.
Step 4 — Iterative entity introspection
Iteration limit: 3 cycles (primary entity → references → child relationships). Hard-stop after 3.
Per cycle:
- Remove already-introspected entities from the list.
- Grep for the remaining entities' fields using the schema patterns above.
- Extract standard field types.
- Identify reference fields (
Owner: User). Fields with the same name on different entities may have different types — check each entity independently. If a field resolves to multiple entity types, mark it polymorphic and plan to use inline fragments (... on TypeA,... on TypeB). - Identify child relationships (Connection types, e.g.,
Contacts: ContactConnection). Add new entities to the unknown list. - If unknown list not empty and iterations < 3, loop.
- Report:
[PASS|FAIL] EntityName - Standard fields: FieldName (type), ... - Reference fields: FieldName → TargetType, ... - Polymorphic fields: FieldName → [TypeA, TypeB], ... - Child relationships: RelationshipName → ChildType, ... - Unknown fields: FieldName, ... Introspection cycles used: N/3 Step 4 status: SUCCESS | FAILED - If any entity is
[FAIL]→ globalFAILED→ remediation → resume from cycle start.
Step 5 — Read query generation (only if query type is read)
Author the read query per references/generation-query.md, feeding in the introspection data, entity list, field types, output format, and usernameOrAlias.
Apply the rules in references/generation-query.md — covers:
- Query root / namespace selection (
uiapi.queryvssetup.query). - Field selection discipline (ask only for fields actually needed — every field is a billable scan).
- Filter operators (
eq,ne,in,nin,gt,gte,lt,lte,like,contains). - OrderBy (per-field direction).
- Pagination (
first,after,last,before;edges.node,pageInfo). - Polymorphic inline fragments.
- Aliasing and variable placeholders.
- Standalone vs LWC output (wire adapter from
lightning/graphql,gqltagged template,refreshGraphQLfor imperative refresh).
If the tool returns an error, categorize it and ask the user how to proceed.
Step 6 — Mutation query generation (only if query type is mutation)
Author the mutation per references/generation-mutation.md — covers:
create,update,deleteoperation shape.- Input types (
<Entity>CreateInput,<Entity>UpdateInput) discovered via theinputgrep pattern. - Required vs optional fields (from schema's
!annotation). - Reference-field updates using
Idonly. - Return selection — what to read back after the mutation to drive cache consistency.
- Error handling (
record.errors[]). - LWC integration: imperative mutation via
graphqlMutatefromlightning/graphql.
Step 7 — Test the query
Run scripts/test-lds-graphql-query.sh USERNAME_OR_ALIAS 'QUERY' '<VARIABLES_JSON>' against the confirmed usernameOrAlias and present the response shape/sample to the user. Errors are categorized, not echoed verbatim.
Cross-References
- Bundled scripts:
scripts/fetch-lds-graphql-schema.sh— schema acquisition via a GraphQL introspection query against the org's/services/data/vX/graphqlendpoint (LDS exposes no/graphql/sdlroute); call once per org/session before query authoring.scripts/test-lds-graphql-query.sh— org-backed validation of the generated query against/services/data/vX/graphql.
- Related skills:
experience-lds-best-practices-apply— general LDS principles, cache semantics, and wire-vs-imperative choice.experience-lds-data-requirements-generate— pre-work that decides what to query before this skill decides how.experience-lwc-generate— host the generated wire adapter cleanly.
Examples
Standalone read — minimal
query Accounts($limit: Int = 10) {
uiapi {
query {
Account(first: $limit) {
edges {
node {
Id
Name { value }
}
}
}
}
}
}
LWC integration — read with wire
import { LightningElement, wire } from 'lwc';
import { gql, graphql } from 'lightning/graphql';
export default class AccountList extends LightningElement {
@wire(graphql, {
query: gql`
query Accounts($limit: Int = 10) {
uiapi {
query {
Account(first: $limit) {
edges { node { Id Name { value } } }
}
}
}
}
`,
variables: '$variables'
})
accounts;
variables = { limit: 10 };
get records() {
return this.accounts?.data?.uiapi?.query?.Account?.edges ?? [];
}
}
Verification
Step 3 status: SUCCESSbefore Step 4;Step 4 status: SUCCESSbefore Steps 5/6.- Every field in the generated query appears in the introspection report (no hallucinated fields).
- Polymorphic fields use inline fragments; non-polymorphic fields do not.
- For mutations, every required input field (
!in schema) is present. scripts/test-lds-graphql-query.shreturns without errors; or, on error, a categorized remediation is presented.- If output format is
LWC integration, the component imports fromlightning/graphql, usesgqltagged template, and exposes data via a getter (not directly in HTML).
Related skills
More from forcedotcom/sf-skills and the wider catalog.

experience-lwc-base-components-integrate
Select and wire the right Lightning Base Component for any UI task using authoritative API docs.

experience-lwc-design-generate
Orchestrate end-to-end creation of Lightning Web Components from Figma designs, PRDs, or Aura sources.

experience-lwc-generate
Lightning Web Components development with PICKLES methodology and 165-point quality scoring.

experience-lwc-rtl-validate
Review Lightning Web Components for right-to-left (RTL) internationalization compliance with code-level fixes.

experience-lwc-runtime-observe
Extract runtime DOM from Salesforce Lightning Preview for local LWC component inspection.

experience-lwc-security-validate
Specialized Lightning Web Security validator for LWC components with severity-ranked findings and SARIF reporting.