MichalLytek / type-graphql

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

Allow resolvers to depend on other async-resolvers. #898

Open annitya opened 3 years ago

annitya commented 3 years ago

Our project has a lot of async-resolvers. This makes it difficult to build an optimal graph because we are unable to use an async-fields for further resolutions. Discussion here

A gist with a code-example can be seen here

I would very much like to have a dependsOn annotation looking something like this The annotation would make sure that the dependee-resolver would be run first and its promise resolved.

I tried using this library, but was unable to make it work. I also tried hacking it together myself using promises, but was unable to do so.

MichalLytek commented 3 years ago

What I can think of now as a workaround is to use graphql-fields library to parse the client's query and resolve the fields manually ahead of time. Then just return the fields as properties of root object, so they are available to other field resolvers in root object.

annitya commented 3 years ago

A bit of extra work and complexity, but definitely a solid suggestion I will consider using. Atm we are just refetching the object manually. This of course has the drawback that none of the resolvers are run for the re-fetched object.