title: GraphQL WS server doesn't appear to be running
body: <p>I'm trying to get GraphQL Subscriptions working (without Apollo) using these libraries:</p>
  <pre><code>import { graphqlHTTP } from 'express-graphql';
  import { WebSocketServer } from 'ws';
  import { useServer } from 'graphql-ws/lib/use/ws';
  </code></pre>
  <p>I've been reading the source of these libraries and everything written online I can find and just can't get Graphiql to initiate the socket connection. It's probably a small configuration issue I'm missing - can you spot it?</p>
  <p><strong>BEHAVIOR</strong>:
  When I open GraphiQL and attempt to create a subscription, I immediately get returned a <code>null</code> result and no connection is made in Chrome's Network &gt; WS tab. The <code>subscribe</code> method doesn't get called but the <code>resolve</code> method does though <code>payload</code> is empty. 2 days trying to sort this out. Please help.</p>
  <pre><code>import http from &quot;http&quot;;
  import express from &quot;express&quot;;
  import { graphqlHTTP } from &quot;express-graphql&quot;;
  import { WebSocketServer } from &quot;ws&quot;;
  import { useServer } from &quot;graphql-ws/lib/use/ws&quot;;
  
  import graphQLSchema from &quot;./graphql&quot;;
  
  const { NODE_ENV } = process.env;
  console.log(`NODE_ENV: ${NODE_ENV}`);
  
  (async () =&gt; {
      /**
       * Setup Express
       */
      const app = express();
  
      /**
       * Setup GraphQL Server
       */
      const API_ENDPOINT = &quot;/api&quot;;
      const PORT = 8080
      const ENABLE_GRAPHIQL = NODE_ENV !== &quot;production&quot;;
      app.use(
          API_ENDPOINT,
          graphqlHTTP((req, res, graphQLParams) =&gt; {
              return {
                  schema: graphQLSchema,
                  graphiql: ENABLE_GRAPHIQL,
                  context: { req, res },
              };
          })
      );
  
      const httpServer = http.createServer(app);
  
      const wsServer = new WebSocketServer({
          server: httpServer,
          path: API_ENDPOINT,
      });
  
      /**
       * Start Server
       */
      try {
          httpServer.listen(8080, () =&gt; {
              console.log(` GraphQL available at http://localhost:${PORT}${API_ENDPOINT}`);
  
              // create and use the websocket server
              useServer(
                  { schema: graphQLSchema },
                  wsServer
              );
  
              const wsAddress = wsServer.address();
              console.log(` WebSockets listening on ws://localhost:${wsAddress.port}${API_ENDPOINT}`);
          });
      } catch (error) {
          console.error(error);
      }
  })();
  </code></pre>
  <pre><code>Subscription: {
      invitationCreated: {
          resolve: payload =&gt; {
              console.log(payload);
              return payload;
          },
          subscribe: () =&gt; pubsub.asyncIterator('INVITATION_CREATED'),
      },
  }
  </code></pre>
  <pre><code>type Subscription {
      invitationCreated: Invitation
  }
  </code></pre>
  <p>Result:</p>
  <pre><code>subscription invitationCreatedSub {
    invitationCreated {
        email
    }
  }
  
  # returns --&gt;
  {
    &quot;data&quot;: {
      &quot;invitationCreated&quot;: null
    }
  }
  </code></pre>
  <p><strong>EDIT</strong>
  I found out you can do websockets in Postman which gives a little more insight:
  <a href="https://i.stack.imgur.com/txKzW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/txKzW.png" alt="enter image description here" /></a></p>