Skip to content

Use express response methods#2842

Merged
abernix merged 4 commits into
apollographql:masterfrom
mike-marcacci:patch-2
Jul 28, 2019
Merged

Use express response methods#2842
abernix merged 4 commits into
apollographql:masterfrom
mike-marcacci:patch-2

Conversation

@mike-marcacci

@mike-marcacci mike-marcacci commented Jun 14, 2019

Copy link
Copy Markdown
Contributor

We should not bypass the express convention of using res.send here. Doing so prevents other middleware from working as intended.

This includes graphql-upload, which is currently unable to force the response to wait for the request to be fully consumed, and causes severe bugs, including locking a browser out of subsequent requests to the server.

Please see this issue and the accompanying demonstration repo put together with heroic effort by @juona.

We should not bypass the express conventions here. Doing so prevents other middleware from working as intended.

This includes `graphql-upload`, which is currently unable to force the response to wait for the request to be fully consumed, and causes severe bugs, including locking a browser out of subsequent requests to the server.

See:
jaydenseric/graphql-upload#152 (comment)
@jaydenseric

Copy link
Copy Markdown

Does this also need to be fixed in the other middleware packages such as apollo-server-koa?

@mike-marcacci

mike-marcacci commented Jun 14, 2019

Copy link
Copy Markdown
Contributor Author

The koa middle correctly follows the koa convention of using ctx.body = graphqlResponse to set the response body, so the behavior is correct when someone brings their own instance of graphql-upload.

However, all of the upload middleware that are build in to the various apollo-server- packages appear to lack any sort of waiting, so this bug will exist for anyone using uploads but not directly using the middleware exported by graphql-upload

I created issue #2843 for this separate, larger problem.

@mike-marcacci

Copy link
Copy Markdown
Contributor Author

Well, it appears that this package is also tested with connect, and not just express. I'll just leave this here for the Apollo team to decide on, as I don't use any of this anymore.

@abernix abernix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM / Thanks, @mike-marcacci. I certainly agree that using send here is more appropriate.

I've added a commit which falls back to calling end when send isn't available, which should satisfy connect's desires (and if tests are any barometer, the additional commit has resolved the failures).

As you've noted in your other PR, there's certainly room for additional improvement here, and while this code has gone relatively unchanged for almost 3 years, this change should still be an improvement worth getting in ASAP.

@abernix abernix merged commit bf7051e into apollographql:master Jul 28, 2019
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants