graphql-js
A reference implementation of GraphQL for JavaScript
Official JavaScript implementation of GraphQL, a query language that lets clients request exactly the data they need from a server in a single query.
GraphQL.js is the official JavaScript reference implementation of GraphQL, the query language for APIs originally created by Facebook. GraphQL itself is a way for client applications to ask a server for exactly the data they need — no more, no less — in a single request. Rather than calling multiple different REST endpoints and stitching responses together, a GraphQL client sends one query describing the exact shape of data it wants, and the server responds with just that structure.
This library is the JavaScript/TypeScript engine that makes that possible on the server side. Using it, a developer first defines a "type schema" — a description of all the data types their application exposes and how they relate to each other. The README demonstrates this with a minimal example: a schema with a single "hello" field that returns the string "world." Once the schema is defined, the library handles parsing incoming GraphQL queries, validating them against the schema (catching errors like requesting a field that does not exist), and executing them by calling "resolver" functions that retrieve or compute the actual data.
GraphQL.js is a general-purpose library that works both in Node.js server environments and in the browser. Higher-level GraphQL server frameworks (like Apollo Server) are built on top of it. You would interact with GraphQL.js directly when building a custom GraphQL server or when you need low-level control; most application developers use it indirectly through a higher-level framework. It is distributed as an npm package and is written in TypeScript.
Where it fits
- Build a custom GraphQL server that validates queries and executes resolver functions to return exactly the data clients request.
- Add GraphQL support to a Node.js or browser application without relying on a higher-level framework like Apollo Server.
- Define a type schema describing your application's data types and relationships, then parse and validate incoming GraphQL queries against it.
- Integrate GraphQL into an existing API to let clients fetch multiple related resources in a single request instead of making multiple REST calls.