useAsyncSchema does not await the schema promise #1110
Labels
documentation
Improvements or additions to documentation
kind/discussion
Improvements or additions to documentation
Milestone
Describe the bug
The
useAsyncSchema
accepts a promise that resolves to a GraphQL schema as argument. It chains a.then()
on this promise (inside the call tosetSchema
happens), but since the envelop initialisation is synchronous, it might happen that the GraphQL server is handling the first request before the schema promise has resolved. (Or rejected, which is also not handled btw 🤔 )To Reproduce
Steps to reproduce the behavior:
setTimeout
of one second.Expected behavior
Environment:
@envelop/core
: latestAdditional context
I looked a bit into the codebase, here are some loose thoughts around how to achieve the first point I noted under "expected behavior":
onPluginInit
hook async would easily solve this, but it would be a major change (atm the plugin initialisation and the call toenvelop
is sync). "Remembering" promises returned from that hook and awaiting them when callinggetEnveloped
would also be a breaking change.setSchema
, because it's non-deterministic in which order these calls will happen?envelop
defeats the purpose ofuseAsyncSchema
(you could just await before and use the syncuseSchema
)Would be open to help with this, but right now I'm not what the way forward would be 😄
The text was updated successfully, but these errors were encountered: