Sometime back I developed a simple project. The pr...
# orm-help
k
Sometime back I developed a simple project. The project works perfectly with
graphiql
in the browser. It worked with
graphql-playground
before but right now I keep getting
Server cannot be reached
error.
graphiql
works perfectly. Here's my main server file:
Copy code
const express = require('express');
const { graphqlExpress, graphiqlExpress } = require('graphql-server-express');
const bodyParser = require('body-parser');
const schema = require('./schema');
const resolvers = require('./resolvers');
const { execute, subscribe } = require('graphql');
const { SubscriptionServer } = require('subscriptions-transport-ws');
const { createServer } = require('http');
 
const PORT = 3500;
 
const app = express();

// The GraphQL endpoint
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema }));

// GraphiQL, a visual editor for queries
app.use('/graphiql', graphiqlExpress({ 
  endpointURL: '/graphql',
  subscriptionsEndpoint: `<ws://localhost:${PORT}/subscriptions>`
}));

var ws = createServer(app);
ws.listen(PORT, ()=> {
  console.log("Server Running on Port:", PORT);
  new SubscriptionServer({
    execute,
    subscribe,
    schema
  }, {
    server: ws,
    path: '/subscriptions',
  });
});
Does graphql-playground work with any graphql server that's not prisma or graphcool? I'm using the latest version of
graphql-playground
.
n
Does graphql-playground work with any graphql server that's not prisma or graphcool?
yes. I can't see any reference to
graphql-playground
in your code, do you use the Electron app?
k
Nope. It's just a plain graphql-server. I thought graphql-playground was just a query editor which should be able to connect to any graphql server. Do I need to do something to allow my server to be accessed by graphql-playground?
n
I thought graphql-playground was just a query editor which should be able to connect to any graphql server.
That's correct.
Do I need to do something to allow my server to be accessed by graphql-playground?
No.
Is your server behind a proxy? Is your local network behind a proxy? Did you double check the endpoint that you're connecting to from GraphQL Playground?
k
There's is no proxy and the endpoint(http://localhost:3500/graphiql) works perfectly when I access it using graphiql editor
n
you need to connect to
<http://localhost:3500/graphql>
from the Playground
not
graphiql
k
Thanks, that worked.
👍 1