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

Execute can continue running resolvers even after its returned Promise resolves #3792

Open
glasser opened this issue Dec 2, 2022 · 0 comments

Comments

@glasser
Copy link
Contributor

glasser commented Dec 2, 2022

(I thought I'd filed this a while ago but apparently not! Came from apollographql/apollo-server#4472 (comment))

graphql-js doesn't proactively short-circuit executions when they are guaranteed to end up ignored by a null-bubbling, as long as the execution actually started due to there being Promises involved.

Let’s say you have { x y { ARBITRARY_SELECTION_SET} } } where x has a non-null return type, and x and y both have resolvers that return Promises. And let’s say that x returns a Promise that rejects (or resolves to null). What this means is that we’re going to eventually end up with {data: null} (nothing under y will actually matter), but that graphql-js execution will continue running whatever is under ARBITRARY_SELECTION_SET without any sort of short circuiting. (Its response ends up in a Promise that is being captured by a Promise.all which has already rejected.). In fact, the Promise returned from execute itself can happily resolve while execution is still chugging away on an arbitrary amount of fields under that ARBITRARY_SELECTION_SET. There’s no way to detect from the outside “all the execution related to this operation is done”, nor to “short-circuit” execution so that it stops going.

In an ideal world, we'd be able to stop processing a selection set as soon as it becomes clear that its results will be ignored. At the very least, it would be nice if we didn't continue running new fields after the overall execute Promise resolves.

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

1 participant