Mirror: The spec-compliant minimum of client-side GraphQL.
1import { describe, bench } from 'vitest';
2
3import * as graphql15 from 'graphql15';
4import * as graphql16 from 'graphql16';
5import * as graphql17 from 'graphql17';
6
7import kitchenSinkAST from './fixtures/kitchen_sink.json';
8import { visit } from '../visitor';
9
10describe('visit (kitchen sink AST)', () => {
11 bench('@0no-co/graphql.web', () => {
12 visit(kitchenSinkAST, {
13 Field: formatNode,
14 InlineFragment: formatNode,
15 });
16 });
17
18 bench('graphql@15', () => {
19 graphql15.visit(kitchenSinkAST, {
20 Field: formatNode,
21 InlineFragment: formatNode,
22 });
23 });
24
25 bench('graphql@16', () => {
26 graphql16.visit(kitchenSinkAST, {
27 Field: formatNode,
28 InlineFragment: formatNode,
29 });
30 });
31
32 bench('graphql@17', () => {
33 graphql17.visit(kitchenSinkAST, {
34 Field: formatNode,
35 InlineFragment: formatNode,
36 });
37 });
38});
39
40function formatNode(node: any) {
41 if (!node.selectionSet) return node;
42 for (const selection of node.selectionSet.selections)
43 if (selection.kind === 'Field' && selection.name.value === '__typename' && !selection.alias)
44 return node;
45
46 return {
47 ...node,
48 selectionSet: {
49 ...node.selectionSet,
50 selections: [
51 ...node.selectionSet.selections,
52 {
53 kind: 'Field',
54 name: {
55 kind: 'Name',
56 value: '__typename',
57 },
58 },
59 ],
60 },
61 };
62}