Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
GraphQL - problem with the code from the tutorial page, it pops up an error "Expected undefined to be a GraphQL schema."

I try to learn GraphQL. I wanted to try out the code that is in the Getting Started With GraphQL.js section in the graphql.org. I created a server.js file like this page says: https://graphql.org/graphql-js/

I followed instructions like:

npm init
npm install graphql --save

The package.json file looks like this:

{
  "name": "graphql",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "graphql": "^16.0.1"
  }
}

The server.js file I created looks exactly like the one from the page (it was copied):

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);
});

But after using the node server.js command (as written on the page) in the terminal, I get this error:

node_modules\graphql\type\schema.js:35
    throw new Error(
          ^

Error: Expected undefined to be a GraphQL schema.
    at assertSchema (F:\GraphQL\node_modules\graphql\type\schema.js:35:11)
    at validateSchema (F:\GraphQL\node_modules\graphql\type\validate.js:34:28)
    at graphqlImpl (F:\GraphQL\node_modules\graphql\graphql.js:52:64)
    at F:\GraphQL\node_modules\graphql\graphql.js:21:43
    at new Promise (<anonymous>)
    at graphql (F:\GraphQL\node_modules\graphql\graphql.js:21:10)
    at Object.<anonymous> (F:\GraphQL\server.js:18:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)

Does anyone know what the problem is? Maybe I am missing some package? Or the code given on the page is wrong? Please help me, thank you in advance for any answer.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda