---
title: NerdGraphMutation
source: https://docs.newrelic.com/docs/new-relic-solutions/build-nr-ui/sdk-component/query-and-storage/NerdGraphMutation
---

A generic NerdGraph mutation component that allows you to mutate anything from NerdGraph.

### Usage

```jsx
import { NerdGraphMutation } from 'nr1'
```

### Examples

#### Do a mutation

```jsx
NerdGraphMutation.mutate({
  mutation: ngql`
    mutation($guid: EntityGuid!) {
      taggingAddTagsToEntity(
        guid: $guid
        tags: { key: "team", values: ["ui"] }
      ) {
        errors {
          message
        }
      }
    }
  `,
  variables: {
    guid: 'XXXXXXXXXXX',
  },
});
```

#### Do mutation and refetch query

```jsx
function render() {
  const mutation = ngql`
    mutation($guid: EntityGuid!) {
      taggingAddTagsToEntity(guid: $guid, tags: $tags) {
        errors {
          message
        }
      }
    }
  `;
  const variables = {
    guid: "XXXXXXXXXXX",
    tags: { key: "team", values: ["ui"] },
  };

  // NOTE: Sometimes mutations take awhile so doing a refetch immediatly after a mutate
  // doesn't show any change.
  return (
    <NerdGraphQuery query={query} variables={variables}>
      {({ data, refetch }) => (
        <>
          <RenderData data={data} />
          <Button
            onClick={() =>
              NerdGraphMutation.mutate({
                mutation,
                variables,
              }).then(refetch)
            }
          >
            Mutate
          </Button>
        </>
      )}
    </NerdGraphQuery>
  );
}
```

### Props

| `children` REQUIREDfunction              | Render prop function as children.                                                                                                                                                                                                                                                                                |
| ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `mutation` REQUIREDstring\|object        | GraphQL mutation, either as a string or a GraphQL document parsed into an AST by `graphql-tag`. ````js import { ngql } from 'nr1';  const mutation = ngql`   mutation($guid: EntityGuid!) {     taggingAddTagsToEntity(guid: $guid, tags: $tags) {       errors {         message       }     }   } `; ```  ```` |
| `unsafeExperimentalNamespaces` string\[] | List containing unsafe [experimental namespaces](https://pages.datanerd.us/unified-api/nerd-graph-docs/graphql/schema_visibility.html#experimental-api-support) your query opts in to using.                                                                                                                     |
| `variables` object                       | Object containing all of the variables your mutation needs to execute.                                                                                                                                                                                                                                           |

### Methods

### `NerdGraphMutation.mutate`

### Type definitions
