Skip to content

Error: Expected undefined to be a GraphQL schema. #620

@tykwon97

Description

@tykwon97

An error continues to occur while practicing the graphql example. I don't know the cause.
I'd appreciate it if you could help me😀

const { graphql, buildSchema } = require("graphql")

const schema = buildSchema(`
  type Query {
    hello: String,
    nodejs: Int
  }
`);

const root = { 
    hello: () => 'Hello world!' ,
    nodejs: () => 20 ,
};

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

The error message is as follows.

(node:20348) UnhandledPromiseRejectionWarning: Error: Expected undefined to be a GraphQL schema.
    at assertSchema (C:\study\JavaScript\Node\GraphQL\node_modules\graphql\type\schema.js:37:11)
    at validateSchema (C:\study\JavaScript\Node\GraphQL\node_modules\graphql\type\validate.js:34:28)
    at graphqlImpl (C:\study\JavaScript\Node\GraphQL\node_modules\graphql\graphql.js:60:64)
    at C:\study\JavaScript\Node\GraphQL\node_modules\graphql\graphql.js:23:43
    at new Promise (<anonymous>)
    at graphql (C:\study\JavaScript\Node\GraphQL\node_modules\graphql\graphql.js:23:10)
    at Object.<anonymous> (C:\study\JavaScript\Node\GraphQL\start.js:16:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:20348) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:20348) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions