Last updated on
M2: Customizing GraphQL Field Names in Commerce
In Magento / Adobe Commerce, you can customize GraphQL field names using the \Magento\Framework\GraphQL\Query\FieldTranslator class.
This allows you to map custom field names in your GraphQL schema to the actual database field names for a given entity.
Configuration
In your module’s etc/graphql/di.xml:
<type name="\Magento\Framework\GraphQL\Query\FieldTranslator">
<arguments>
<argument name="translationMap" xsi:type="array">
<item name="new_graphql_field_name" xsi:type="string">actual_graphql_field_name</item>
<!-- ... additional field mappings go here -->
</argument>
</arguments>
</type>
Schema Definition
When defining your schema, you introduce the custom field name:
type SomeType{
new_graphql_field_name: string
}
Resolver
Then create or adjust your resolver as needed to handle returning the value for the custom field name…