我正在尝试在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,
}));
buildSchema
的参数应为字符串。(注意背键)
var schema=buildSchema(`
type Query {
name:String
}
`);
缺少 =
!
要使用您需要执行此操作的类型:
type Query = {
//Variables and types goes here:
//ex: username: string
}
希望我有帮助