dangcuuson / graphql-schema-typescript

Generate TypeScript from GraphQL's schema type definitions
190 stars 36 forks source link

Unable to see Typescript suggestions to resolver returns when `asyncResult` is set to `true` #17

Closed ccpacillos closed 4 years ago

ccpacillos commented 5 years ago

When I set asyncResult option to true, the return type of the resolvers are set to TResult | Promise<TResult> as indicated in the docs, but when I use Ctrl + Space to see suggestions in my resolver returns, it does not give me field suggestions for the TResult. However, when I change all of the resolver return types from TResult | Promise<TResult> to Promise<TResult>, I am already able to see field suggestions. Can we add an option to set resolver return types to Promise<TResult> only? Will it produce undesired side effects?

I'm not sure if it's because of my typescript configuration or not, and I'm still new in Typescript. I'm using VS Code as my editor.

dangcuuson commented 5 years ago

I think it's a limitation on suggestion feature of VSCode, I just tested and have exact same issue.

Having Promise<TResult> as return value when asyncResult set to true could produce some side effects if your resolver does not return a promise (which can be fix easily by making your function async), but I can make the type of asyncResult option to be true | 'asyncOnly' to ensure backward compatibility.

Thank you for the feedback. :smile:

dangcuuson commented 4 years ago

Fixed by allow asyncResult to accept always option.

Under this option, resolve functions will always returns Promise<TResult>, so basically any resolver function will need async keyword.