GraphQL Mutate Parameters
The GraphQL mutate() method in the Data SDK includes several parameters.
1 import { createDataSDK , gql } from "@salesforce/platform-sdk/data" ;
2
3 const dataSdk = await createDataSDK ( ) ;
4
5 const result = await dataSdk . graphql ?. mutate < ResponseType , VariablesType > ( {
6 mutation: MUTATION_STRING ,
7 variables: { ... } ,
8 operationName? : "..."
9 } ) ;
graphql.mutate<T, V = Record<string, unknown>>(options: MutateOptions<V>)
Runs a GraphQL mutation without caching.
Parameters
Parameter Type Description mutationstringThe GraphQL mutation operation string. variables?V, defaults to Record<string, unknown>Optional key-value map of GraphQL variables referenced by the mutation. operationName?stringOptional operation name for multi-operation documents.
UI API Mutation Structure
All GraphQL mutations follow this UI API structure.
1 mutation < OperationName > ( $input : < ObjectName > < Operation > Input ! ) {
2 uiapi {
3 < ObjectName > < Operation > ( input : $input ) {
4 # Create /Update: return Record with selected fields
5 Record {
6 Id
7 < FieldName > { value }
8 }
9 # Delete: return only Id
10 Id
11 }
12 }
13 }
For more information, see Mutations Schema in the GraphQL API Developer Guide .
Inline Mutations with gql Tag
For simple mutations without external .graphql files, use the gql template tag.
1 import { createDataSDK , gql } from "@salesforce/platform-sdk/data" ;
2
3 const DELETE_ACCOUNT = gql `
4 mutation DeleteAccount($id: ID!) {
5 uiapi {
6 AccountDelete(input: { Id: $id }) {
7 Id
8 }
9 }
10 }
11 ` ;
12
13 export async function deleteAccount ( id : string ) {
14 const dataSdk = await createDataSDK ( ) ;
15 const result = await dataSdk . graphql ?. mutate ( {
16 mutation: DELETE_ACCOUNT ,
17 variables: { id } ,
18 } ) ;
19
20 if ( result ?. errors ?. length ) {
21 throw new Error ( "Failed to delete account" ) ;
22 }
23
24 return result ?. data ?. uiapi ?. AccountDelete ?. Id ;
25 }
Inline Mutations
Use inline mutations when:
Simple mutations without complex input structures
Mutations used in only one place
Rapid prototyping or testing
External .graphql Files
Use external .graphql files when:
Complex mutations with many fields
Mutations shared across multiple files
When you want full type generation from codegen
For more information on generating types and implementing a mutation operation, see GraphQL Mutations in Data SDK .
Returns
1 Promise < MutationResult < T > > ;
The return type of dataSdk.graphql?.mutate(), which resolves to the typed GraphQL response payload.
1 interface MutationResult < T > {
2 data : T | undefined ;
3 errors ?: GraphQLError [ ] ;
4 }
Mutations don’t support subscribe() or refresh() like GraphQL queries . To update stale data after a mutation, use a query result reference to call result.refresh().
Consider these mutation response behavior:
A successful mutation returns data with no errors.
A partially successful mutation has both data and errors.
Data SDK preserves the partial data payload, so callers can still use returned fields even when errors exist.
GraphQL mutation operations return these response structures.
Record Create
A create operation returns the record ID and any queried fields.
1 {
2 data: {
3 uiapi: {
4 AccountCreate ?: {
5 Record? : {
6 Id: string ;
7 Name ?: { value? : string | null } ;
8 Industry ?: { value? : string | null } ;
9 // other returned fields...
10 } | null ;
11 } | null ;
12 } ;
13 } ;
14 errors ?: Array < {
15 message : string ;
16 locations ?: Array < { line : number ; column : number } > ;
17 path ?: string [ ] ;
18 } > ;
19 }
Record Update
An update operation returns the record ID and the updated fields.
1 {
2 data: {
3 uiapi: {
4 AccountUpdate ?: {
5 Record? : {
6 Id: string ;
7 Name ?: { value? : string | null } ;
8 // returned updated fields...
9 } | null ;
10 } | null ;
11 } ;
12 } ;
13 errors ?: Array < {
14 message : string ;
15 locations ?: Array < { line : number ; column : number } > ;
16 path ?: string [ ] ;
17 } > ;
18 }
Record Delete
A delete operation returns the deleted record ID only.
1 {
2 data: {
3 uiapi: {
4 AccountDelete ?: {
5 Id: string ;
6 } | null ;
7 } ;
8 } ;
9 errors ?: [
10 {
11 message: string ;
12 locations ?: [ { line: number ; column : number } ] ;
13 path ?: string [ ] ;
14 }
15 ] ;
16 }
Example: Successful Create Record Response
A successful query response includes record data in the RecordCreate object.
1 {
2 "data" : {
3 "uiapi" : {
4 "AccountCreate" : {
5 "Record" : {
6 "Id" : "001xx000003DHP0AAO" ,
7 "Name" : { "value" : "Acme Corp" } ,
8 "Industry" : { "value" : "Technology" }
9 }
10 }
11 }
12 }
13 }
Example: Partially Successful Create Record Response
A partially successful query response includes errors and some data.
1 {
2 "data" : {
3 "uiapi" : {
4 "AccountCreate" : {
5 "Record" : {
6 "Id" : "001xx000003DHP0AAO" ,
7 "Name" : { "value" : "Acme Corp" }
8 }
9 }
10 }
11 } ,
12 "errors" : [
13 {
14 "message" : "Insufficient access on field AnnualRevenue" ,
15 "locations" : [ { "line" : 8 , "column" : 5 } ] ,
16 "path" : [ "uiapi" , "AccountCreate" , "Record" , "AnnualRevenue" ]
17 }
18 ]
19 }
See Also