# Create a GraphQL mutation We know that GraphQL is great for retrieving data. GraphQL can also create, update, and delete commercetools resources. In GraphQL, these operations are called mutations instead of queries. With mutations in commercetools, you specify an update action and the new values. Update actions work the same way as with the REST API. For the general mutation syntax and structural patterns, see [Create and update resources](/api/graphql.md#create-and-update-resources) and [Delete resources](/api/graphql.md#delete-resources) in the GraphQL API reference. The following sections walk through creating, updating, and deleting a Customer resource as a practical example. ## Use mutations to create resources How do you create a Customer with the API? As you learned in the [Manage resources with the SDK](/learning-developer-essentials/manage-resources-with-the-sdk/overview.md) module, you send a Draft record. In a GraphQL mutation, to create a Customer we have to specify the action customerSignUp and enter the values in a Customer draft record. You must enter all required values-for Customer, only email and password are required. To understand the address information and how to indicate the default shipping address, visit the [API reference](/api/projects/customers.md#customerdraft). As in a GraphQL query, we can ask to have values returned—in this case, we are asking for the generated `id` and `version` along with a few other fields. ```graphql highlightLines="12-17" mutation createCustomer { customerSignUp( draft: { email: "martha.jones@example.com" firstName: "Martha" lastName: "Jones" password: "password" addresses: { country: "DE" } defaultShippingAddress: 0 } ) { customer { id version email defaultShippingAddress { country } } } } ``` Our response looks like this: ```json { "data": { "customerSignUp": { "customer": { "id": "57def72f-c92c-437e-a35c-f6216f780bea", "version": 1, "email": "martha.jones@example.com", "defaultShippingAddress": { "country": "DE" } } } } } ``` Does it really work like a REST request? Yes. We can also check in the Merchant Center if our request was successful: ![Example of Martha Jones having been created in the Customer List in Merchant Center.](https://docs.commercetools.com/learning-developer-essentialsimages/graphql/martha-jones-customer-list.png) ## Use mutations to update resources As a developer working with commercetools, you already know that to update a commercetools resource you have to provide not only the `id` or `key` to specify which record you want to update but also the `version` number of the record handling concurrent updates. You also have to provide the actions you want to perform and any required values for that action (see our [Manage resources with the SDK](/learning-developer-essentials/manage-resources-with-the-sdk/overview.md) module section on version control). This is the same if you are using a GraphQL mutation to update the data. Here’s an example of updating an existing Customer record to set the `firstName` to a new value: ```graphql mutation updateCustomer { updateCustomer( id: "{id}" version: 1 actions: [{ setFirstName: { firstName: "Jan" } }] ) { version firstName lastName email } } ``` We’ve used the `id` and `version` to identify the record and then have one action in our array of actions to indicate we want to set the `firstName` field to the value `Jan`. It is possible to have multiple updates to one record with GraphQL, just like using the REST API and we can request which data we want to have returned. The above query would return: ```json { "data": { "updateCustomer": { "version": 2, "firstName": "Jan", "lastName": "Johns", "email": "martha.johns@sportforall.com" } } } ``` ## Use mutations to delete resources GraphQL can be used for all actions in the resource life cycle management, including the deletion of resources. Just as with updating resources, to delete a resource we have to identify the resource and also provide the correct `version` number. Here’s an example of deleting a Customer: ```graphql mutation deleteCustomer { deleteCustomer(id: "{id}", version: 2) { id version firstName lastName email } } ``` Notice that even with a delete action, we can request values to be returned from the record we are deleting. The above delete action would return: ```json { "data": { "deleteCustomer": { "id": "{id}", "version": 2, "firstName": "Jan", "lastName": "Jones", "email": "martha.jones@example.com" } } } ``` ## Related pages - [Area overview page with navigation](/learning-developer-essentials.md) - [Previous page: Create a GraphQL query](/learning-developer-essentials/graphql/create-a-graphql-query.md) - [Next page: Create an advanced GraphQL query](/learning-developer-essentials/graphql/create-an-advanced-graphql-query.md)