question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Express Playground Not Using Provided Subscription Endpoint

See original GitHub issue

This issue pertains to the following package(s):

  • GraphQL Playground - Electron App
  • GraphQL Playground HTML
  • GraphQL Playground
  • GraphQL Playground Express Middleware
  • GraphQL Playground Hapi Middleware
  • GraphQL Playground Koa Middleware
  • GraphQL Playground Lambda Middleware

What OS and OS version are you experiencing the issue(s) on?

macOS High Sierra Version 10.13.3

What version of graphql-playground(-electron/-middleware) are you experiencing the issue(s) on?

graphql-playground Version 1.4.5 (1.4.5.2716) graphql-playground-middleware-express Version 1.5.7

What is the expected behavior?

A WebSocket connection to a provided subscription endpoint (ie ws://localhost:4000/subscriptions) should be established successfully.

What is the actual behavior?

Playground attempts to establish a WebSocket connection to a different endpoint than the one provided (perhaps a default / fallback endpoint) and fails.

image

As you can see in the screenshot above, a WebSocket connection is trying to be established to ws://localhost:4000/graphql, but that’s not the endpoint I specified.

What steps may we take to reproduce the behavior?

Clone relevant tutorial code from Apollo blog post (https://dev-blog.apollodata.com/tutorial-graphql-subscriptions-server-side-e51c32dc2951):

git clone https://github.com/apollographql/graphql-tutorial.git
cd graphql-tutorial
git checkout t6-end
cd server && npm install
npm install graphql-playground-middleware-express

Add the following code to server.js:

server.use(
  '/playground',
  expressPlayground({
    endpoint: '/graphql',
    subscriptionsEndpoint: 'ws://localhost:4000/subscriptions',
  }),
);

Don’t forget to import:

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

Start the server:

npm start

Go to http://localhost:4000/playground and check the console.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

2reactions
realironnamcommented, Aug 14, 2018

In my case I’m using apollo-server-express 2.0.0 I add config

 playground: {
    subscriptionEndpoint: `ws://${IP_Address}:${PORT}`
  }

to ApolloServer. it’s working properly

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express Playground Not Using Provided Subscription Endpoint
A WebSocket connection to a provided subscription endpoint (ie ws://localhost:4000/subscriptions ) should be established successfully. What is ...
Read more >
Subscriptions - Apollo GraphQL Docs
Subscriptions are long-lasting GraphQL read operations that can update their result whenever a particular server-side event occurs.
Read more >
Apollo Server Express - Playground cannot be reached
Any idea on where could be the issue? Seems like express didn't create the POST endpoint for the /graphql route. EDIT: It works...
Read more >
Untitled
`graphql-yoga` is based on the following libraries & tools: * [`express`](https ... upload * GraphQL Subscriptions * TypeScript typings * GraphQL Playground ......
Read more >
GraphQL: Server-side Subscriptions | by Yuri Nezdemkovski
We use it as a server middleware and the graphql-playground-middleware-express package is all we need. If you use another server framework (such as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found