Intento aprender GraphQL. Quería probar el código que se encuentra en la sección Primeros pasos con GraphQL.js en graphql.org. Creé un archivo server.js como dice esta página: https://graphql.org/graphql-js/
Seguí instrucciones como :
npm init npm install graphql --saveEl archivo package.json se ve así:
{ "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" } }El archivo server.js que creé se ve exactamente como el de la página (fue copiado):
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); });Pero después de usar el comando node server.js (como está escrito en la página) en la terminal, aparece este 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)Alguien sabe cual es el problema? ¿Quizás me estoy perdiendo algún paquete? ¿O el código dado en la página es incorrecto? Por favor ayúdenme, gracias de antemano por cualquier respuesta.