---
description:
  The Rename Transform in GraphQL Mesh allows you to rename types, fields, and field arguments,
  making queries look more like mutations. Learn how to use this transform and its RegEx feature in
  this guide.
---

import { Callout } from '@theguild/components'

# Rename Transform

The `rename` transform allows you to rename:

- GraphQL types
- GraphQL fields
- GraphQL field arguments

The `rename` transform helps you avoid conflicting names, simplify complicated names and make
queries look more like mutations.

`rename` elements can contain arrays of individual renaming operations, defined in separate renames
objects. Each of these objects must define the from and to values.

## Installation

```sh npm2yarn
npm i @graphql-mesh/transform-rename
```

## How to use?

Add the following configuration to your Mesh config file:

```yaml filename=".meshrc.yaml"
transforms:
  - rename:
      mode: bare | wrap
      renames:
        # rename type
        - from:
            type: ApiUser
          to:
            type: User
        # rename type fields
        - from:
            type: Query
            field: apiUser
          to:
            type: Query
            field: user
        # rename field arguments
        - from:
            type: Query
            field: user
            argument: user_id
          to:
            type: Query
            field: user
            argument: userId
```

<Callout type="warning" emoji="⚠️">
  `type` and `field` are mandatory to rename a field argument with `argument`.
</Callout>

### RegEx example

You can use RegEx flags to enable the use of regular expressions when renaming using this transform.
This way you can rename multiple types, fields or both. For example, you could use the key value
pair field: api(.\*) in the from object to rename any field of the corresponding type that begins
with "api".

```yaml filename=".meshrc.yaml"
- rename:
    mode: bare | wrap
    renames:
      - from:
          type: Api(.*)
        to:
          type: $1
        useRegExpForTypes: true

      - from:
          type: Query
          field: api(.*)
        to:
          type: Query
          field: $1
        useRegExpForFields: true
```

<Callout>
  For information about "bare" and "wrap" modes, please read the [dedicated
  section](/docs/transforms/transforms-introduction#two-different-modes).
</Callout>

## Config API Reference

import API from '../../../generated-markdown/RenameTransform.generated.md'

<API />
