MichalLytek / type-graphql

Create GraphQL schema and resolvers with TypeScript, using classes and decorators!
https://typegraphql.com
MIT License
7.98k stars 674 forks source link

Update documentation to clarify that enum keys are what are passed in/out of resolvers. #1714

Open dwjohnston opened 1 week ago

dwjohnston commented 1 week ago

Describe the issue

An issue I have just experience is when I have an enum like:

enum Status = {
    PENDING = "P", 
    COMPLETE = "C"
}

registerEnumType(Status, {name: "Status}); 

Where I'm hoping to use a query argument like : {status: 'P'}.

That this won't work, GraphQL will resolve the on the keys of the enum, not the values.

There are github issues that similarly reference this issue:

https://github.com/MichalLytek/type-graphql/issues/741 https://github.com/MichalLytek/type-graphql/issues/1521

and this section of the documentation is linked:

https://typegraphql.com/docs/enums.html#interoperability

However, what this doesn't communicate is that the use of enums expects the enum keys to be passed into resolvers/returned from resolvers. This pitfall should be more strongly emphasised.

Are you able to make a PR that fix this?

Sure.

Additional context Add any other context about the problem here.