Possibility of passing an expression for the mappers config
#5,594 opened on 2021年2月23日
説明
Is your feature request related to a problem? Please describe.
Not related to a problem. I'm using Mongoose and in order it to work properly I have to map the Mongoose Document interface of my models to the generated resolvers Types. The case it that the map list is getting quite big, once I have to manually add every new Mongoose model to the map list.
Describe the solution you'd like A pattern that can be set for the mappers to resolve would be very handy. Example:
overwrite: true
schema: "./src/typeDefs/*.graphql"
documents: null
generates:
src/lib/generated/graphql.ts:
plugins:
- "typescript"
- "typescript-resolvers"
config:
contextType: ../graphql#Context
useIndexSignature: true
mapperPattern: ../mongoose/models/{{TypeName}}Model#{{TypeName}}Document
The above expression would resolve for each Type of the schema and produce a result like:
(Let's assume TypeName as equal to User)
../mongoose/models/UserModel#UserDocument
For the expressions that could not be resolved to a real reference, the default behavior can be assumed.
The maps explicitly set on mappers option, overrides the pattern one.
An additional option mapperPatternExclude as a list of Types names, can be used to exclude some Types to be parsed by the pattern expression.
Describe alternatives you've considered A plugin that implements such behavior.
Additional context Imagine a project with dozens or even hundreds of Types that have to be mapped.