Error: Expected undefined to be a GraphQL schema on hello world

Viewed 626

Below is my simple graph ql hellow rold code which i directly used from graphql official docs toget started, somehow its giving me error: Expected undefined to be a GraphQL schema on hello world


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

var root = { hello: () => "Hello world!" };

graphql(schema, "{ hello }", root).then((response) => {
  console.log(response);
});
1 Answers

Seems the documentation is wrong. It needs to be updated, Can you try updating the code like below?

From

graphql(schema, "{ hello }", root).then((response) => {
  console.log(response);
});

To

graphql({
    schema: schema, 
    source: '{ hello }', 
    rootValue: root
}).then((response) => {
  console.log(response);
});
Related