dotansimha / dotansimha/graphql-code-generator-community

MongoDB Plugin: Add way to specify custom type for discriminatorField

Open
#127 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
137
Forks
195
Avg merge
6h 20m
Merged PRs (30d)
16

Description

When using the MongoDB TypeScript plugin and specifying discriminatorField on an abstractEntity/union it results in a string property. It would be very useful to be able to specify an enum here to take full advantage of TypeScript.

I have two suggestions on how this could work:
1. Add a configuration option in codegen.yml - something similar to "mappers" for Resolvers. It could look something like this:
````yml
discriminatorTypeMappers:
MyAbstractEntity: MyFirstDiscriminatorFieldEnum
MyAbstractUnion: MySecondDiscriminatorFieldEnum
````
2. Add possibility in the discriminatorField to map it to an enum in the GraphQL schema. Probably not optimal since we'd often not want to expose this to the client, but only use it internally on the backend.

My current workaround is to extend the types generated by Codegen. I think a solution like this would make it a lot cleaner and radically improve the usability of abstractEntity/union.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the MongoDB TypeScript plugin and the codegen.yml handling for resolver mappers, then compare how abstractEntity and union discriminatorField values are generated. Done means a documented, tested way to configure a custom discriminator enum without requiring that enum to be exposed in the GraphQL schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, mongodb, typescript
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.