Estudio de GraphQL.js

Query Language ⭐ 19k stars
Implementación de referencia de GraphQL en JavaScript para entornos Node.js.

🤖 Skill de implementación: frontend-desarrollo (regla: solo catálogo de las 66 · versiones por ERR/MEJ)

1 · Características

2 · Casos de uso

3 · Script minimalista

Instalación: npm i graphql

import { buildSchema, graphql } from 'graphql';
const s = buildSchema('type Query { hola: String }');
graphql({ schema: s, source: '{ hola }', rootValue: { hola: 'mundo' } }).then(console.log);

4 · Casos de uso (implementación real)

Dos casos de uso comunes implementados con esta librería.

1. Query con schema

Define un tipo y resuelve una consulta.

import { buildSchema, graphql } from 'graphql';

const schema = buildSchema(`
  type Query { hola(nombre: String): String }
`);
const root = { hola: ({ nombre }) => 'Hola ' + (nombre ?? 'mundo') };

graphql({ schema, source: '{ hola(nombre: "Ana") }', rootValue: root }).then(console.log);
🔁 Cómo funciona: `buildSchema` define el SDL y `rootValue` implementa los resolvers.

2. Mutation

Agrega un elemento y devuelve el resultado.

import { buildSchema, graphql } from 'graphql';

const schema = buildSchema(`
  type Query { items: [String] }
  type Mutation { agregar(texto: String): [String] }
`);
const items = [];
const root = {
  items: () => items,
  agregar: ({ texto }) => { items.push(texto); return items; },
};
graphql({ schema, source: 'mutation { agregar(texto: "nuevo") }', rootValue: root }).then(console.log);
🔁 Cómo funciona: Las `Mutation` cambian datos y devuelven el estado; las `Query` solo leen.

5 · Referencia

CategoríaQuery Language
Stars (GitHub)⭐ 19k
Sitio oficialhttps://graphql.org/graphql-js/
GitHubhttps://github.com/graphql/graphql-js
Instalaciónnpm i graphql
RelacionadasApollo Server · Relay · express-graphql
📦 Regla de librerías (local primero): revisar C:\Users\TUF\Documents\librerías\local\ antes de descargar. Volver al índice de los 66 estudios.