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

Use express response methods #2842

Merged
merged 4 commits into from
Jul 28, 2019
Merged

Conversation

mike-marcacci
Copy link
Contributor

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

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

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

@mike-marcacci
Copy link
Contributor Author

mike-marcacci commented Jun 14, 2019

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

Copy link
Member

@abernix abernix left a comment

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