Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow returning AsyncIterators from resolvers 🤔 #100

Open
n1ru4l opened this issue Sep 19, 2020 · 1 comment
Open

Allow returning AsyncIterators from resolvers 🤔 #100

n1ru4l opened this issue Sep 19, 2020 · 1 comment

Comments

@n1ru4l
Copy link
Owner

n1ru4l commented Sep 19, 2020

I had this idea that is actually possible to allow returning AsyncIterators from resolvers without waiting for it to land in graphql-js. The only downside would be that typings in user code could be wrong (Promise<T> | T expected instead of AsyncIterator<T>) 😅. However, that could be easily solved with patch-package.

The idea is to wrap each field resolver (as in #94). The wrapper will then check whether the returned value is a plain value, a Promise, or an AsyncIterator. In the case of plain value and Promise it will just forward it. In case of an AsyncIterator it will (1) get the first value and resolve a Promise with it and (2) register that the live query returns an AsyncIterator for a given query path and then forwards patches to the client once new data is returned from the AsyncIterator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant