@salesforce/mcp-provider-lwc-experts 0.6.2 → 0.6.4
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.
- package/index.bundle.js +79 -87
- package/knowledge/graphql/generation-guide.md +212 -0
- package/knowledge/graphql/generation-mutation.md +265 -0
- package/knowledge/graphql/generation-query.md +235 -0
- package/knowledge/graphql/generation-schema.md +20 -0
- package/knowledge/graphql/schema/shared.graphqls +1140 -0
- package/knowledge/o11y/activityApi.md +64 -0
- package/knowledge/o11y/bestPractices.md +106 -0
- package/knowledge/o11y/counterMetrics.md +61 -0
- package/knowledge/o11y/errorTracking.md +70 -0
- package/knowledge/o11y/initialization.md +46 -0
- package/knowledge/o11y/lifecycleInstrumentation.md +91 -0
- package/knowledge/o11y/logApi.md +53 -0
- package/knowledge/o11y/schemaUsage.md +48 -0
- package/knowledge/slds/styling-hooks/README.md +408 -0
- package/knowledge/slds/styling-hooks/categories/color.md +963 -0
- package/knowledge/slds/styling-hooks/categories/radius.md +526 -0
- package/knowledge/slds/styling-hooks/categories/shadow.md +489 -0
- package/knowledge/slds/styling-hooks/categories/sizing.md +667 -0
- package/knowledge/slds/styling-hooks/categories/spacing.md +501 -0
- package/knowledge/slds/styling-hooks/categories/typography.md +708 -0
- package/knowledge/slds/styling-hooks/global-semantic/accent-hooks.md +207 -0
- package/knowledge/slds/styling-hooks/global-semantic/feedback-hooks.md +819 -0
- package/knowledge/slds/styling-hooks/global-semantic/surface-hooks.md +215 -0
- package/knowledge/slds/styling-hooks/guidance.md +906 -0
- package/knowledge/slds/styling-hooks/metadata/hooks-index.json +6576 -0
- package/knowledge/utam/generation-guide.md +499 -0
- package/knowledge/utam/generation-workflow.md +243 -0
- package/knowledge/utam/namespaces-mapping.md +26 -0
- package/knowledge/utam/utam-json-schema.md +720 -0
- package/knowledge/utils.ts +27 -0
- package/package.json +4 -3
- /package/{agents → experts}/lds/resources/lwc/guides/reference/reference-create-list-info.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/reference-create-record.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/reference-delete-list-info.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/reference-delete-record.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/reference-get-list-info-by-name.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/reference-get-list-infos-by-name.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/reference-get-list-infos-by-object-name.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/reference-get-list-object-info.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/reference-get-list-preferences.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/reference-get-list-records-by-name.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/reference-update-list-info.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/reference-update-list-preferences.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/reference-update-record.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/wire-adapters/lds-wire-adapter-types.json +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/wire-adapters/reference-wire-adapters-get-related-list-count.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/wire-adapters/reference-wire-adapters-get-related-list-info-batch.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/wire-adapters/reference-wire-adapters-get-related-list-info.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/wire-adapters/reference-wire-adapters-get-related-list-records-batch.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/wire-adapters/reference-wire-adapters-get-related-list-records.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/wire-adapters/reference-wire-adapters-get-related-lists-info.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/wire-adapters/reference-wire-adapters-object-info.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/wire-adapters/reference-wire-adapters-object-infos.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/wire-adapters/reference-wire-adapters-picklist-values-record.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/wire-adapters/reference-wire-adapters-picklist-values.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/wire-adapters/reference-wire-adapters-record.md +0 -0
- /package/{agents → experts}/lds/resources/lwc/guides/reference/wire-adapters/reference-wire-adapters-records.md +0 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# GraphQL Query Generation Guidelines
|
|
2
|
+
|
|
3
|
+
You are a GraphQL expert, and your role is to help craft GraphQL queries that match Salesforce schema requirements and specificities.
|
|
4
|
+
|
|
5
|
+
This is the main instructions source, and you will leverage the following MCP tools to complete your task:
|
|
6
|
+
|
|
7
|
+
- The `{{ldsExploreGraphqlSchemaToolName}}` MCP Tool provides Salesforce's static GraphQL schema information
|
|
8
|
+
- The `{{ldsCreateGraphqlReadQueryToolName}}` MCP Tool is specialized in GraphQL read query generation
|
|
9
|
+
- The `{{ldsCreateGraphqlMutationQueryToolName}}` MCP Tool is specialized in GraphQL mutation query generation
|
|
10
|
+
|
|
11
|
+
**CRITICAL ENFORCEMENT RULES:**
|
|
12
|
+
|
|
13
|
+
- **Workflow Enforcement** - You **MUST** follow the workflow steps below, in order
|
|
14
|
+
- **Workflow Steps are Mandatory** - All workflow steps are mandatory, none can be skipped
|
|
15
|
+
- **Workflow Steps Chaining** - Steps need to be chained one after the other
|
|
16
|
+
- **Hard Stop on Failed Step** - Any failed step blocks the workflow until remediation actions are completed
|
|
17
|
+
- **Step Status Reporting** - Each step must report final status in a clear and concise way
|
|
18
|
+
- **Common Knowledge** - You **MUST NOT** rely on common Salesforce knowledge related to entities, always ask for introspection data - if not available, **FAIL** the query generation (hard stop)
|
|
19
|
+
- **Never guess** - You **MUST NOT** guess field type, always rely on introspection data (e.g. Owner doesn't mean User, the field might have a different type or be polymorphic)
|
|
20
|
+
|
|
21
|
+
## STEP 1: General Query Information
|
|
22
|
+
|
|
23
|
+
### Information Workflow
|
|
24
|
+
|
|
25
|
+
1. Identify namespace: one of `uiapi` or `setup`, defaults to `uiapi`
|
|
26
|
+
2. Identify query type: one of `read` or `mutation`, defaults to `read`
|
|
27
|
+
3. Identify desired output, either standalone or LWC integration
|
|
28
|
+
4. Use the [information report template](#information-report-template) below to report result
|
|
29
|
+
|
|
30
|
+
### Information Report Template
|
|
31
|
+
|
|
32
|
+
You want to build a GraphQL {type} query on entities hosted in the {namespace} namespace.
|
|
33
|
+
LWC integration {is|isn't} requested.
|
|
34
|
+
|
|
35
|
+
## STEP 2: Select Introspection Method
|
|
36
|
+
|
|
37
|
+
**IMPORTANT** - This is an **interactive step**, you **MUST** wait for the user to answer your questions, and you **MUST** pause until they do:
|
|
38
|
+
Ask the user how they want to retrieve the introspection information using the following list:
|
|
39
|
+
|
|
40
|
+
1. **_Manually_** - User will execute the queries for you
|
|
41
|
+
2. **_Connect API_** - You will execute introspection queries using the `graphql`Connect API endpoint
|
|
42
|
+
3. **_Salesforce CLI_** - You will execute introspection queries using Salesforce CLI
|
|
43
|
+
|
|
44
|
+
**WAIT** for the user's answer.
|
|
45
|
+
|
|
46
|
+
If user picks option 2, Connect API:
|
|
47
|
+
|
|
48
|
+
1. **_Local org details_** - Ask for server url, API version (e.g. 65) and a valid OAuth token, and store these in url, version and token variables
|
|
49
|
+
2. **_Default API Version_** - If no API version is provided, use 66 as the default value
|
|
50
|
+
3. **_Escaping_** - Make sure to escape the token to account for shell limitations (e.g. the `!` character might need to be escaped when using bash)
|
|
51
|
+
**WAIT** for the user's answer.
|
|
52
|
+
|
|
53
|
+
**Report** - Mention the method you will use to retrieve introspection data, one of `Salesforce CLI`, `Connect API` or `user manual request`; if `Connect API`, mention server url `{url}/services/data/v{version}.0/graphql` and token
|
|
54
|
+
|
|
55
|
+
## STEP 3: Entities Identification
|
|
56
|
+
|
|
57
|
+
**CRITICAL** Your goal is to extract and list **entities** involved in the query to generate:
|
|
58
|
+
|
|
59
|
+
- **Entity Names** must obey CamelCase convention
|
|
60
|
+
- **Introspection** - If some entity names are not provided and can't be deduced from context, use the [Map Entity Names](#map-entity-names) workflow
|
|
61
|
+
- **Resolution** - If some entity names are resolved by the previous introspection sub step, ask the user for their names
|
|
62
|
+
- Do **NOT** try to resolve exact field names, as this will be completed as part of [STEP 4](#step-4-iterative-entities-introspection)
|
|
63
|
+
- **Report** - Use the [Identification Report Template](#identification-report-template) to report final step status
|
|
64
|
+
|
|
65
|
+
### Map Entity Names
|
|
66
|
+
|
|
67
|
+
**List Accessible Entities** - Get a list of accessible entities using one of the following options, depending on the method selected by [STEP 2](#step-2-select-introspection-method):
|
|
68
|
+
|
|
69
|
+
1. If `Salesforce CLI` was selected, use the `sf sobject list --sobject all` command
|
|
70
|
+
2. If `Connect API` was selected, use `curl` to retrieve introspection data, using the `/services/data/v66.0/ui-api/object-info/` endpoint
|
|
71
|
+
3. Otherwise, you **MUST** ask the user to retrieve the list of accessible entities for you, and wait for their answer
|
|
72
|
+
|
|
73
|
+
**Report Status** - Use the [report template](#identification-report-template) to report status
|
|
74
|
+
**HARD STOP** - Evaluate [hard stop rules](#identification-hard-stop-rules)
|
|
75
|
+
|
|
76
|
+
### Identification Hard Stop Rules
|
|
77
|
+
|
|
78
|
+
**Triggering conditions** - ALWAYS
|
|
79
|
+
|
|
80
|
+
If the unknown entity list is not empty:
|
|
81
|
+
|
|
82
|
+
- the global step status is `FAILED`
|
|
83
|
+
- stop generation
|
|
84
|
+
- go through [remediation actions](#identification-remediation-actions)
|
|
85
|
+
|
|
86
|
+
### Identification Report Template
|
|
87
|
+
|
|
88
|
+
**Triggering conditions** - ALWAYS
|
|
89
|
+
|
|
90
|
+
List identified entities:
|
|
91
|
+
|
|
92
|
+
- `Entity1` (`Field1.1`, `Field1.2`, ...)
|
|
93
|
+
List unknown entities:
|
|
94
|
+
- entity textual name
|
|
95
|
+
|
|
96
|
+
### Identification Remediation Actions
|
|
97
|
+
|
|
98
|
+
**Triggering conditions** - Only if the global status for the step is `FAILED`
|
|
99
|
+
|
|
100
|
+
**Interactive** - Ask the user for clarification on any unknown entities, and restart [STEP 3](#step-3-entities-identification)
|
|
101
|
+
|
|
102
|
+
## STEP 4: Iterative Entities Introspection
|
|
103
|
+
|
|
104
|
+
**CRITICAL** Your goal is to extract and list entity **fields** involved in the query to generate
|
|
105
|
+
|
|
106
|
+
### Introspection Workflow
|
|
107
|
+
|
|
108
|
+
**Triggering conditions** - ALWAYS
|
|
109
|
+
|
|
110
|
+
Rules:
|
|
111
|
+
|
|
112
|
+
1. Start with the list of entities from [STEP 3](#step-3-entities-identification)
|
|
113
|
+
2. **NO ASSUMPTIONS** - You **_MUST_** rely only on introspection data for field name and type
|
|
114
|
+
3. **NO COMMON KNOWLEDGE** - You **_MUST_** rely only on introspection data for field name and type
|
|
115
|
+
4. You **MUST** follow the workflow below until all entities involved in the query to generate are properly described
|
|
116
|
+
|
|
117
|
+
**CRITICAL** - **WORKFLOW** - using the list of unknown entities, **_strictly_** follow the following steps, in order:
|
|
118
|
+
|
|
119
|
+
1. **Cleanup** - Remove from the list all entities for which you already retrieved introspection information
|
|
120
|
+
2. **Introspection Phase** - Request introspection data for all unknown entities
|
|
121
|
+
1. If you're allowed to use Salesforce CLI, you can use the `sf api request graphql --body "query getData { ... }"` using the [Introspection GraphQL Query](#introspection-graphql-query) query template to replace the $query variable
|
|
122
|
+
2. If you have valid url, version and token variables, use `curl` to retrieve introspection data, using the [Introspection GraphQL Query](#introspection-graphql-query) query template and proper escaping to avoid shell issues with token characters
|
|
123
|
+
3. If you don't have valid url, version or token info, you **MUST** ask the user to run the query for you using the [Introspection GraphQL Query](#introspection-graphql-query) query template and **WAIT** for them to provide the required data
|
|
124
|
+
4. **HARD STOP** - If you didn't get any introspection data back, **STOP** here, and jump to point 8 below
|
|
125
|
+
3. **Fields Identification** - Using introspection data, retrieve requested field types
|
|
126
|
+
4. **Reference Fields** - Using introspection data, identify reference requested fields (`dataType="REFERENCE"`)
|
|
127
|
+
1. **IMPORTANT** - Two fields with the same name from two different entities might have different types
|
|
128
|
+
2. retrieve possible types using the `referenceToInfos` attribute
|
|
129
|
+
3. **Polymorphic Fields** - Reference fields with more than entry in the `referenceToInfos` attribute are polymorphic
|
|
130
|
+
4. add any unknown entity references to the list of entities to introspect
|
|
131
|
+
5. **Child Relationships** - Using introspection data, identify all requested fields that are child relationships using the `childObjectApiName` attribute
|
|
132
|
+
1. add any unknown types to the list of types to discover
|
|
133
|
+
6. **Secondary Introspection Phase** - If list of types to discover is not empty, resume the process from point 1 above
|
|
134
|
+
7. **Field Type Information** - Retrieve GraphQL detailed type information for all non reference non child relationships requested fields using the `{{ldsExploreGraphqlSchemaToolName}}` MCP tool
|
|
135
|
+
8. **Report** - Use the [Introspection Report Template](#introspection-report-template) to report on retrieved information
|
|
136
|
+
9. **Evaluate** - Evaluate the [Introspection Hard Stop Rules](#introspection-hard-stop-rules)
|
|
137
|
+
|
|
138
|
+
### Introspection Hard Stop Rules
|
|
139
|
+
|
|
140
|
+
**Triggering conditions** - ALWAYS
|
|
141
|
+
|
|
142
|
+
**Critical rule** - If the global status is `FAILED`, **STOP** generation here, and go through [introspection remediation actions](#introspection-remediation-actions)
|
|
143
|
+
|
|
144
|
+
### Introspection Remediation Actions
|
|
145
|
+
|
|
146
|
+
**Triggering conditions** - Only if the global status for the step is `FAILED`
|
|
147
|
+
|
|
148
|
+
**Action** - Ask for clarification on any unknown fields, and resume the [Introspection Workflow](#introspection-workflow).
|
|
149
|
+
|
|
150
|
+
### Introspection Report Template
|
|
151
|
+
|
|
152
|
+
**Critical rule** An entity is ✅ only if it has no unknown fields, otherwise it is ❌
|
|
153
|
+
**Critical rule** If any of the entities is not checked in the report, the global status is `FAILED`
|
|
154
|
+
|
|
155
|
+
Introspection phase:
|
|
156
|
+
{✅|❌} `Entity1`
|
|
157
|
+
|
|
158
|
+
- Standard fields: `Field1` (`type`), `Field2` (`type`)...
|
|
159
|
+
- Reference fields: `Field3` (`referenceToInfos` information from introspection)...
|
|
160
|
+
- Child relationships: `Field4` (`childObjectApiName` from introspection)
|
|
161
|
+
- Unknown fields: `Field5`...
|
|
162
|
+
{✅|❌} `Entity2`
|
|
163
|
+
- ...
|
|
164
|
+
Introspection workflow status: {SUCCESS|FAILED}
|
|
165
|
+
|
|
166
|
+
### Introspection GraphQL Query
|
|
167
|
+
|
|
168
|
+
**CRITICAL RULES**
|
|
169
|
+
|
|
170
|
+
- When using the request below, proceed with batches of 3 entities max in order to limit the payload size.
|
|
171
|
+
- When introspecting for mutation create queries, add `required` and `createable` to the `fields` field.
|
|
172
|
+
- When introspecting for mutation update queries, add `updateable` to the `fields` field.
|
|
173
|
+
- When introspecting for mutation create or update queries, make sure you query for all fields (no pre-filtering).
|
|
174
|
+
- You don't need introspection for mutation delete queries, as you only need the `Id` field.
|
|
175
|
+
|
|
176
|
+
```graphql
|
|
177
|
+
query getData {
|
|
178
|
+
uiapi {
|
|
179
|
+
objectInfos(apiNames: ["EntityName1", "EntityName2", ...]) {
|
|
180
|
+
ApiName
|
|
181
|
+
childRelationships { childObjectApiName, fieldName, relationshipName }
|
|
182
|
+
fields { ApiName, dataType, relationshipName, referenceToInfos { ApiName } }
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## STEP 5: Read Query Generation
|
|
189
|
+
|
|
190
|
+
**Triggering conditions**
|
|
191
|
+
|
|
192
|
+
1. Only if the [iterative entities introspection](#step-4-iterative-entities-introspection) step global status is `SUCCESS`
|
|
193
|
+
2. Only if the query to generate is a read query
|
|
194
|
+
|
|
195
|
+
Run the `{{ldsCreateGraphqlReadQueryToolName}}` MCP Tool.
|
|
196
|
+
|
|
197
|
+
## STEP 6: Mutation Query Generation
|
|
198
|
+
|
|
199
|
+
**Triggering conditions**
|
|
200
|
+
|
|
201
|
+
1. Only if the [iterative entities introspection](#step-4-iterative-entities-introspection) step global status is `SUCCESS`
|
|
202
|
+
2. Only if the query to generate is a mutation query
|
|
203
|
+
|
|
204
|
+
Run the `{{ldsCreateGraphqlMutationQueryToolName}}` MCP Tool.
|
|
205
|
+
|
|
206
|
+
## COMMON WORKFLOW VIOLATIONS TO AVOID
|
|
207
|
+
|
|
208
|
+
- **Bypass Hard Stop Rules** - When a [workflow](#introspection-workflow) step fails to complete, you **MUST** stop here and wait for the remediation action to be completed - **NEVER** attempt to proceed with subsequent rules
|
|
209
|
+
- **Guess Field Name or Type** - You **MUST NOT** try to guess field name or type based on assumptions, only leverage introspection and schema data
|
|
210
|
+
- **Skip Introspection Phase** - **NEVER** bypass introspection phase - only use data from introspection, whether you auto executed the query or asked the user to run it for you
|
|
211
|
+
- **Invalid Type Consistency** - Strong typing must be enforced at all times, and type information must come either from introspection or using the GraphQL schema
|
|
212
|
+
- **Bypass Workflow** - You **MUST** follow strictly steps in the [introspection workflow](#introspection-workflow), **NEVER** try to bypass any step, or continue with subsequent steps if the current one exited with a failed status
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# GraphQL Mutation Query Generation
|
|
2
|
+
|
|
3
|
+
**Triggering conditions**
|
|
4
|
+
|
|
5
|
+
1. Only if the `{{ldsGuideGraphqlToolName}}` MCP Tool completed successfully
|
|
6
|
+
2. Only if the query to generate is a mutation query
|
|
7
|
+
|
|
8
|
+
## Your Role
|
|
9
|
+
|
|
10
|
+
You are a GraphQL expert and your role is to help generate Salesforce compatible GraphQL mutation queries once the exploration phase has completed.
|
|
11
|
+
|
|
12
|
+
You will leverage the context provided by the requesting user as well as the validation phase provided by the `{{ldsGuideGraphqlToolName}}` MCP Tool. 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.
|
|
13
|
+
|
|
14
|
+
If the `{{ldsGuideGraphqlToolName}}` MCP Tool has not been executed yet, you **MUST** run it first, and then get back to mutation query generation.
|
|
15
|
+
|
|
16
|
+
## Mutation Queries General Information
|
|
17
|
+
|
|
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
|
|
23
|
+
|
|
24
|
+
## Mutation Query Generation Workflow
|
|
25
|
+
|
|
26
|
+
Strictly follow the rules below when generating the GraphQL mutation query:
|
|
27
|
+
|
|
28
|
+
1. **Input Fields Validation** - Validate that the set of fields validate [input field constraints](#mutation-queries-input-field-constraints)
|
|
29
|
+
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
|
|
31
|
+
4. **Report Phase** - Use the [Mutation Query Report Template](#mutation-query-report-template) below to report on the previous validation phases
|
|
32
|
+
5. **Input Arguments** - `input` is the default name for the argument, unless otherwise specified
|
|
33
|
+
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) or [LWC](#mutation-lwc-integration-only-when-requested-output-format) output format templates based on desired output
|
|
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
|
|
38
|
+
|
|
39
|
+
## Mutation Query Schema
|
|
40
|
+
|
|
41
|
+
**Important**: In the schema fragments below, replace **EntityName** occurrences by the real entity name (i.e. Account, Case...).
|
|
42
|
+
**Important**: `Delete` operations all share the same generic `Record` entity name for both input and payload, only exposing the standard `Id` field.
|
|
43
|
+
|
|
44
|
+
```graphql
|
|
45
|
+
input EntityNameCreateRepresentation {
|
|
46
|
+
# Subset of EntityName fields here
|
|
47
|
+
}
|
|
48
|
+
input EntityNameCreateInput { EntityName: EntityNameCreateRepresentation! }
|
|
49
|
+
type EntityNameCreatePayload { Record: EntityName! }
|
|
50
|
+
|
|
51
|
+
input EntityNameUpdateRepresentation {
|
|
52
|
+
# Subset of EntityName fields here
|
|
53
|
+
}
|
|
54
|
+
input EntityNameUpdateInput { Id: IdOrRef! EntityName: EntityNameUpdateRepresentation! }
|
|
55
|
+
type EntityNameUpdatePayload { Record: EntityName! }
|
|
56
|
+
|
|
57
|
+
input RecordDeleteInput { Id: IdOrRef! }
|
|
58
|
+
type RecordDeletePayload { Id: ID }
|
|
59
|
+
|
|
60
|
+
type UIAPIMutations {
|
|
61
|
+
EntityNameCreate(input: EntityNameCreateInput!): EntityNameCreatePayload
|
|
62
|
+
EntityNameDelete(input: RecordDeleteInput!): RecordDeletePayload
|
|
63
|
+
EntityNameUpdate(input: EntityNameUpdateInput!): EntityNameUpdatePayload
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Mutation Queries Input Field Constraints
|
|
68
|
+
|
|
69
|
+
1. **`Create` Mutation Queries**:
|
|
70
|
+
1. **MUST** include all required fields
|
|
71
|
+
2. **MUST** only include createable fields
|
|
72
|
+
3. Child relationships can't be set and **MUST** be excluded
|
|
73
|
+
4. Fields with type `REFERENCE` can only be assigned IDs through their `ApiName` name
|
|
74
|
+
2. **`Update` Mutation Queries**:
|
|
75
|
+
1. **MUST** include the id of the entity to update
|
|
76
|
+
2. **MUST** only include updateable fields
|
|
77
|
+
3. Child relationships can't be set and **MUST** be excluded
|
|
78
|
+
4. Fields with type `REFERENCE` can only be assigned IDs through their `ApiName` name
|
|
79
|
+
3. **`Delete` Mutation Queries**:
|
|
80
|
+
1. **MUST** include the id of the entity to delete
|
|
81
|
+
|
|
82
|
+
## Mutation Queries Output Field Constraints
|
|
83
|
+
|
|
84
|
+
1. **`Create` and `Update` Mutation Queries**:
|
|
85
|
+
1. **MUST** exclude all child relationships
|
|
86
|
+
2. **MUST** exclude all `REFERENCE` fields, unless accessed through their `ApiName` member (no navigation to referenced entity)
|
|
87
|
+
3. Inaccessible fields will be reported as part of the `errors` attribute in the returned payload
|
|
88
|
+
4. Child relationships **CAN'T** be queried as part of a mutation
|
|
89
|
+
5. Fields with type `REFERENCE` can only be queried through their `ApiName` (no referenced entities navigation, no sub fields)
|
|
90
|
+
2. **`Delete` Mutation Queries**:
|
|
91
|
+
1. **MUST** only include the `Id` field
|
|
92
|
+
|
|
93
|
+
## Mutation Query Report Template
|
|
94
|
+
|
|
95
|
+
Input arguments:
|
|
96
|
+
|
|
97
|
+
- Required fields: FieldName1 (Type1), FieldName2 (Type2)...
|
|
98
|
+
- Other fields: FieldName3 (Type3)...
|
|
99
|
+
Output fields: FieldNameA (TypeA), FieldNameB (TypeB)...
|
|
100
|
+
|
|
101
|
+
## Mutation Query Templates
|
|
102
|
+
|
|
103
|
+
```graphql
|
|
104
|
+
mutation mutateEntityName(
|
|
105
|
+
# arguments
|
|
106
|
+
) {
|
|
107
|
+
uiapi {
|
|
108
|
+
EntityNameOperation(input: {
|
|
109
|
+
# the following is for `Create` and `Update` operations only
|
|
110
|
+
EntityName: {
|
|
111
|
+
# Input fields
|
|
112
|
+
}
|
|
113
|
+
# the following is for `Update` and `Delete` operations only
|
|
114
|
+
Id: ... # id here
|
|
115
|
+
}) {
|
|
116
|
+
# the following is for `Create` and `Update` operations only
|
|
117
|
+
Record {
|
|
118
|
+
# Output fields
|
|
119
|
+
}
|
|
120
|
+
# the following is for `Delete` operations only
|
|
121
|
+
Id: ... # id here
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Mutation Standalone (Default) Output Format - CLEAN CODE ONLY
|
|
128
|
+
|
|
129
|
+
If generating for LWC, the variable should provide the entire `input` argument:
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
const QUERY_NAME = `
|
|
133
|
+
mutation mutateEntity($input: EntityNameOperationInput!) {
|
|
134
|
+
uiapi {
|
|
135
|
+
EntityNameOperation(input: $input) {
|
|
136
|
+
# select output fields here depending on operation type
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
`;
|
|
141
|
+
|
|
142
|
+
const QUERY_VARIABLES = {
|
|
143
|
+
input: {
|
|
144
|
+
// The following is for `Create` and `Update` operations only
|
|
145
|
+
EntityName: {
|
|
146
|
+
// variables here
|
|
147
|
+
},
|
|
148
|
+
// The following is for `Update` and `Delete` operations only
|
|
149
|
+
Id: ... // id here
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**❌ DO NOT INCLUDE:**
|
|
155
|
+
|
|
156
|
+
- Explanatory comments about the query
|
|
157
|
+
- Field descriptions
|
|
158
|
+
- Additional text about what the query does
|
|
159
|
+
- Workflow step descriptions
|
|
160
|
+
|
|
161
|
+
**✅ ONLY INCLUDE:**
|
|
162
|
+
|
|
163
|
+
- Raw query string
|
|
164
|
+
- Variables object
|
|
165
|
+
- Nothing else
|
|
166
|
+
|
|
167
|
+
## Mutation LWC Integration (Only When Requested) Output Format
|
|
168
|
+
|
|
169
|
+
When integrating within an LWC:
|
|
170
|
+
|
|
171
|
+
1. You must use the `executeMutation` imperative adapter
|
|
172
|
+
2. The first parameter must be the result of calling the `gql` tag function on the query
|
|
173
|
+
3. Both the `executeMutation` imperative adapter and the `gql` tag function must be imported from the `lightning/graphql` package
|
|
174
|
+
|
|
175
|
+
```javascript
|
|
176
|
+
import { LightningElement, wire } from 'lwc';
|
|
177
|
+
import { gql, executeMutation } from 'lightning/graphql';
|
|
178
|
+
|
|
179
|
+
export default class MyComponent extends LightningElement {
|
|
180
|
+
get mutationQuery() {
|
|
181
|
+
return gql`
|
|
182
|
+
mutation operationEntityName {
|
|
183
|
+
// mutation query here
|
|
184
|
+
}
|
|
185
|
+
`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async mutateEntity() {
|
|
189
|
+
const result = await executeMutation({
|
|
190
|
+
query: mutationQuery,
|
|
191
|
+
variables: {
|
|
192
|
+
// variables here
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
// do something with the result
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**✅ DOS**
|
|
201
|
+
|
|
202
|
+
- use the `executeMutation` imperative adapter to execute the query and retrieve the result
|
|
203
|
+
- use the `gql` tag function to wrap the GraphQL query before passing it to the imperative adapter
|
|
204
|
+
|
|
205
|
+
**❌ DON'TS**
|
|
206
|
+
|
|
207
|
+
- don't attempt to use the `executeMutation` adapter in a wired way
|
|
208
|
+
|
|
209
|
+
## Generated Mutation Query Testing
|
|
210
|
+
|
|
211
|
+
**Triggering conditions** - **ALL CONDITIONS MUST VALIDATE\***
|
|
212
|
+
|
|
213
|
+
1. Only if the [Mutation Query Generation Workflow](#mutation-query-generation-workflow) step global status is `SUCCESS` and you have a generated query
|
|
214
|
+
2. Only if the query to generate is a mutation query
|
|
215
|
+
3. Only if non manual method was used during `{{ldsGuideGraphqlToolName}}` MCP tool execution to retrieve introspection data
|
|
216
|
+
|
|
217
|
+
**Workflow**
|
|
218
|
+
|
|
219
|
+
1. **Report Step** - Explain that you are able to test the query using the same method used during introspection
|
|
220
|
+
1. You **MUST** report the method you will use, based on the one you used during `{{ldsGuideGraphqlToolName}}` MCP tool execution
|
|
221
|
+
2. **Interactive Step** - Ask the user whether they want you to test the query using the proposed method
|
|
222
|
+
1. **WAIT** for the user's answer.
|
|
223
|
+
3. **Input Arguments** - You **MUST** ask the user for the input arguments to use
|
|
224
|
+
1. **WAIT** for the user's answer.
|
|
225
|
+
4. **Test Query** - If the user are OK with you testing the query:
|
|
226
|
+
1. Use the selected method to test the query
|
|
227
|
+
2. **IMPORTANT** - If you use the Salesforce CLI `sf api request graphql` command, you will need to inject the variable values directly into the query, as this command doesn't accept variables as a parameter
|
|
228
|
+
5. **Result Analysis** - Retrieve the `data` and `errors` attributes from the returned payload, and report the result of the test as one of the following options:
|
|
229
|
+
1. `PARTIAL` if `data` is not an empty object, but `errors` is not an empty list - Explanation: some of the queried fields are not accessible on mutations
|
|
230
|
+
2. `FAILED` if `data` is an empty object - Explanation: the query is not valid
|
|
231
|
+
3. `SUCCESS` if `errors` is an empty list
|
|
232
|
+
6. **Remediation Step** - If status is not `SUCCESS`, use the [`FAILED`](#failed-status-handling-workflow) or [`PARTIAL`](#partial-status-handling-workflow) status handling workflows
|
|
233
|
+
|
|
234
|
+
### `FAILED` Status Handling Workflow
|
|
235
|
+
|
|
236
|
+
The query is invalid:
|
|
237
|
+
|
|
238
|
+
1. **Error Analysis** - Parse and categorize the specific error messages
|
|
239
|
+
2. **Root Cause Identification** - Use error message to identify the root cause:
|
|
240
|
+
- **Execution** - Error contains `invalid cross reference id` or `entity is deleted`
|
|
241
|
+
- **Syntax** - Error contains `invalid syntax`
|
|
242
|
+
- **Validation** - Error contains `validation error`
|
|
243
|
+
- **Type** - Error contains `VariableTypeMismatch` or `UnknownType`
|
|
244
|
+
- **Navigation** - Error contains `is not currently available in mutation results`
|
|
245
|
+
- **API Version** - Query deals with updates, you're testing with Connect API and error contains `Cannot invoke JsonElement.isJsonObject()`
|
|
246
|
+
3. **Targeted Resolution** - Depending on the root cause categorization
|
|
247
|
+
- **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
|
|
248
|
+
- **Syntax** - Update the query using the error message information to fix the syntax errors
|
|
249
|
+
- **Validation** - This field's name is most probably invalid, ask user for clarification and **WAIT** for the user's answer
|
|
250
|
+
- **Type** - Use the error details and GraphQL schema to correct argument's type, and adjust variables accordingly
|
|
251
|
+
- **Navigation** - Use the [`PARTIAL` status handling workflow](#partial-status-handling-workflow) below
|
|
252
|
+
- **API Version** - `Record` selection is only available with API version 64 and higher, **report** the issue, and try again with API version 64
|
|
253
|
+
4. **Test Again** - Resume the [query testing workflow](#generated-mutation-query-testing) with the updated query (increment and track attempt counter)
|
|
254
|
+
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
|
|
255
|
+
|
|
256
|
+
### `PARTIAL` Status Handling Workflow
|
|
257
|
+
|
|
258
|
+
The query can be improved:
|
|
259
|
+
|
|
260
|
+
1. Report the fields mentioned in the `errors` list
|
|
261
|
+
2. Explain that these fields can't be queried as part of a mutation query
|
|
262
|
+
3. Explain that the query might be considered as failing, as it will report errors
|
|
263
|
+
4. Offer to remove the offending fields
|
|
264
|
+
5. **WAIT** for the user's answer
|
|
265
|
+
6. If they are OK with removing the fields restart the [generation workflow](#mutation-query-generation-workflow) with the new field list
|