Mirror: The spec-compliant minimum of client-side GraphQL.
1<div align="center">
2 <h2>@0no-co/graphql.web</h2>
3 <strong>The spec-compliant minimum of client-side GraphQL.</strong>
4 <br />
5 <br />
6 <a href="https://github.com/0no-co/graphql.web/actions/workflows/release.yml">
7 <img alt="CI Status" src="https://github.com/0no-co/graphql.web/actions/workflows/release.yml/badge.svg?branch=main" />
8 </a>
9 <a href="https://npmjs.com/package/@0no-co/graphql.web">
10 <img alt="Bundlesize" src="https://deno.bundlejs.com/?q=@0no-co/graphql.web&badge" />
11 </a>
12 <a href="https://urql.dev/discord">
13 <img alt="Discord" src="https://img.shields.io/discord/1082378892523864074?color=7389D8&label&logo=discord&logoColor=ffffff" />
14 </a>
15 <br />
16 <br />
17</div>
18
19`@0no-co/graphql.web` is a utility library, aiming to provide the minimum of
20functions that typical GraphQL clients need and would usually import from
21`graphql`, e.g. a GraphQL query parser, printer, and visitor.
22
23While its goal isn’t to be an exact match to [the GraphQL.js
24API](https://graphql.org/graphql-js/graphql/) it aims to remain API- and
25type-compatible where possible and necessary. However, its goal is to provide
26the smallest implementation for common GraphQL utilities that are still either
27spec-compliant or compatible with GraphQL.js’ implementation.
28
29> **Note:** If you’re instead looking for a drop-in replacement for the
30> `graphql` package that you can just alias into your web apps, read more about
31> the [`graphql-web-lite` project](https://github.com/0no-co/graphql-web-lite),
32> which uses this library to shim the `graphql` package.
33
34[`@urql/core`](https://github.com/urql-graphql/urql) depends on this package to
35power its GraphQL query parsing and printing. **If you’re using `@urql/core@^4`
36you’re already using this library! ✨**
37
38### Overview
39
40`@0no-co/graphql.web` aims to provide a minimal set of exports to implement
41client-side GraphQL utilities, mostly including parsing, printing, and visiting
42the GraphQL AST, and the `GraphQLError` class.
43
44Currently, `graphql.web` compresses to under 4kB and doesn’t regress on
45GraphQL.js’ performance when parsing, printing, or visiting the AST.
46
47For all primary APIs we aim to hit 100% test coverage and match the output,
48types, and API compatibility of GraphQL.js, including — as far as possible
49— TypeScript type compatibility of the AST types with the currently stable
50version of GraphQL.js.
51
52### API
53
54Currently, only a select few exports are provided — namely, the ones listed here
55are used in `@urql/core`, and we expect them to be common in all client-side
56GraphQL applications.
57
58| Export | Description | Links |
59| --------------------- | ------------------------------------------------------------------ | -------------------------- |
60| `parse` | A tiny (but compliant) GraphQL query language parser. | [Source](./src/parser.ts) |
61| `print` | A (compliant) GraphQL query language printer. | [Source](./src/printer.ts) |
62| `visit` | A recursive reimplementation of GraphQL.js’ visitor. | [Source](./src/printer.ts) |
63| `Kind` | The GraphQL.js’ `Kind` enum, containing supported `ASTNode` kinds. | [Source](./src/kind.ts) |
64| `GraphQLError` | `GraphQLError` stripped of source/location debugging. | [Source](./src/kind.ts) |
65| `valueFromASTUntyped` | Coerces AST values into JS values. | [Source](./src/values.ts) |
66
67The stated goals of any reimplementation are:
68
691. Not to implement any execution or type system parts of the GraphQL
70 specification.
712. To adhere to GraphQL.js’ types and APIs as much as possible.
723. Not to implement or expose any rarely used APIs or properties of the
73 GraphQL.js library.
744. To provide a minimal and maintainable subset of GraphQL.js utilities.
75
76Therefore, while we can foresee implementing APIs that are entirely separate and
77unrelated to the GraphQL.js library in the future, for now the stated goals are
78designed to allow this library to be used by GraphQL clients, like
79[`@urql/core`](https://github.com/urql-graphql/urql).