Query Language ⭐ 19k stars
Implementación de referencia de GraphQL en JavaScript para entornos Node.js.
frontend-desarrollo (regla: solo catálogo de las 66 · versiones por ERR/MEJ)
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);
Dos casos de uso comunes implementados con esta librería.
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);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);| Categoría | Query Language |
|---|---|
| Stars (GitHub) | ⭐ 19k |
| Sitio oficial | https://graphql.org/graphql-js/ |
| GitHub | https://github.com/graphql/graphql-js |
| Instalación | npm i graphql |
| Relacionadas | Apollo Server · Relay · express-graphql |
C:\Users\TUF\Documents\librerías\local\ antes de descargar.
Volver al índice de los 66 estudios.