Express中的graphql错误,节点js

时间:2017-12-17 13:38:26

标签: node.js express graphql express-graphql

我正在尝试在express中运行graphql server。但它会引发跟随错误。

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,
}));

2 个答案:

答案 0 :(得分:1)

The argument for buildSchema should be string. (Notice the back-ticks)

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

答案 1 :(得分:-1)

它错过了=

要使用您需要执行此操作的类型:

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

希望我帮助过