Edit in GitHubLog an issue

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.

Usage

The following example renames the currency query field to currencyType in the Adobe Commerce source:

Copied to your clipboard
{
"meshConfig": {
"sources": [
{
"name": "AdobeCommerce",
"transforms": [
{
"rename": {
"renames": [
{
"from": {
"type": "Query",
"field": "currency"
},
"to": {
"type": "Query",
"field": "currencyType"
}
}
]
}
}
],
"handler": {
"graphql": {
"endpoint": "https://venia.magento.com/graphql"
}
}
}
]
}
}

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".

Copied to your clipboard
[
{
"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
}
]
}
}
]

Config API Reference

  • mode (type: String (bare | wrap)) - Specify to apply rename transforms to bare schema or by wrapping original schema
  • renames (type: Array of Object, required) - Array of rename rules:
    • from (type: Object, required):
      • type (type: String)
      • field (type: String)
      • argument (type: String)
    • to (type: Object, required):
      • type (type: String)
      • field (type: String)
      • argument (type: String)
    • useRegExpForTypes (type: Boolean) - Use Regular Expression for type names
    • useRegExpForFields (type: Boolean) - Use Regular Expression for field names
    • useRegExpForArguments (type: Boolean) - Use Regular Expression for field names
    • regExpFlags (type: String) - Flags to use in the Regular Expression
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.