我通过终端运行我的graphql服务器,但是当我正在运行时
$node server
像这样的/home/bimoan/Desktop/bibitnomic-api/server.js:3
var { buildSchema } = require("graphql");
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3
这是我的server.js
var express = require("express");
var express_graphql = require("express-graphql");
var { buildSchema } = require("graphql");
// GraphQL schema
var schema = buildSchema(`
type Query {
message: String,
User: String
}
`);
// Root resolver
var root = {
message: () => "Hello World!",
User: () => " Bimo ANugrah"
};
// Create an express server and a GraphQL endpoint
var app = express();
app.use(
"/graphql",
express_graphql({
schema: schema,
rootValue: root,
graphiql: true
})
);
app.listen(4000, () =>
console.log("Express GraphQL Server Now Running On localhost:4000/graphql")
);
我的代码错了? 我没有改变什么以及为什么会发生这种情况?任何人都可以帮助我吗?