···11+<div align="center">
22+ <h2 align="center">graphql-web-lite</h2>
33+ <p align="center"><strong>The small sibling of the <code>graphql</code> package, slimmed down for client-side libraries</strong></p>
44+ <br />
55+ <a href="https://npmjs.com/package/graphql-web-lite">
66+ <img alt="NPM Version" src="https://img.shields.io/npm/v/graphql-web-lite.svg" />
77+ </a>
88+ <a href="https://npmjs.com/package/use-interactions">
99+ <img alt="License" src="https://img.shields.io/npm/l/graphql-web-lite.svg" />
1010+ </a>
1111+ <a href="https://bundlephobia.com/result?p=graphql-web-lite">
1212+ <img alt="Minified gzip size" src="https://img.shields.io/bundlephobia/minzip/graphql-web-lite.svg?label=gzip%20size" />
1313+ </a>
1414+ <br />
1515+ <br />
1616+</div>
1717+1818+The `graphql` package serves two purposes in being the reference implementation of the
1919+[GraphQL specification](https://spec.graphql.org/) and being used as the shared toolkit
2020+for implementing GraphQL in client-side and server-side JavaScript applications. This
2121+can cause bloat for client-side apps, where we'd rather choose lower bundlesize impact
2222+over fidelity.
2323+2424+`graphql-web-lite` is an **experimental** library, providing an alias package that can
2525+be swapped in for the standard `graphql` package in client-side applications.
2626+It aims to reduce the size of imports that are in common use by GraphQL clients and
2727+users, while still providing most `graphql` exports that are used in other contexts.
2828+2929+## Installation
3030+3131+`graphql-web-lite` mirrors the folder structure of the regular `graphql` package and
3232+includes mostly the same files and imports as the `graphql` package, minus a couple
3333+that aren't commonly used for client-side GraphQL.
3434+This offers us several installation options, depending on how the package is aliased
3535+to the regular `"graphql"` import.
3636+3737+<details>
3838+<summary><strong>Installation with <code>package.json</code> aliases</strong></summary>
3939+4040+When your dependencies and `node_modules` folder isn't used by a _GraphQL server_ and
4141+only used by a _GraphQL clients_, you can use a quick and easy npm installation alias.
4242+In your `package.json` file you can define your `graphql` installation to use
4343+`graphql-web-lite` instead, which is supported by both Yarn and npm:
4444+4545+```diff
4646+{
4747+ "dependencies": {
4848+- "graphql": "^15.5.0"
4949++ "graphql": "npm:graphql-web-lite@^15.5.1000"
5050+ }
5151+}
5252+```
5353+5454+Alternatively, you can run an installation command to alias the package:<br />
5555+5656+```sh
5757+npm install --save graphql@npm:graphql-web-lite
5858+# or
5959+yarn add graphql@npm:graphql-web-lite
6060+```
6161+6262+When this isn't suitable — for instance, because the same dependencies are shared
6363+with an API or server-side GraphQL consumer, or you're working inside a monorepo —
6464+you can try one of the other aliasing techniques below.
6565+6666+</details>
6767+6868+<details>
6969+<summary><strong>Installation with Webpack aliases</strong></summary>
7070+7171+First, we'll need to install `graphql-web-lite` _alongside_ the regular `graphql`
7272+package.
7373+7474+```sh
7575+npm install --save graphql-web-lite
7676+# or
7777+yarn add graphql-web-lite
7878+```
7979+8080+To alias a package in Webpack, an entry must be added to your Webpack
8181+configuration's `resolve.alias` section. Depending on your implementation,
8282+the configuration may already contain some keys inside `resolve.alias`, and
8383+you'd want to add another entry for `"graphql"`.
8484+8585+```js
8686+const webpackConfig = {
8787+ // ...
8888+ resolve: {
8989+ alias: {
9090+ graphql: 'graphql-web-lite',
9191+ },
9292+ },
9393+};
9494+```
9595+9696+</details>
9797+9898+<details>
9999+<summary><strong>Installation with Next.js</strong></summary>
100100+101101+First, we'll need to install `graphql-web-lite` _alongside_ the regular `graphql`
102102+package.
103103+104104+```sh
105105+npm install --save graphql-web-lite
106106+# or
107107+yarn add graphql-web-lite
108108+```
109109+110110+In your [Next.js configuration file](https://nextjs.org/docs/api-reference/next.config.js/introduction),
111111+under `next.config.js`, you can add an additional `webpack()` function that is
112112+able to modify Next's Webpack configuration to add an alias for `graphql`.
113113+114114+```js
115115+module.exports = {
116116+ webpack(config, { isServer }) {
117117+ if (!isServer) {
118118+ config.resolve.alias = {
119119+ ...config.resolve.alias,
120120+ graphql: 'graphql-web-lite',
121121+ };
122122+ }
123123+ return config;
124124+ },
125125+};
126126+```
127127+128128+Here we're also ensuring that the alias isn't applied on the server-side, in case
129129+an API route is using `graphql` for a server-side GraphQL schema.
130130+131131+</details>
132132+133133+<details>
134134+<summary><strong>Installation with Rollup's alias plugin</strong></summary>
135135+136136+First, we'll need to install `graphql-web-lite` _alongside_ the regular `graphql`
137137+package.
138138+139139+```sh
140140+npm install --save graphql-web-lite
141141+# or
142142+yarn add graphql-web-lite
143143+```
144144+145145+In Rollup, the easiest way to add a new alias is to use `@rollup/plugin-alias`.
146146+We'll have to install this plugin and ensure that every import and deep import
147147+to `graphql` is aliased to `graphql-web-lite`.
148148+149149+Any Rollup-based build will fail when the import name of the package does not
150150+match the `name` field in the module's `package.json` file, so this step is
151151+necessary.
152152+153153+```js
154154+import alias from '@rollup/plugin-alias';
155155+156156+module.exports = {
157157+ plugins: [
158158+ alias({
159159+ entries: [{ find: 'graphql', replacement: 'graphql-web-lite' }],
160160+ }),
161161+ ],
162162+};
163163+```
164164+165165+</details>
166166+167167+<details>
168168+<summary><strong>Installation with Vite</strong></summary>
169169+170170+First, we'll need to install `graphql-web-lite` _alongside_ the regular `graphql`
171171+package.
172172+173173+```sh
174174+npm install --save graphql-web-lite
175175+# or
176176+yarn add graphql-web-lite
177177+```
178178+179179+In your [Vite configuration file](https://vitejs.dev/config/#config-file-resolving)
180180+you may add a new entry for its `resolve.alias` entries. This entry works the same
181181+as Rollup's alias plugin.
182182+183183+```js
184184+import { defineConfig } from 'vite';
185185+186186+export default defineConfig({
187187+ resolve: {
188188+ alias: {
189189+ graphql: 'graphql-web-lite',
190190+ },
191191+ },
192192+});
193193+```
194194+195195+Here we're also ensuring that the alias isn't applied on the server-side, in case
196196+an API route is using `graphql` for a server-side GraphQL schema.
197197+198198+</details>
199199+200200+<details>
201201+<summary><strong>Installation with Parcel</strong></summary>
202202+203203+First, we'll need to install `graphql-web-lite` _alongside_ the regular `graphql`
204204+package.
205205+206206+```sh
207207+npm install --save graphql-web-lite
208208+# or
209209+yarn add graphql-web-lite
210210+```
211211+212212+In Parcel, we can add an entry in our `package.json` file for an alias. Specifically,
213213+the `alias` property may contain an object that maps packages to their aliases.
214214+215215+```diff
216216+{
217217+ "alias": {
218218++ "graphql": "graphql-web-lite"
219219+ }
220220+}
221221+```
222222+223223+</details>
224224+225225+<details>
226226+<summary><strong>Installation with Jest's module mapping</strong></summary>
227227+228228+First, we'll need to install `graphql-web-lite` _alongside_ the regular `graphql`
229229+package.
230230+231231+```sh
232232+npm install --save graphql-web-lite
233233+# or
234234+yarn add graphql-web-lite
235235+```
236236+237237+Jest allows any module names to be remapped using regular expression-based
238238+mappings. In your Jest config you'll need to add an entry for `graphql` that
239239+remaps all imports and deep imports to `graphql-web-lite`.
240240+241241+```json
242242+{
243243+ "moduleNameMapper": {
244244+ "graphql(.*)": "graphql-web-lite$1"
245245+ }
246246+}
247247+```
248248+249249+</details>
250250+251251+## Impact & Changes
252252+253253+In short, most utilities, functions, and classes exported by the `graphql`
254254+package are only used for server-side GraphQL. Some of them have been removed
255255+in `graphql-web-lite` to discourage its server-side usage, and help bundlers
256256+exlude them if tree-shaking were to fail.
257257+258258+Most GraphQL clients rely on importing the parser, printer, visitor, and the
259259+`GraphQLError` class. These have all been modified to reduce their bundlesize
260260+impact and to remove any support for
261261+[GraphQL's schema language and type system](https://spec.graphql.org/June2018/#sec-Type-System).
262262+263263+Any debugging calls, development-time warnings, and other non-production code
264264+is also being transpiled away, and `process.env.NODE_ENV` has been compiled
265265+away.
266266+267267+<details>
268268+<summary><strong>Full List of Changes</strong></summary>
269269+270270+| Export | Changes | Notes |
271271+| -------------------------- | ----------- | ------------------------------------------------------------------- |
272272+| `getVisitFn` | _unchanged_ | n/a |
273273+| `visitInParallel` | _unchanged_ | n/a |
274274+| `BREAK` | _unchanged_ | n/a |
275275+| `visit` | _modified_ | works recursively and does not detect invalid AST nodes |
276276+| `print` | _modified_ | won't output any schema nodes and does not detect invalid AST nodes |
277277+| `printLocation` | _modified_ | won't output source snippets |
278278+| `printSourceLocation` | _modified_ | won't output source snippets |
279279+| `parse` | _modified_ | won't parse schema nodes or throw precise syntax errors |
280280+| `parseType` | _modified_ | won't throw precise syntax errors |
281281+| `parseValue` | _modified_ | won't throw precise syntax errors |
282282+| `GraphQLError` | _modified_ | doesn't handle locations and Error stacks |
283283+| `syntaxError` | _removed_ | n/a |
284284+| `printType` | _removed_ | n/a |
285285+| `printSchema` | _removed_ | n/a |
286286+| `printIntrospectionSchema` | _removed_ | n/a |
287287+| `lexicographicSortSchema` | _removed_ | n/a |
288288+| `isSchema` | _removed_ | n/a |
289289+| `isInterfaceType` | _removed_ | n/a |
290290+| `getDescription` | _removed_ | n/a |
291291+| `findDeprecatedUsages` | _removed_ | n/a |
292292+| `buildSchema` | _removed_ | n/a |
293293+| `buildASTSchema` | _removed_ | n/a |
294294+| `assertSchema` | _removed_ | n/a |
295295+| `assertInterfaceType` | _removed_ | n/a |
296296+| `assertCompositeType` | _removed_ | n/a |
297297+| `assertAbstractType` | _removed_ | n/a |
298298+| `TokenKind` | _removed_ | n/a |
299299+| `Token` | _removed_ | n/a |
300300+| `Lexer` | _removed_ | n/a |
301301+| `GraphQLUnionType` | _removed_ | n/a |
302302+| `GraphQLInterfaceType` | _removed_ | n/a |
303303+| `GraphQLInputObjectType` | _removed_ | n/a |
304304+305305+</details>