nestjs / graphql

GraphQL (TypeScript) module for Nest framework (node.js) 🍷
https://docs.nestjs.com/graphql/quick-start
MIT License
1.46k stars 396 forks source link

Add capability to add directive to GraphQL enum and union (Code First approach) #2920

Open AnhQuanTrl opened 1 year ago

AnhQuanTrl commented 1 year ago

Is there an existing issue that is already proposing this?

Is your feature request related to a problem? Please describe it

Currently, even though the GraphQL spec allow directive to be added to enum and union. There is no possible solutions at the moment to add them to Enum and Union with the code first approach.

Describe the solution you'd like

For enum, I think we can add a directive options toregisterEnumType registerEnumType(COLOR, { valuesMap: { RED: { description: 'Risk record', directive: '@directive' }, BLUE: { description: 'Business service record in OpRes', directive: '@directive' }, directive: '@directive' }); The same thing can be done for createUnionType: createUnionType({ name: 'UnionName', types: ..., directive: '@directive' })

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

We need the ability to apply a directive to types and fields in our GraphQL schema and then at build time generate different schema for different environments (parner/third-party and internal use). This is similar to Apollo Contract . Even if we use Apollo Contract, we need a way to apply the @tag directive to enum, enum values and union to hide it.

kamilmysliwiec commented 1 year ago

Would you like to create a PR for this issue?

AnhQuanTrl commented 1 year ago

I would love to but currently have limited time. I will create a PR once I find some free time. Thank you.

snovos commented 5 months ago

Its been a year. Any updates on this?