Skip to content

The instructions at "Getting Started With GraphQL.js" are not working #1168

Closed
@fskuteken

Description

@fskuteken

Description

The instructions at the page Getting Started With GraphQL.js didn't work for me.
Even though the page mentions Node v6, I expected that it should work on more recent versions as well.

Steps to Reproduce

Follow the instructions at https://graphql.org/graphql-js/:

  1. npm init
  2. npm install graphql --save
  3. Create the server.js file
var { graphql, buildSchema } = require('graphql');

// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
  type Query {
    hello: String
  }
`);

// The root provides a resolver function for each API endpoint
var root = {
  hello: () => {
    return 'Hello world!';
  },
};

// Run the GraphQL query '{ hello }' and print out the response
graphql(schema, '{ hello }', root).then((response) => {
  console.log(response);
});
  1. Run node server.js

Expected Result

{ data: { hello: 'Hello world!' } }

Actual Result

UnhandledPromiseRejectionWarning: Error: Expected undefined to be a GraphQL schema.

Additional Context

The installed package version was "graphql": "^16.0.1".
The node version I used was v14.17.0.

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