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

Feature request: mung.write #15

Closed
hedgeday opened this issue Apr 4, 2018 · 6 comments
Closed

Feature request: mung.write #15

hedgeday opened this issue Apr 4, 2018 · 6 comments

Comments

@hedgeday
Copy link
Contributor

hedgeday commented Apr 4, 2018

I have a use case for a mung.writeJson function which overrides the res.write function only when the response type application/json.

For example, apollo-server sends graphQL responses via res.write, after setting the Content-Type and Content-Length headers. You can take a look at the specific source code here. If this happens, mung.json is never called even though the response is a json object.

Thoughts on this? I have a simple working implementation, I have opened a pull request (#14). Let me know what you think 😄

@richardschneider
Copy link
Owner

Why not submit a PR to apollo-server to use res.json?

@hedgeday
Copy link
Contributor Author

hedgeday commented Apr 5, 2018

Good question. From what I can see it's a matter of consistency and possible code reusability within the repo. Apollo-server supports several server side frameworks (express, connect, hapi and so on) - it seems not to rely on framework specific functions like the express-specific res.json, and relies instead on the node native res.write function across the codebase. Given that, I'm not sure it would be the right thing to change it in this one instance.

@hedgeday hedgeday changed the title Feature request: writeJson Feature request: mung.write Apr 5, 2018
@richardschneider
Copy link
Owner

mung.write added to NPM v0.5.0 release.

Thanks for all the extra effort.

@anodynos
Copy link

anodynos commented Sep 24, 2018

I'm using it in this scenario, but after manipulating the response I'm getting:

  • a failure on Chrome / graphiql ERR_CONTENT_LENGTH_MISMATCH 200 (OK) (after 5.1 secs)
  • an OK response on PostMan, again after 5.1 secs (normal query takes 0.1 secs).

I can indeed see the Content-Length header having a very different size (the manipulated is smaller) - any ideas how to go about it? Should I also manipulate the headers?

@richardschneider
Copy link
Owner

Is it possible to show the code (or point to the repo) that manipulates the the response?

@richardschneider
Copy link
Owner

@anodynos Also, could you open a new issue.

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

3 participants