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 Subscriptions Stop Working When WebSocket Gateway Is Added #3448

Open
2 of 4 tasks
e-labInnovations opened this issue Jan 19, 2025 · 0 comments
Open
2 of 4 tasks

Comments

@e-labInnovations
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

  • Without WebSocket Gateway:
    GraphQL queries, mutations, and subscriptions work as expected using the Altair GraphQL extension.
  • With WebSocket Gateway:
    • GraphQL queries and mutations continue to work.
    • GraphQL subscriptions stop working, while the WebSocket Gateway operates correctly.
    • The GraphQL subscription URL (ws://localhost:3000/graphql) is unresponsive, even though other features function properly.

Let me know if you'd like to refine this further!

Minimum reproduction code

https://github.com/e-labInnovations/nest-ws-with-graphql-ws

Steps to reproduce

  1. Clone the repository:

    git clone https://github.com/e-labInnovations/nest-ws-with-graphql-ws.git  
    cd nest-ws-with-graphql-ws  
  2. Install dependencies:

    npm ci  
  3. Start the server:

    npm start  
  4. Open http://localhost:3000/graphql and test the following:

    Query:

    query {  
      getEvents {  
        id  
        title  
        description  
      }  
    }  

    Mutation:

    mutation {  
      createEvent(input: { title: "New Event", description: "This is a new event." }) {  
        id  
        title  
        description  
      }  
    }  
  5. To test subscriptions:

    • Install the Altair GraphQL Chrome Extension
    • Use this subscription query:
      subscription {  
        eventCreated {  
          id  
          title  
          description  
        }  
      }  
    • Set Subscription URL: ws://localhost:3000/graphql
    • Set Subscription Type: WebSocket (graphql-ws)
    • Verify the subscription works as expected.
  6. Now enable the WebSocket Gateway:

    • Uncomment the commented code in src/main.ts and src/events/events.module.ts.
    • Restart the server.
  7. Test the WebSocket Gateway using a WebSocket client like WebSocket King :

    • URL: ws://localhost:3000/
    • Message:
      {"event":"message","data":"new text msg"}  
    • Confirm it works.
  8. Finally, recheck the GraphQL subscription. It will no longer work while queries and mutations continue functioning.

Expected behavior

  • GraphQL queries, mutations, and subscriptions should work seamlessly alongside the WebSocket Gateway without interference.

Package version

12.2.2

Graphql version

  • @nestjs/graphql: ^12.2.2
  • GraphQL: ^16.10.0
  • GraphQL Subscriptions: ^3.0.0
  • GraphQL WS: ^5.16.2

NestJS Version

  • @nestjs/core: ^10.4.15
  • @nestjs/platform-ws: ^10.4.15
  • @nestjs/apollo: ^12.2.2

NestJS version

10.4.15

Node.js version

22.12.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant