Skip to content

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

Closed
@glasser

Description

@glasser

(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions