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

graphql-server-micro with graphiql issue - "Can't set headers after they are sent" #449

Closed
bwlt opened this issue Jul 2, 2017 · 7 comments

Comments

@bwlt
Copy link
Contributor

bwlt commented Jul 2, 2017

The example on the README.md does not work.
When calling GET http://localhost:3000/graphiql it responds 404 instead of serving the graphiql html app.
On console output there is an error message:

Error: Can't set headers after they are sent.
    at validateHeader (_http_outgoing.js:504:11)
    at ServerResponse.setHeader (_http_outgoing.js:511:3)
    at GraphiQL.resolveGraphiQLString.then.res.statusCode (.../node_modules/graphql-server-micro/src/microApollo.ts:67:11)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:169:7)

I think that on this line the request handler is not waiting for 'resolveGraphiQLString'; So the request pass to the next handler (the 404 handler on the README example).

Later, when 'resolveGraphiQLString' resolves it try to respond but the response was already sent.

The issue is very similar with this: #447

@jimthedev
Copy link
Contributor

I am using them together right now and I ran across this. You can work around it by adding a single 200 route. I didn't investigate further but I added this to my routes and voila everything worked.

get("/noop", (req, res) => {
  return send(res, 200, "");
}),

jimthedev added a commit to jimthedev/graphql-server that referenced this issue Jul 7, 2017
Fixes apollographql#449 for now by adding a noop route to the example so that graphiql does not 404.
@jimthedev
Copy link
Contributor

Docs PR change submitted.

@bwlt
Copy link
Contributor Author

bwlt commented Jul 10, 2017

I'm not sure that the PR is the correct resolution of the problem. It fix only the README example with a workaround :(

@freiksenet
Copy link
Contributor

I'll reopen the issue, it was auto-closed. PRs to fix it properly are very welcome.

@farzd
Copy link

farzd commented Jul 18, 2017

i'm getting this as well
edit: its this release thats causing it
https://github.com/apollographql/apollo-server/releases/tag/v1.0.0

@frederikhors
Copy link

The problem I think is still there: #1523

@abernix
Copy link
Member

abernix commented Feb 19, 2019

The most recent comment on this issue is different than the original issue which was reported.

I'm going to close this issue since it hasn't received a lot of traction and could have been resolved already, particularly since the micro implementation is now built with Apollo Server and now at apollo-server-micro@2.4.2.

If this is still a problem, would someone who's experiencing the problem (or anyone who comes across this issue and is able to assist) mind building a reproduction of the problem in to a runnable CodeSandbox reproduction using the latest version of Apollo Server and sharing the link to that CodeSandbox in this issue?

I'm happy to re-open if this is still occurring and someone can provide a reproduction. Thanks again!

@abernix abernix closed this as completed Feb 19, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 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

No branches or pull requests

6 participants