我正在尝试在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,
}));
答案 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
}
希望我帮助过