@salesforce/webapp-template-feature-react-chart-experimental 1.105.0 → 1.106.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +1 -1
  2. package/{skills/analytics-charts → dist/.a4drules/skills/building-analytics-charts}/SKILL.md +1 -1
  3. package/dist/.a4drules/skills/{webapp-react-data-visualization → building-data-visualization}/SKILL.md +3 -3
  4. package/dist/.a4drules/skills/{webapp-react-data-visualization → building-data-visualization}/implementation/donut-chart.md +1 -1
  5. package/dist/.a4drules/skills/{webapp-react-interactive-map → building-interactive-map}/SKILL.md +1 -1
  6. package/dist/.a4drules/skills/{webapp-react → building-react-components}/SKILL.md +1 -1
  7. package/dist/.a4drules/skills/{webapp-react-weather-widget → building-weather-widget}/SKILL.md +2 -2
  8. package/dist/.a4drules/skills/{webapp-csp-trusted-sites → configuring-csp-trusted-sites}/SKILL.md +1 -1
  9. package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/SKILL.md +14 -14
  10. package/dist/.a4drules/skills/{feature-micro-frontend-micro-frontend → generating-micro-frontend-lwc}/SKILL.md +1 -1
  11. package/dist/.a4drules/skills/{feature-react-file-upload-file-upload → implementing-file-upload}/SKILL.md +1 -1
  12. package/dist/.a4drules/skills/{webapp-features → installing-webapp-features}/SKILL.md +1 -1
  13. package/dist/.a4drules/skills/{feature-react-agentforce-conversation-client-embedded-agent → integrating-agentforce-conversation-client}/SKILL.md +1 -1
  14. package/dist/.a4drules/skills/{webapp-unsplash-images → integrating-unsplash-images}/SKILL.md +1 -1
  15. package/dist/.a4drules/skills/salesforce-data-access/SKILL.md +165 -0
  16. package/dist/.a4drules/skills/salesforce-graphql/SKILL.md +323 -0
  17. package/dist/.a4drules/skills/salesforce-graphql-explore-schema/SKILL.md +160 -0
  18. package/dist/.a4drules/skills/{feature-graphql-graphql-data-access/docs/generate-mutation-query.md → salesforce-graphql-mutation-query/SKILL.md} +72 -42
  19. package/dist/.a4drules/skills/salesforce-graphql-read-query/SKILL.md +253 -0
  20. package/dist/.a4drules/skills/salesforce-rest-api-fetch/SKILL.md +167 -0
  21. package/dist/.a4drules/webapp-react.md +2 -50
  22. package/dist/AGENT.md +5 -0
  23. package/dist/CHANGELOG.md +19 -0
  24. package/dist/force-app/main/default/webapplications/feature-react-chart/eslint.config.js +42 -27
  25. package/dist/package.json +1 -1
  26. package/package.json +2 -2
  27. package/{dist/.a4drules/skills/feature-react-chart-analytics-charts → skills/building-analytics-charts}/SKILL.md +1 -1
  28. package/dist/.a4drules/features/feature-graphql-graphql-data-access-rule.md +0 -470
  29. package/dist/.a4drules/skills/feature-graphql-graphql-data-access/SKILL.md +0 -155
  30. package/dist/.a4drules/skills/feature-graphql-graphql-data-access/docs/explore-schema.md +0 -256
  31. package/dist/.a4drules/skills/feature-graphql-graphql-data-access/docs/generate-read-query.md +0 -202
  32. /package/dist/.a4drules/skills/{feature-react-chart-analytics-charts → building-analytics-charts}/docs/schema-mapping.md +0 -0
  33. /package/dist/.a4drules/skills/{webapp-react-data-visualization → building-data-visualization}/implementation/dashboard-layout.md +0 -0
  34. /package/dist/.a4drules/skills/{webapp-react-data-visualization → building-data-visualization}/implementation/stat-card.md +0 -0
  35. /package/dist/.a4drules/skills/{webapp-react-interactive-map → building-interactive-map}/implementation/geocoding.md +0 -0
  36. /package/dist/.a4drules/skills/{webapp-react-interactive-map → building-interactive-map}/implementation/leaflet-map.md +0 -0
  37. /package/dist/.a4drules/skills/{webapp-react → building-react-components}/implementation/component.md +0 -0
  38. /package/dist/.a4drules/skills/{webapp-react → building-react-components}/implementation/header-footer.md +0 -0
  39. /package/dist/.a4drules/skills/{webapp-react → building-react-components}/implementation/page.md +0 -0
  40. /package/dist/.a4drules/skills/{webapp-react-weather-widget → building-weather-widget}/implementation/weather-hook.md +0 -0
  41. /package/dist/.a4drules/skills/{webapp-react-weather-widget → building-weather-widget}/implementation/weather-ui.md +0 -0
  42. /package/dist/.a4drules/skills/{webapp-csp-trusted-sites → configuring-csp-trusted-sites}/implementation/metadata-format.md +0 -0
  43. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/data/charts.csv +0 -0
  44. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/data/colors.csv +0 -0
  45. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/data/icons.csv +0 -0
  46. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/data/landing.csv +0 -0
  47. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/data/products.csv +0 -0
  48. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/data/react-performance.csv +0 -0
  49. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/data/stacks/html-tailwind.csv +0 -0
  50. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/data/stacks/react.csv +0 -0
  51. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/data/stacks/shadcn.csv +0 -0
  52. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/data/styles.csv +0 -0
  53. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/data/typography.csv +0 -0
  54. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/data/ui-reasoning.csv +0 -0
  55. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/data/ux-guidelines.csv +0 -0
  56. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/data/web-interface.csv +0 -0
  57. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/scripts/core.js +0 -0
  58. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/scripts/design_system.js +0 -0
  59. /package/dist/.a4drules/skills/{webapp-ui-ux → designing-webapp-ui-ux}/scripts/search.js +0 -0
  60. /package/dist/.a4drules/skills/{feature-react-agentforce-conversation-client-embedded-agent → integrating-agentforce-conversation-client}/docs/embed-examples.md +0 -0
  61. /package/dist/.a4drules/skills/{feature-react-agentforce-conversation-client-embedded-agent → integrating-agentforce-conversation-client}/docs/troubleshooting.md +0 -0
  62. /package/dist/.a4drules/skills/{webapp-unsplash-images → integrating-unsplash-images}/implementation/usage.md +0 -0
  63. /package/dist/.a4drules/skills/{feature-graphql-graphql-data-access/docs → salesforce-graphql}/shared-schema.graphqls +0 -0
  64. /package/skills/{analytics-charts → building-analytics-charts}/docs/schema-mapping.md +0 -0
@@ -0,0 +1,323 @@
1
+ ---
2
+ name: salesforce-graphql
3
+ description: Salesforce GraphQL data access. Use when the user asks to fetch, query, or mutate Salesforce data, or add a GraphQL operation for an object like Account, Contact, or Opportunity.
4
+ paths:
5
+ - "**/*.ts"
6
+ - "**/*.tsx"
7
+ - "**/*.graphql"
8
+ ---
9
+
10
+ # Salesforce GraphQL
11
+
12
+ Guidance for querying and mutating Salesforce data via the Salesforce GraphQL API. Use `createDataSDK()` + `sdk.graphql?.()` and codegen tooling.
13
+
14
+ ## When to Use
15
+
16
+ - User asks to "fetch data from Salesforce"
17
+ - User asks to "query" or "mutate" Salesforce records
18
+ - User wants to add a new GraphQL operation (query or mutation)
19
+ - User asks to add data access for a Salesforce object (Account, Contact, Opportunity, etc.)
20
+
21
+ ## Schema Access Policy (GREP ONLY)
22
+
23
+ > **GREP ONLY** — The `schema.graphql` file is very large (~265,000+ lines). All schema lookups **MUST** use the grep-only commands defined in the `salesforce-graphql-explore-schema` skill. Do NOT open, read, stream, or parse `./schema.graphql` with any tool other than grep.
24
+
25
+ ## Directory Context
26
+
27
+ The generated app has a two-level directory structure. Commands must run from the correct directory.
28
+
29
+ ```
30
+ <project-root>/ ← SFDX project root
31
+ ├── schema.graphql ← grep target
32
+ ├── sfdx-project.json
33
+ └── force-app/main/default/webapplications/<app-name>/ ← webapp dir
34
+ ├── package.json (npm scripts: graphql:schema, graphql:codegen, lint)
35
+ ├── eslint.config.js (schema ref: ../../../../../schema.graphql)
36
+ ├── codegen.yml (schema ref: ../../../../../schema.graphql)
37
+ └── src/ (source code, .graphql query files)
38
+ ```
39
+
40
+ | Command | Run from | Why |
41
+ | ------------------------- | ---------------- | -------------------------------------- |
42
+ | `npm run graphql:schema` | **webapp dir** | Script is in webapp's `package.json` |
43
+ | `npm run graphql:codegen` | **webapp dir** | Reads `codegen.yml` in webapp dir |
44
+ | `npx eslint <file>` | **webapp dir** | Reads `eslint.config.js` in webapp dir |
45
+ | `grep ... schema.graphql` | **project root** | `schema.graphql` lives at project root |
46
+ | `sf api request graphql` | **project root** | Needs `sfdx-project.json` |
47
+
48
+ > **Wrong directory = silent failures.** `npm run graphql:schema` from the project root will fail with "missing script." `grep ./schema.graphql` from the webapp dir will fail with "no such file."
49
+
50
+ ## Prerequisites
51
+
52
+ The base React app (`base-react-app`) ships with all GraphQL dependencies and tooling pre-configured:
53
+
54
+ - `@salesforce/sdk-data` — runtime SDK for `createDataSDK` and `gql`
55
+ - `@graphql-codegen/cli` + plugins — type generation from `.graphql` files and inline `gql` queries
56
+ - `@graphql-eslint/eslint-plugin` — validates `.graphql` files and `gql` template literals against `schema.graphql` (used as a query validation gate — see Step 6)
57
+ - `graphql` — shared by codegen, ESLint, and schema introspection
58
+
59
+ Before using this skill, ensure:
60
+
61
+ 1. The `@salesforce/sdk-data` package is available (provides `createDataSDK`, `gql`, `NodeOfConnection`)
62
+ 2. A `schema.graphql` file exists at the project root. If missing, generate it:
63
+ ```bash
64
+ # Run from webapp dir (force-app/main/default/webapplications/<app-name>/)
65
+ npm run graphql:schema
66
+ ```
67
+
68
+ ## npm Scripts
69
+
70
+ - **`npm run graphql:schema`** — _(run from webapp dir)_ Downloads the full GraphQL schema from a connected Salesforce org via introspection. Outputs `schema.graphql` to the project root.
71
+ - **`npm run graphql:codegen`** — _(run from webapp dir)_ Generates TypeScript types from `.graphql` files and inline `gql` queries. Outputs to `src/api/graphql-operations-types.ts`.
72
+
73
+ ## Workflow
74
+
75
+ ### Step 1: Download Schema
76
+
77
+ Ensure `schema.graphql` exists at the project root. If missing, run `npm run graphql:schema` from the webapp dir.
78
+
79
+ ### Step 2: Explore the Schema (grep-only)
80
+
81
+ Before writing any query, verify the target object and its fields exist in the schema.
82
+
83
+ **Invoke the `salesforce-graphql-explore-schema` skill** for the full exploration workflow and **mandatory grep-only access policy**.
84
+
85
+ > **GREP ONLY** — All schema lookups MUST use the grep commands defined in the `salesforce-graphql-explore-schema` skill. Do NOT open, read, stream, or parse `./schema.graphql` with any tool other than grep.
86
+
87
+ Key actions (all via grep):
88
+
89
+ - `type <ObjectName> implements Record` — find available fields
90
+ - `input <ObjectName>_Filter` — find filter options
91
+ - `input <ObjectName>_OrderBy` — find sorting options
92
+ - `input <ObjectName>CreateInput` / `<ObjectName>UpdateInput` — find mutation input types
93
+
94
+ ### Step 3: Choose the Query Pattern
95
+
96
+ **Pattern 1 — External `.graphql` file** (recommended for complex queries):
97
+
98
+ - Queries with variables, fragments, or shared across files
99
+ - Full codegen support, syntax highlighting, shareable
100
+ - Requires codegen step after changes
101
+ - See example: `api/utils/accounts.ts` + `api/utils/query/highRevenueAccountsQuery.graphql`
102
+
103
+ **Pattern 2 — Inline `gql` tag** (recommended for simple queries):
104
+
105
+ - Simple queries without variables; colocated with usage code
106
+ - Supports dynamic queries (field set varies at runtime)
107
+ - **MUST use `gql` tag** — plain template strings bypass `@graphql-eslint` validation
108
+ - See example: `api/utils/user.ts`
109
+
110
+ ### Step 4: Write the Query
111
+
112
+ For **Pattern 1**:
113
+
114
+ 1. Create a `.graphql` file under `src/api/utils/query/`
115
+ 2. Follow UIAPI structure: `query { uiapi { query { ObjectName(...) { edges { node { ... } } } } } }`
116
+ 3. For mutations, invoke the `salesforce-graphql-mutation-query` skill
117
+ 4. For read queries, invoke the `salesforce-graphql-read-query` skill
118
+
119
+ For **Pattern 2**:
120
+
121
+ 1. Define query inline using the `gql` template tag
122
+ 2. Ensure the query name matches what codegen expects
123
+
124
+ ### Step 5: Test Queries Against Live Org
125
+
126
+ Use the testing workflows in the `salesforce-graphql-read-query` and `salesforce-graphql-mutation-query` skills to validate queries against the connected org before integrating into the app.
127
+
128
+ ### Step 6: Generate Types
129
+
130
+ ```bash
131
+ # Run from webapp dir (force-app/main/default/webapplications/<app-name>/)
132
+ npm run graphql:codegen
133
+ ```
134
+
135
+ This updates `src/api/graphql-operations-types.ts` with `<OperationName>Query`/`<OperationName>Mutation` and `<OperationName>QueryVariables`/`<OperationName>MutationVariables`.
136
+
137
+ ### Step 7: Lint Validate
138
+
139
+ Run ESLint on the file containing the query to validate it against the schema **before** any live testing:
140
+
141
+ ```bash
142
+ # Run from webapp dir
143
+ npx eslint <path-to-file>
144
+ ```
145
+
146
+ The `@graphql-eslint/eslint-plugin` processor extracts GraphQL from `gql` template literals and validates them against `schema.graphql`. Fix all ESLint errors before proceeding.
147
+
148
+ ### Step 8: Implement and Verify
149
+
150
+ Implement the data access function using the pattern below. Use the Quality Checklist before completing.
151
+
152
+ ---
153
+
154
+ ## Core Types & Function Signatures
155
+
156
+ ### createDataSDK and graphql
157
+
158
+ ```typescript
159
+ import { createDataSDK } from "@salesforce/sdk-data";
160
+
161
+ const sdk = await createDataSDK();
162
+ const response = await sdk.graphql?.<ResponseType, VariablesType>(query, variables);
163
+ ```
164
+
165
+ `createDataSDK()` returns a `DataSDK` instance. The `graphql` method uses optional chaining (`?.`) because not all surfaces support GraphQL.
166
+
167
+ ### gql Template Tag
168
+
169
+ ```typescript
170
+ import { gql } from "@salesforce/sdk-data";
171
+
172
+ const MY_QUERY = gql`
173
+ query MyQuery {
174
+ uiapi { ... }
175
+ }
176
+ `;
177
+ ```
178
+
179
+ The `gql` tag enables ESLint validation against the schema. Plain template strings bypass validation.
180
+
181
+ ### Error Handling
182
+
183
+ Default: treat any errors as failure (Strategy A). For partial data tolerance, log errors but use data. For mutations where some return fields are inaccessible, use Strategy C (fail only when no data).
184
+
185
+ ```typescript
186
+ // Default: strict
187
+ if (response?.errors?.length) {
188
+ throw new Error(response.errors.map((e) => e.message).join("; "));
189
+ }
190
+ const result = response?.data;
191
+ ```
192
+
193
+ Responses follow `uiapi.query.ObjectName.edges[].node`; fields use `{ value }`.
194
+
195
+ ### NodeOfConnection
196
+
197
+ ```typescript
198
+ import { type NodeOfConnection } from "@salesforce/sdk-data";
199
+
200
+ type AccountNode = NodeOfConnection<GetHighRevenueAccountsQuery["uiapi"]["query"]["Account"]>;
201
+ ```
202
+
203
+ ---
204
+
205
+ ## Pattern 1: External .graphql File
206
+
207
+ Create a `.graphql` file, run `npm run graphql:codegen`, import with `?raw` suffix, and use generated types.
208
+
209
+ **Required imports:**
210
+
211
+ ```typescript
212
+ import { createDataSDK, type NodeOfConnection } from "@salesforce/sdk-data";
213
+ import MY_QUERY from "./query/myQuery.graphql?raw"; // ← ?raw suffix required
214
+ import type { GetMyDataQuery, GetMyDataQueryVariables } from "../graphql-operations-types";
215
+ ```
216
+
217
+ **When to use:** Complex queries with variables, fragments, or shared across files. Does NOT support dynamic queries (field set varies at runtime).
218
+
219
+ ---
220
+
221
+ ## Pattern 2: Inline gql Tag
222
+
223
+ **Required imports:**
224
+
225
+ ```typescript
226
+ import { createDataSDK, gql } from "@salesforce/sdk-data";
227
+ import { type CurrentUserQuery } from "../graphql-operations-types";
228
+
229
+ const MY_QUERY = gql`
230
+ query CurrentUser {
231
+ uiapi { ... }
232
+ }
233
+ `;
234
+ ```
235
+
236
+ > **MUST use `gql` tag** — plain template strings bypass the `@graphql-eslint` processor entirely, meaning no lint validation against the schema.
237
+
238
+ **When to use:** Simple, colocated queries. Supports dynamic queries (field set varies at runtime).
239
+
240
+ ---
241
+
242
+ ## Conditional Field Selection
243
+
244
+ For dynamic fieldsets with **known** fields, use `@include(if: $condition)` and `@skip(if: $condition)` in `.graphql` files. See GraphQL spec for details.
245
+
246
+ ---
247
+
248
+ ## Anti-Patterns (Not Recommended)
249
+
250
+ ### Direct API Calls
251
+
252
+ ```typescript
253
+ // NOT RECOMMENDED: Direct axios/fetch calls for GraphQL
254
+ // PREFERRED: Use the Data SDK
255
+ const sdk = await createDataSDK();
256
+ const response = await sdk.graphql?.<ResponseType>(query, variables);
257
+ ```
258
+
259
+ ### Missing Type Definitions
260
+
261
+ ```typescript
262
+ // NOT RECOMMENDED: Untyped GraphQL calls
263
+ // PREFERRED: Provide response type
264
+ const response = await sdk.graphql?.<GetMyDataQuery>(query);
265
+ ```
266
+
267
+ ### Plain String Queries (Without gql Tag)
268
+
269
+ ```typescript
270
+ // NOT RECOMMENDED: Plain strings bypass ESLint validation
271
+ const query = `query { ... }`;
272
+
273
+ // PREFERRED: Use gql tag for inline queries
274
+ const QUERY = gql`query { ... }`;
275
+ ```
276
+
277
+ ---
278
+
279
+ ## Quality Checklist
280
+
281
+ > If you have not completed the workflow above, **stop and complete it first**. Invoke the skill workflow before using this checklist.
282
+
283
+ Before completing GraphQL data access code:
284
+
285
+ ### For Pattern 1 (.graphql files):
286
+
287
+ 1. [ ] All field names verified via grep against `schema.graphql` (invoke `salesforce-graphql-explore-schema`)
288
+ 2. [ ] Create `.graphql` file for the query/mutation
289
+ 3. [ ] Run `npm run graphql:codegen` to generate types
290
+ 4. [ ] Import query with `?raw` suffix
291
+ 5. [ ] Import generated types from `graphql-operations-types.ts`
292
+ 6. [ ] Use `sdk.graphql?.<ResponseType>()` with proper generic
293
+ 7. [ ] Handle `response.errors` and destructure `response.data`
294
+ 8. [ ] Use `NodeOfConnection` for cleaner node types when needed
295
+ 9. [ ] Run `npx eslint <file>` from webapp dir — fix all GraphQL errors
296
+
297
+ ### For Pattern 2 (inline with gql):
298
+
299
+ 1. [ ] All field names verified via grep against `schema.graphql`
300
+ 2. [ ] Define query using `gql` template tag (NOT a plain string)
301
+ 3. [ ] Ensure query name matches generated types in `graphql-operations-types.ts`
302
+ 4. [ ] Import generated types for the query
303
+ 5. [ ] Use `sdk.graphql?.<ResponseType>()` with proper generic
304
+ 6. [ ] Handle `response.errors` and destructure `response.data`
305
+ 7. [ ] Run `npx eslint <file>` from webapp dir — fix all GraphQL errors
306
+
307
+ ### General:
308
+
309
+ - [ ] Lint validation passes (`npx eslint <file>` reports no GraphQL errors)
310
+ - [ ] Query field names match the schema exactly (case-sensitive, confirmed via grep)
311
+ - [ ] Response type generic is provided to `sdk.graphql?.<T>()`
312
+ - [ ] Optional chaining is used for nested response data
313
+
314
+ ---
315
+
316
+ ## Reference
317
+
318
+ - Schema exploration: invoke the `salesforce-graphql-explore-schema` skill
319
+ - Read query generation: invoke the `salesforce-graphql-read-query` skill
320
+ - Mutation query generation: invoke the `salesforce-graphql-mutation-query` skill
321
+ - Shared GraphQL schema types: `shared-schema.graphqls` (in this skill directory)
322
+ - Schema download: `npm run graphql:schema` (run from webapp dir)
323
+ - Type generation: `npm run graphql:codegen` (run from webapp dir)
@@ -0,0 +1,160 @@
1
+ ---
2
+ name: salesforce-graphql-explore-schema
3
+ description: Explore the Salesforce GraphQL schema via grep-only lookups. Use before generating any GraphQL query — schema exploration must complete first.
4
+ paths:
5
+ - "**/*.ts"
6
+ - "**/*.tsx"
7
+ - "**/*.graphql"
8
+ ---
9
+
10
+ # Salesforce GraphQL Schema Exploration
11
+
12
+ Guidance for AI agents working with the Salesforce GraphQL API schema. **GREP ONLY** — the schema file is very large (~265,000+ lines). All lookups MUST use grep; do NOT open, read, stream, or parse the file.
13
+
14
+ ## Schema File Location
15
+
16
+ **Location:** `schema.graphql` at the **SFDX project root** (NOT inside the webapp dir). All grep commands **must be run from the project root** where `schema.graphql` lives.
17
+
18
+ > ⚠️ **Important (Access Policy - GREP ONLY)**: Do NOT open, view, stream, paginate, or parse the schema with any tool other than grep. All lookups MUST be done via grep using anchored patterns with minimal context as defined below.
19
+
20
+ If the file is not present, generate it by running (from the **webapp dir**, not the project root):
21
+
22
+ ```bash
23
+ # Run from webapp dir (force-app/main/default/webapplications/<app-name>/)
24
+ npm run graphql:schema
25
+ ```
26
+
27
+ **BEFORE generating any GraphQL query, you MUST:**
28
+
29
+ 1. **Check if schema exists**: Look for `schema.graphql` in the **SFDX project root**
30
+ 2. **If schema is missing**:
31
+ - `cd` to the **webapp dir** and run `npm run graphql:schema` to download it
32
+ - Wait for the command to complete successfully
33
+ - Then proceed with grep-only lookups as defined below.
34
+ 3. **If schema exists**: Proceed with targeted searches as described below
35
+
36
+ > ⚠️ **DO NOT** generate GraphQL queries without first having access to the schema. Standard field assumptions may not match the target org's configuration.
37
+
38
+ ## Schema Structure Overview
39
+
40
+ Main entry points: `Query { uiapi }` for reads; `Mutation { uiapi(input: ...) }` for creates/updates/deletes. Record queries use `uiapi.query.<ObjectName>`.
41
+
42
+ ## Allowed Lookups (grep-only)
43
+
44
+ Use ONLY these grep commands to locate specific definitions in schema.graphql. Do not use editors (VS Code/vim/nano), cat/less/more/head/tail, or programmatic parsers (node/python/awk/sed/jq).
45
+
46
+ - Always include:
47
+ - `-n` (line numbers) and `-E` (extended regex)
48
+ - Anchors (`^`) and word boundaries (`\b`)
49
+ - Minimal context with `-A N` (prefer the smallest N that surfaces the needed lines)
50
+
51
+ ### 1. Find Available Fields for a Record Type
52
+
53
+ Search for `type <ObjectName> implements Record` to find all queryable fields:
54
+
55
+ ```bash
56
+ # Example: Find Account fields (anchored, minimal context)
57
+ grep -nE '^type[[:space:]]+Account[[:space:]]+implements[[:space:]]+Record\b' ./schema.graphql -A 60
58
+ ```
59
+
60
+ ### 2. Find Filter Options for a Record Type
61
+
62
+ Search for `input <ObjectName>_Filter` to find filterable fields and operators:
63
+
64
+ ```bash
65
+ # Example: Find Account filter options (anchored)
66
+ grep -nE '^input[[:space:]]+Account_Filter\b' ./schema.graphql -A 40
67
+ ```
68
+
69
+ ### 3. Find OrderBy Options
70
+
71
+ Search for `input <ObjectName>_OrderBy` for sorting options:
72
+
73
+ ```bash
74
+ # Example: Find Account ordering options (anchored)
75
+ grep -nE '^input[[:space:]]+Account_OrderBy\b' ./schema.graphql -A 30
76
+ ```
77
+
78
+ ### 4. Find Mutation Operations
79
+
80
+ Search for operations in `UIAPIMutations`:
81
+
82
+ ```bash
83
+ # Example: Find Account mutations (extended regex)
84
+ grep -nE 'Account.*(Create|Update|Delete)' ./schema.graphql
85
+ ```
86
+
87
+ ### 5. Find Input Types for Mutations
88
+
89
+ Search for `input <ObjectName>CreateInput` or `input <ObjectName>UpdateInput`:
90
+
91
+ ```bash
92
+ # Example: Find Account create input (anchored)
93
+ grep -nE '^input[[:space:]]+AccountCreateInput\b' ./schema.graphql -A 30
94
+ ```
95
+
96
+ ## Common Operator Types
97
+
98
+ - **StringOperators**: `eq`, `ne`, `like`, `lt`, `gt`, `lte`, `gte`, `in`, `nin`
99
+ - **OrderByClause**: `order: ResultOrder` (ASC/DESC), `nulls: NullOrder` (FIRST/LAST)
100
+
101
+ ## Field Value Wrappers
102
+
103
+ Salesforce GraphQL returns field values wrapped in typed objects:
104
+
105
+ | Wrapper Type | Access Pattern |
106
+ | --------------- | ---------------------------------- |
107
+ | `StringValue` | `FieldName { value }` |
108
+ | `IntValue` | `FieldName { value }` |
109
+ | `BooleanValue` | `FieldName { value }` |
110
+ | `DateTimeValue` | `FieldName { value displayValue }` |
111
+ | `PicklistValue` | `FieldName { value displayValue }` |
112
+ | `CurrencyValue` | `FieldName { value displayValue }` |
113
+
114
+ ## Agent Workflow for Building Queries (grep-only)
115
+
116
+ **Pre-requisites (MANDATORY):**
117
+
118
+ - [ ] Verified `schema.graphql` exists in the **SFDX project root**
119
+ - [ ] If missing, ran `npm run graphql:schema` from the **webapp dir** and waited for completion
120
+ - [ ] Confirmed connection to correct Salesforce org (if downloading fresh schema)
121
+
122
+ **Workflow Steps:**
123
+
124
+ 1. **Identify the target object** (e.g., Account, Contact, Opportunity)
125
+ 2. **Run the "Find Available Fields" grep command** for your object (copy only the field names visible in the grep output; do not open the file)
126
+ 3. **Run the "Find Filter Options" grep command** (`<Object>_Filter`) to understand filtering options
127
+ 4. **Run the "Find OrderBy Options" grep command** (`<Object>_OrderBy`) for sorting capabilities
128
+ 5. **Build the query** following the patterns in the `salesforce-graphql-read-query` or `salesforce-graphql-mutation-query` skill using only values returned by grep
129
+ 6. **Validate field names** using grep matches (case-sensitive). Do not open or parse the file beyond grep.
130
+
131
+ ## Tips for Agents
132
+
133
+ - **Always verify field names** by running the specific grep commands; do not open the schema file
134
+ - **Use grep with anchors and minimal -A context** to explore the schema efficiently—never read or stream the file
135
+ - **Check relationships** by looking for `parentRelationship` and `childRelationship` comments in type definitions
136
+ - **Look for Connection types** (e.g., `AccountConnection`) via grep to understand pagination structure
137
+ - **Custom objects** end with `__c` (e.g., `CustomObject__c`)
138
+ - **Custom fields** also end with `__c` (e.g., `Custom_Field__c`)
139
+
140
+ ## Forbidden Operations
141
+
142
+ To prevent accidental large reads, the following are prohibited for schema.graphql:
143
+
144
+ - Opening in any editor (VS Code, vim, nano)
145
+ - Using cat, less, more, head, or tail
146
+ - Programmatic parsing (node, python, awk, sed, jq)
147
+ - Streaming or paginating through large portions of the file
148
+
149
+ If any of the above occurs, stop and replace the action with one of the Allowed Lookups (grep-only).
150
+
151
+ ## Output Minimization
152
+
153
+ - Prefer precise, anchored patterns with word boundaries
154
+ - Use the smallest `-A` context that surfaces required lines
155
+ - If results are noisy, refine the regex rather than increasing context
156
+
157
+ ## Related Skills
158
+
159
+ - For generating read queries, invoke the `salesforce-graphql-read-query` skill
160
+ - For generating mutation queries, invoke the `salesforce-graphql-mutation-query` skill
@@ -1,40 +1,47 @@
1
- # GraphQL Mutation Query Generation
1
+ ---
2
+ name: salesforce-graphql-mutation-query
3
+ description: Generate Salesforce GraphQL mutation queries. Use when the query to generate is a mutation query. Schema exploration must complete first — invoke salesforce-graphql-explore-schema first.
4
+ paths:
5
+ - "**/*.ts"
6
+ - "**/*.tsx"
7
+ - "**/*.graphql"
8
+ ---
9
+
10
+ # Salesforce GraphQL Mutation Query Generation
2
11
 
3
12
  **Triggering conditions**
4
13
 
5
- 1. Only if the schema exploration phase completed successfully
14
+ 1. Only if the schema exploration phase completed successfully (invoke `salesforce-graphql-explore-schema` first)
6
15
  2. Only if the query to generate is a mutation query
7
16
 
8
- ## Your Role
17
+ ## Schema Access Policy
9
18
 
10
- You are a GraphQL expert and your role is to help generate Salesforce compatible GraphQL mutation queries once the exploration phase has completed.
19
+ > ⚠️ **GREP ONLY** During mutation generation you may need to verify field names, input types, or representations. All schema lookups **MUST** use the grep-only commands defined in the `salesforce-graphql-explore-schema` skill. Do NOT open, read, stream, or parse `./schema.graphql` with any tool other than grep.
11
20
 
12
- You will leverage the context provided by the requesting user as well as the validation phase provided by the schema exploration. This tool will also provide you with a method to dynamically query the target org instance that you will use to test the generated query.
21
+ ## Your Role
13
22
 
14
- If the schema exploration has not been executed yet, you **MUST** run it first, and then get back to mutation query generation.
23
+ You are a GraphQL expert. Generate Salesforce-compatible mutation queries. Schema exploration must complete first. If the schema exploration has not been executed yet, you **MUST** run the full exploration workflow from the `salesforce-graphql-explore-schema` skill first, then return here for mutation query generation.
15
24
 
16
25
  ## Mutation Queries General Information
17
26
 
18
- **IMPORTANT**:
19
-
20
- 1. **Mutation Types**: The GraphQL engine supports `Create`, `Update` and `Delete` operations
21
- 2. **Id Based Mutations**: `Update` and `Delete` operations operate on Id-based entity identification
22
- 3. **Mutation Schema**: Defined in the [mutation query schema](#mutation-query-schema) section
27
+ The GraphQL engine supports `Create`, `Update`, and `Delete` operations. `Update` and `Delete` operate on Id-based entity identification. See the [mutation query schema](#mutation-query-schema) section.
23
28
 
24
29
  ## Mutation Query Generation Workflow
25
30
 
26
31
  Strictly follow the rules below when generating the GraphQL mutation query:
27
32
 
28
- 1. **Input Fields Validation** - Validate that the set of fields validate [input field constraints](#mutation-queries-input-field-constraints)
33
+ 1. **Input Fields Validation** - Validate that the set of fields validate [input field constraints](#mutation-queries-input-field-constraints). Verify every field name and type against grep output from the schema — do NOT guess or assume
29
34
  2. **Output Fields Validation** - Validate that the set of fields used in the select part of the query validate the [output fields constraints](#mutation-queries-output-field-constraints)
30
- 3. **Type Consistency** - Make sure variables used as query arguments and their related fields share the same GraphQL type
35
+ 3. **Type Consistency** - Make sure variables used as query arguments and their related fields share the same GraphQL type. Verify types via grep lookup — do NOT assume types
31
36
  4. **Report Phase** - Use the [Mutation Query Report Template](#mutation-query-report-template) below to report on the previous validation phases
32
37
  5. **Input Arguments** - `input` is the default name for the argument, unless otherwise specified
33
38
  6. **Output Field** - For `Create` and `Update` operations, the output field is always named `Record`, and is of type EntityName
34
- 7. **Query Generation** - Use the [mutation query](#mutation-query-templates) template and adjust it based on the selected operation
35
- 8. **Output Format** - Use the [standalone](#mutation-standalone-default-output-format---clean-code-only)
36
- 9. **Test the Query** - Use the [Generated Mutation Query Testing](#generated-mutation-query-testing) workflow to test the generated query
37
- 1. **Report First** - Always report first, using the proper output format, before testing
39
+ 7. **Field Name Validation** - Every field name in the generated mutation **MUST** match a field confirmed via grep lookup in the schema. Do NOT guess or assume field names exist
40
+ 8. **Query Generation** - Use the [mutation query](#mutation-query-templates) template and adjust it based on the selected operation
41
+ 9. **Output Format** - Use the [standalone](#mutation-standalone-default-output-format---clean-code-only)
42
+ 10. **Lint Validation** - After writing the mutation to a file, run `npx eslint <file>` from the webapp dir to validate it against the schema. Fix any reported errors before proceeding. See [Lint Validation](#lint-validation) for details
43
+ 11. **Test the Query** - Use the [Generated Mutation Query Testing](#generated-mutation-query-testing) workflow to test the generated query
44
+ 1. **Report First** - Always output the generated mutation in the proper output format BEFORE initiating any test
38
45
 
39
46
  ## Mutation Query Schema
40
47
 
@@ -127,7 +134,7 @@ mutation mutateEntityName(
127
134
  ## Mutation Standalone (Default) Output Format - CLEAN CODE ONLY
128
135
 
129
136
  ```javascript
130
- import { gql } from 'api/graphql.ts';
137
+ import { gql } from '@salesforce/sdk-data';
131
138
  const QUERY_NAME = gql`
132
139
  mutation mutateEntity($input: EntityNameOperationInput!) {
133
140
  uiapi {
@@ -150,36 +157,54 @@ const QUERY_VARIABLES = {
150
157
  };
151
158
  ```
152
159
 
153
- **❌ DO NOT INCLUDE:**
160
+ **❌ FORBIDDEN — Do NOT include any of the following:**
154
161
 
155
- - Explanatory comments about the query
156
- - Field descriptions
162
+ - Explanatory comments about the query (inline or surrounding)
163
+ - Field descriptions or annotations
157
164
  - Additional text about what the query does
158
- - Workflow step descriptions
165
+ - Workflow step descriptions or summaries
166
+ - Comments like `// fetches...`, `// creates...`, `/* ... */`
159
167
 
160
- **✅ ONLY INCLUDE:**
168
+ **✅ ONLY output:**
161
169
 
162
- - Raw query string
163
- - Variables object
164
- - Nothing else
170
+ - The raw query string constant (using `gql` tagged template)
171
+ - The variables object constant
172
+ - Nothing else — no extra imports, no exports, no wrapper functions
173
+
174
+ ## Lint Validation
175
+
176
+ After writing the generated mutation into a source file, validate it against the schema using the project's GraphQL ESLint setup:
177
+
178
+ ```bash
179
+ # Run from webapp dir (force-app/main/default/webapplications/<app-name>/)
180
+ npx eslint <path-to-file-containing-mutation>
181
+ ```
182
+
183
+ **How it works:** The ESLint config uses `@graphql-eslint/eslint-plugin` with its `processor`, which extracts GraphQL operations from `gql` template literals in `.ts`/`.tsx` files and validates the extracted `.graphql` virtual files against `schema.graphql`.
184
+
185
+ **Rules enforced:** `no-anonymous-operations`, `no-duplicate-fields`, `known-fragment-names`, `no-undefined-variables`, `no-unused-variables`
186
+
187
+ **On failure:** Fix the reported issues, re-run `npx eslint <file>` until clean, then proceed to testing.
188
+
189
+ > ⚠️ **Prerequisites**: The `schema.graphql` file must exist (invoke `salesforce-graphql-explore-schema` first) and project dependencies must be installed (`npm install`).
165
190
 
166
191
  ## Generated Mutation Query Testing
167
192
 
168
- **Triggering conditions** - **ALL CONDITIONS MUST VALIDATE\***
193
+ **Triggering conditions** **ALL conditions must be true:**
169
194
 
170
- 1. Only if the [Mutation Query Generation Workflow](#mutation-query-generation-workflow) step global status is `SUCCESS` and you have a generated query
171
- 2. Only if the query to generate is a mutation query
172
- 3. Only if non manual method was used during schema exploration to retrieve introspection data
195
+ 1. The [Mutation Query Generation Workflow](#mutation-query-generation-workflow) completed with status `SUCCESS` and you have a generated query
196
+ 2. The query is a mutation query
197
+ 3. A non-manual method was used during schema exploration to retrieve introspection data
173
198
 
174
199
  **Workflow**
175
200
 
176
- 1. **Report Step** - Explain that you are able to test the query using `sf api request rest`
177
- 2. **Interactive Step** - Ask the user whether they want you to test the query
178
- 1. **WAIT** for the user's answer.
179
- 3. **Input Arguments** - You **MUST** ask the user for the input arguments to use
180
- 1. **WAIT** for the user's answer.
181
- 4. **Test Query** - If the user are OK with you testing the query:
182
- 1. Use `sf api request rest` to POST the query and variables to the GraphQL endpoint:
201
+ 1. **Report Step** - State the exact method you will use to test (e.g., `sf api request graphql` from the **project root**, Connect API, etc.) — this **MUST** match the method used during schema exploration
202
+ 2. **Interactive Step** - Ask the user whether they want you to test the query using the proposed method
203
+ 1. **STOP and WAIT** for the user's answer. Do NOT proceed until the user responds. Do NOT assume consent.
204
+ 3. **Input Arguments** - You **MUST** ask the user for the input argument values to use in the test
205
+ 1. **STOP and WAIT** for the user's answer. Do NOT proceed until the user provides values. Do NOT fabricate test data.
206
+ 4. **Test Query** - Only if the user explicitly agrees and has provided input values:
207
+ 1. Execute the mutation using the reported method (e.g., `sf api request rest` to POST the query and variables to the GraphQL endpoint):
183
208
  ```bash
184
209
  sf api request rest /services/data/v65.0/graphql \
185
210
  --method POST \
@@ -207,14 +232,14 @@ The query is invalid:
207
232
  - **Navigation** - Error contains `is not currently available in mutation results`
208
233
  - **API Version** - Query deals with updates, you're testing with Connect API and error contains `Cannot invoke JsonElement.isJsonObject()`
209
234
  3. **Targeted Resolution** - Depending on the root cause categorization
210
- - **Execution** - You're trying to update or delete an unknown/no longer available entity: either create an entity first, if you have generated the related query, or ask for a valid entity id to use
235
+ - **Execution** - You're trying to update or delete an unknown/no longer available entity: either create an entity first, if you have generated the related query, or ask for a valid entity id to use. **STOP and WAIT** for the user to provide a valid Id
211
236
  - **Syntax** - Update the query using the error message information to fix the syntax errors
212
- - **Validation** - This field's name is most probably invalid, ask user for clarification and **WAIT** for the user's answer
213
- - **Type** - Use the error details and GraphQL schema to correct argument's type, and adjust variables accordingly
237
+ - **Validation** - The field name is most probably invalid. Re-run the relevant grep command from the `salesforce-graphql-explore-schema` skill to verify the correct field name. If still unclear, ask the user for clarification and **STOP and WAIT** for their answer
238
+ - **Type** - Use the error details and re-verify the type via grep lookup in the schema. Correct the argument type and adjust variables accordingly
214
239
  - **Navigation** - Use the [`PARTIAL` status handling workflow](#partial-status-handling-workflow) below
215
240
  - **API Version** - `Record` selection is only available with API version 64 and higher, **report** the issue, and try again with API version 64
216
241
  4. **Test Again** - Resume the [query testing workflow](#generated-mutation-query-testing) with the updated query (increment and track attempt counter)
217
- 5. **Escalation Path** - If targeted resolution fails after 2 attempts, ask for additional details and restart the entire GraphQL workflow, going again through the introspection phase
242
+ 5. **Escalation Path** - If targeted resolution fails after 2 attempts, ask for additional details and restart the entire GraphQL workflow from the `salesforce-graphql-explore-schema` skill
218
243
 
219
244
  ### `PARTIAL` Status Handling Workflow
220
245
 
@@ -224,5 +249,10 @@ The query can be improved:
224
249
  2. Explain that these fields can't be queried as part of a mutation query
225
250
  3. Explain that the query might be considered as failing, as it will report errors
226
251
  4. Offer to remove the offending fields
227
- 5. **WAIT** for the user's answer
252
+ 5. **STOP and WAIT** for the user's answer. Do NOT remove fields without explicit consent.
228
253
  6. If they are OK with removing the fields restart the [generation workflow](#mutation-query-generation-workflow) with the new field list
254
+
255
+ ## Related Skills
256
+
257
+ - Schema exploration: `salesforce-graphql-explore-schema` (must complete first)
258
+ - Read query generation: `salesforce-graphql-read-query`