Transform - rename any field that matches regex in any type #5437
Replies: 2 comments
-
Hey @cristianbriscaru! I noticed that you're trying to rename fields in multiple types using a regex pattern with GraphQL Mesh's Instead of using the transforms:
namingConvention:
mode: wrap
fieldNames: camelCase
fieldArgumentNames: camelCase
wrap:
Query:
addressLine_(.*):
resolve: ${_args => _args[0].replace('addressLine_', 'addressLine')} In this configuration, we use the By adopting this approach, the field renaming will be applied to all fields across the types that match the regex pattern. This saves you from the effort of specifying the renaming individually for each type. Make sure to adjust the configuration according to your specific type names and field patterns. You can extend this approach to handle additional types and field renaming patterns as needed. I hope this solution works for you! Feel free to reach out if you have any further questions or need more assistance. |
Beta Was this translation helpful? Give feedback.
-
Hi @bartvdbraak , thanks for the quick response. I tried you solution but unfortunately I am getting this error : not sure if I need to install a dedicate package for
this is how my code looks:
any ideea what might be wrong ? |
Beta Was this translation helpful? Give feedback.
-
Hi, how can I rename any field that matches a regex, eg from 'addressLine_(.*)' to addressLine$1' , in any type ?
I have tried this but it doesn't seem to have any effect :
`
transforms:
mode: wrap
fieldNames: camelCase
fieldArgumentNames: camelCase
mode: wrap
renames:
- from:
field: .addressLine_(.)
to:
field: addressLine$1
useRegExpForFields: true
`
only way I could make it work was if I specify the type:
`
transforms:
mode: wrap
fieldNames: camelCase
fieldArgumentNames: camelCase
mode: wrap
renames:
- from:
type: UserProfile
field: addressLine_(.*)
to:
type: UserProfile
field: addressLine$1
useRegExpForFields: true
`
but I have 6 types and it looks counter productive to specify the field rename for all types
Can this be done in a single 'rename' ?
Beta Was this translation helpful? Give feedback.
All reactions