Express 中的 graphql 错误,节点 js

Error in graphql in Express , node js

我正在尝试 运行 Express 中的 graphql 服务器。但它抛出以下错误。

var graphqlHTTP = require('express-graphql'); // express graphql
var { buildSchema } = require('graphql');  // graphql
var schema=buildSchema(
    type Query {
        name:String});

var classifyRoot={
     name:()=>{
        classified.find({name:"shoes"},function(err,classified){
            //res.render("card",{classifieds:classifieds});
            return classified.name;
        });
    },};
app.use('/graphql', graphqlHTTP({
  schema: schema,
  rootValue: classifyRoot,
  graphiql: true,
}));

缺少 = !

要使用类型,您需要这样做:

type Query = {
  //Variables and types goes here:
  //ex:  username: string
}

希望我帮到了你

buildSchema 的参数应该是字符串。 (注意 back-ticks

var schema=buildSchema(`
    type Query {
        name:String
    }
`);