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

External schema generation and Promises for Observables #43

Open
steffansluis opened this issue May 15, 2018 · 2 comments
Open

External schema generation and Promises for Observables #43

steffansluis opened this issue May 15, 2018 · 2 comments

Comments

@steffansluis
Copy link

I'm using an external library to generate part of my schema. The library support async resolvers but isn't aware they are allowed to be AsyncIterators/Observables, and as such I end up with strings saying [object Object] if I try to use Observables in the partially generated resolvers. As far as I can tell, this is because the library wraps the result in a Promise, resulting in an Observable wrapped in a Promise which is just interpreted as being a Promise resolving to an object.

I will probably end up solving this by fixing this myself on the library, but I was thinking this might be a broader problem that might be generally solvable by considering Promises for Observables to be a valid use case. Curious about your thoughts. 😃

@DxCx
Copy link
Owner

DxCx commented May 16, 2018

wait, so how the library "updates" ?
i mean, it returns a promise no if i got it right..

@steffansluis
Copy link
Author

The library works by allowing you to provide a set of resolvers for different use-cases, each of which may return a Promise or not. The library then wraps the result of the resolvers in a Promise and does some processing before handing it off to GraphQL. Basically, I'd have to update the library anyway to fix the processing, but I think most of the processing doesn't affect the results, so the Observable I return from the resolvers it ending up in the proper place, it is just wrapped in a Promise.

I would guess many schema-generating tools work in a similar manner:

  • Provide some resolver functions, async or not.
  • Library does some connecting up, maybe some checking of results but usually no modification, except wrapping in Promise to ensure async things work correctly.
  • Wrapping with prepareSchema breaks on Observables because they are also being wrapped in a Promise.

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

No branches or pull requests

2 participants