1

I'm trying to run graphql server in express. But it throws following error.

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 Answers2

1

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

var schema=buildSchema(`
    type Query {
        name:String
    }
`);
Bless
  • 5,052
  • 2
  • 40
  • 44
-1

Its missing the = !

To use types you need to do this:

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

Hope i have helped