Express中的graphql错误,节点js

问题描述 投票:1回答:2

我正在尝试在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,
}));
node.js express graphql express-graphql
2个回答
1
投票

buildSchema的论据应该是字符串。 (注意back-ticks

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

-1
投票

它错过了=

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

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

希望我有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.