Cannot POST /graphql

Ash*_*Ash 1 javascript express graphql

I am trying to setup graphiql API but i m getting this error on the screen and network tab of console, i don't understand what is wrong as i have same boilerplate code running in other project. I tried removing httpServer, tried adding cors, checked almost all posts related to this error but could not figure out, please suggestCannot POST /graphql

import express from 'express';
import { createServer } from 'http';
import bodyParser from 'body-parser';
import { graphiqlExpress, graphqlExpress } from 'apollo-server-express';
import { makeExecutableSchema } from 'graphql-tools';
import typeDefs from './graphql/schema';
import resolvers from './graphql';


const schema = makeExecutableSchema({
    typeDefs,
    resolvers
})

const app = express();

app.use(bodyParser.json());

//issue is here
app.use(
    '/graphiql',
    graphiqlExpress({
      endpointURL: "/graphql"
    })
);


app.use(
    '/graphiql',
    graphqlExpress(req => ({
      schema,
      context: {
        user: req.user
      }
    })),
);

const httpServer = createServer(app);

httpServer.listen(3000, err => {
    if (err) {
      console.error(err);
    } else {
      console.log(`App listen to port 3000`);
    }
  });
Run Code Online (Sandbox Code Playgroud)

Dan*_*den 5

您没有设置路由/graphql——路由graphqlExpressgraphiqlExpress中间件都与路由一起使用/graphiql。只需更新路径:

app.use(
    '/graphql',
    graphqlExpress(req => ({
      schema,
      context: {
        user: req.user
      }
    })),
);
Run Code Online (Sandbox Code Playgroud)