1

我正在尝试以 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,
}));
4

2 回答 2

1

的参数buildSchema应该是字符串。(注意反引号

var schema=buildSchema(`
    type Query {
        name:String
    }
`);
于 2017-12-18T06:17:03.433 回答
-1

它缺少=

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

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

希望我有帮助

于 2017-12-17T13:45:40.133 回答