最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Express中的graphql错误,节点js

运维笔记admin12浏览0评论

Express中的graphql错误,节点js

Express中的graphql错误,节点js

我正在尝试在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的论据应该是字符串。 (注意back-ticks)

var schema=buildSchema(`
    type Query {
        name:String
    }
`);
发布评论

评论列表(0)

  1. 暂无评论