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

Bug: Cannot set headers after they are sent to the client #25

Closed
cschroeter opened this issue May 30, 2018 · 3 comments
Closed

Bug: Cannot set headers after they are sent to the client #25

cschroeter opened this issue May 30, 2018 · 3 comments

Comments

@cschroeter
Copy link

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

import graphqlPlayground from 'graphql-playground-middleware-express';

// ...
 consumer
      .apply(
        // Here the error happens
        graphqlPlayground({
          endpoint: '/graphql',
          subscriptionsEndpoint: `ws://localhost:5001/subscriptions`
        })
      )
      .forRoutes('/graphiql')
      .apply(
        graphqlExpress(async req => ({
          schema,
          rootValue: req,
          context: req,
          formatError: (error: GraphQLError) => {
            return error.originalError instanceof BaseException ? error.originalError.serialize() : error;
          }
        }))
      )
      .forRoutes('/graphql');
(node:10937) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:471:11)
    at ServerResponse.header (/Users/cschroeter/Workspace/Playground/graphql-yoga/nest-yoga/node_modules/express/lib/response.js:767:10)
    at ServerResponse.send (/Users/cschroeter/Workspace/Playground/graphql-yoga/nest-yoga/node_modules/express/lib/response.js:170:12)
    at ServerResponse.json (/Users/cschroeter/Workspace/Playground/graphql-yoga/nest-yoga/node_modules/express/lib/response.js:267:15)
    at ExpressAdapter.reply (/Users/cschroeter/Workspace/Playground/graphql-yoga/nest-yoga/node_modules/@nestjs/core/adapters/express-adapter.js:41:52)
    at ExceptionsHandler.next (/Users/cschroeter/Workspace/Playground/graphql-yoga/nest-yoga/node_modules/@nestjs/core/exceptions/exceptions-handler.js:33:29)
    at /Users/cschroeter/Workspace/Playground/graphql-yoga/nest-yoga/node_modules/@nestjs/core/router/router-proxy.js:12:35
    at Layer.handle [as handle_request] (/Users/cschroeter/Workspace/Playground/graphql-yoga/nest-yoga/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/cschroeter/Workspace/Playground/graphql-yoga/nest-yoga/node_modules/express/lib/router/index.js:317:13)
    at /Users/cschroeter/Workspace/Playground/graphql-yoga/nest-yoga/node_modules/express/lib/router/index.js:284:7

Expected behavior

Instead of the classic GraphiQL UI, I would like to use the superior graphql-playground-middleware-express

Environment


"@nestjs/common": "5.0.1",
"@nestjs/core": "5.0.1",
"@nestjs/graphql": "3.0.0",
"@nestjs/mongoose": "5.0.0",
"@nestjs/passport": "1.0.10",
"@nestjs/testing": "5.0.1"

 
For Tooling issues:
- Node version: 10.2.1
- Platform:  Mac OS

@kamilmysliwiec
Copy link
Member

Hey @cschroeter,
This issue comes from the playground library: graphql/graphql-playground#557

Temporary workaround:

consumer
      .apply(
        graphqlPlayground({
          endpoint: '/graphql',
        }),
        () => {},
      )
      .forRoutes('/graphiql');

@esingletary
Copy link

If anyone gets an error of Expected 1 arguments but got 2, casting it to any does the trick until the bug is fixed.

    (consumer
      .apply as any)(
        graphqlPlayground({
          endpoint: '/graphql',
        }),
        () => { },
    )
      .forRoutes('/graphiql');

@lock
Copy link

lock bot commented Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
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

3 participants