Mirror: The spec-compliant minimum of client-side GraphQL.

Add initial template test

Changed files
+796 -1
src
__tests__
+4
package.json
···
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-tsdoc": "^0.2.17",
+
"graphql": "^16.6.0",
"husky-v4": "^4.3.8",
"lint-staged": "^13.2.0",
"npm-run-all": "^4.1.5",
···
"terser": "^5.16.6",
"typescript": "^5.0.2",
"vitest": "^0.29.3"
+
},
+
"publishConfig": {
+
"access": "public"
}
}
+2 -1
pnpm-lock.yaml
···
eslint-config-prettier: ^8.7.0
eslint-plugin-prettier: ^4.2.1
eslint-plugin-tsdoc: ^0.2.17
+
graphql: ^16.6.0
husky-v4: ^4.3.8
lint-staged: ^13.2.0
npm-run-all: ^4.1.5
···
eslint-config-prettier: 8.7.0_eslint@8.36.0
eslint-plugin-prettier: 4.2.1_eqzx3hpkgx5nnvxls3azrcc7dm
eslint-plugin-tsdoc: 0.2.17
+
graphql: 16.6.0
husky-v4: 4.3.8
lint-staged: 13.2.0
npm-run-all: 4.1.5
···
/graphql/16.6.0:
resolution: {integrity: sha512-KPIBPDlW7NxrbT/eh4qPXz5FiFdL5UbaA0XUNz2Rp3Z3hqBSkbj0GVjwFDztsWVauZUWsbKHgMg++sk8UX0bkw==}
engines: {node: ^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0}
-
dev: false
/hard-rejection/2.1.0:
resolution: {integrity: sha512-VIZB+ibDhx7ObhAe7OVtoEbuP4h/MuOTHJ+J8h/eBXotJYl0fBgR72xDFCKgIh22OJZIOVNxBMWuhAr10r8HdA==}
+779
src/__tests__/__snapshots__/parser.test.ts.snap
···
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
+
+
exports[`parse > parses the kitchen sink query 1`] = `
+
{
+
"definitions": [
+
{
+
"directives": [
+
{
+
"arguments": [],
+
"kind": "Directive",
+
"name": {
+
"kind": "Name",
+
"value": "onQuery",
+
},
+
},
+
],
+
"kind": "OperationDefinition",
+
"name": {
+
"kind": "Name",
+
"value": "queryName",
+
},
+
"operation": "query",
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": {
+
"kind": "Name",
+
"value": "whoever123is",
+
},
+
"arguments": [
+
{
+
"kind": "Argument",
+
"name": {
+
"kind": "Name",
+
"value": "id",
+
},
+
"value": {
+
"kind": "ListValue",
+
"values": [
+
{
+
"kind": "FloatValue",
+
"value": "123",
+
},
+
{
+
"kind": "FloatValue",
+
"value": "456",
+
},
+
],
+
},
+
},
+
],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "node",
+
},
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "id",
+
},
+
"selectionSet": undefined,
+
},
+
{
+
"directives": [],
+
"kind": "FragmentSpread",
+
"name": {
+
"kind": "Name",
+
"value": "on",
+
},
+
},
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [
+
{
+
"arguments": [],
+
"kind": "Directive",
+
"name": {
+
"kind": "Name",
+
"value": "onInlineFragment",
+
},
+
},
+
],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "User",
+
},
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "field2",
+
},
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "id",
+
},
+
"selectionSet": undefined,
+
},
+
{
+
"alias": {
+
"kind": "Name",
+
"value": "alias",
+
},
+
"arguments": [
+
{
+
"kind": "Argument",
+
"name": {
+
"kind": "Name",
+
"value": "first",
+
},
+
"value": {
+
"kind": "FloatValue",
+
"value": "10",
+
},
+
},
+
{
+
"kind": "Argument",
+
"name": {
+
"kind": "Name",
+
"value": "after",
+
},
+
"value": {
+
"kind": "Variable",
+
"name": {
+
"kind": "Name",
+
"value": "foo",
+
},
+
},
+
},
+
],
+
"directives": [
+
{
+
"arguments": [
+
{
+
"kind": "Argument",
+
"name": {
+
"kind": "Name",
+
"value": "if",
+
},
+
"value": {
+
"kind": "Variable",
+
"name": {
+
"kind": "Name",
+
"value": "foo",
+
},
+
},
+
},
+
],
+
"kind": "Directive",
+
"name": {
+
"kind": "Name",
+
"value": "include",
+
},
+
},
+
],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "field1",
+
},
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "id",
+
},
+
"selectionSet": undefined,
+
},
+
{
+
"directives": [
+
{
+
"arguments": [],
+
"kind": "Directive",
+
"name": {
+
"kind": "Name",
+
"value": "onFragmentSpread",
+
},
+
},
+
],
+
"kind": "FragmentSpread",
+
"name": {
+
"kind": "Name",
+
"value": "frag",
+
},
+
},
+
],
+
},
+
},
+
],
+
},
+
},
+
],
+
},
+
},
+
{
+
"directives": [
+
{
+
"arguments": [
+
{
+
"kind": "Argument",
+
"name": {
+
"kind": "Name",
+
"value": "unless",
+
},
+
"value": {
+
"kind": "Variable",
+
"name": {
+
"kind": "Name",
+
"value": "foo",
+
},
+
},
+
},
+
],
+
"kind": "Directive",
+
"name": {
+
"kind": "Name",
+
"value": "skip",
+
},
+
},
+
],
+
"kind": "InlineFragment",
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "id",
+
},
+
"selectionSet": undefined,
+
},
+
],
+
},
+
"typeCondition": undefined,
+
},
+
{
+
"directives": [],
+
"kind": "InlineFragment",
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "id",
+
},
+
"selectionSet": undefined,
+
},
+
],
+
},
+
"typeCondition": undefined,
+
},
+
],
+
},
+
},
+
],
+
},
+
"variableDefinitions": [
+
{
+
"defaultValue": undefined,
+
"directives": [],
+
"kind": "VariableDefinition",
+
"type": {
+
"kind": "NamedType",
+
"name": {
+
"kind": "Name",
+
"value": "ComplexType",
+
},
+
},
+
"variable": {
+
"kind": "Variable",
+
"name": {
+
"kind": "Name",
+
"value": "foo",
+
},
+
},
+
},
+
{
+
"defaultValue": {
+
"kind": "EnumValue",
+
"value": "MOBILE",
+
},
+
"directives": [],
+
"kind": "VariableDefinition",
+
"type": {
+
"kind": "NamedType",
+
"name": {
+
"kind": "Name",
+
"value": "Site",
+
},
+
},
+
"variable": {
+
"kind": "Variable",
+
"name": {
+
"kind": "Name",
+
"value": "site",
+
},
+
},
+
},
+
],
+
},
+
{
+
"directives": [
+
{
+
"arguments": [],
+
"kind": "Directive",
+
"name": {
+
"kind": "Name",
+
"value": "onMutation",
+
},
+
},
+
],
+
"kind": "OperationDefinition",
+
"name": {
+
"kind": "Name",
+
"value": "likeStory",
+
},
+
"operation": "mutation",
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [
+
{
+
"kind": "Argument",
+
"name": {
+
"kind": "Name",
+
"value": "story",
+
},
+
"value": {
+
"kind": "FloatValue",
+
"value": "123",
+
},
+
},
+
],
+
"directives": [
+
{
+
"arguments": [],
+
"kind": "Directive",
+
"name": {
+
"kind": "Name",
+
"value": "onField",
+
},
+
},
+
],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "like",
+
},
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "story",
+
},
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [
+
{
+
"arguments": [],
+
"kind": "Directive",
+
"name": {
+
"kind": "Name",
+
"value": "onField",
+
},
+
},
+
],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "id",
+
},
+
"selectionSet": undefined,
+
},
+
],
+
},
+
},
+
],
+
},
+
},
+
],
+
},
+
"variableDefinitions": [],
+
},
+
{
+
"directives": [
+
{
+
"arguments": [],
+
"kind": "Directive",
+
"name": {
+
"kind": "Name",
+
"value": "onSubscription",
+
},
+
},
+
],
+
"kind": "OperationDefinition",
+
"name": {
+
"kind": "Name",
+
"value": "StoryLikeSubscription",
+
},
+
"operation": "subscription",
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [
+
{
+
"kind": "Argument",
+
"name": {
+
"kind": "Name",
+
"value": "input",
+
},
+
"value": {
+
"kind": "Variable",
+
"name": {
+
"kind": "Name",
+
"value": "input",
+
},
+
},
+
},
+
],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "storyLikeSubscribe",
+
},
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "story",
+
},
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "likers",
+
},
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "count",
+
},
+
"selectionSet": undefined,
+
},
+
],
+
},
+
},
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "likeSentence",
+
},
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "text",
+
},
+
"selectionSet": undefined,
+
},
+
],
+
},
+
},
+
],
+
},
+
},
+
],
+
},
+
},
+
],
+
},
+
"variableDefinitions": [
+
{
+
"defaultValue": undefined,
+
"directives": [],
+
"kind": "VariableDefinition",
+
"type": {
+
"kind": "NamedType",
+
"name": {
+
"kind": "Name",
+
"value": "StoryLikeSubscribeInput",
+
},
+
},
+
"variable": {
+
"kind": "Variable",
+
"name": {
+
"kind": "Name",
+
"value": "input",
+
},
+
},
+
},
+
],
+
},
+
{
+
"directives": [
+
{
+
"arguments": [],
+
"kind": "Directive",
+
"name": {
+
"kind": "Name",
+
"value": "onFragmentDefinition",
+
},
+
},
+
],
+
"kind": "FragmentDefinition",
+
"name": {
+
"kind": "Name",
+
"value": "frag",
+
},
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [
+
{
+
"kind": "Argument",
+
"name": {
+
"kind": "Name",
+
"value": "size",
+
},
+
"value": {
+
"kind": "Variable",
+
"name": {
+
"kind": "Name",
+
"value": "site",
+
},
+
},
+
},
+
{
+
"kind": "Argument",
+
"name": {
+
"kind": "Name",
+
"value": "bar",
+
},
+
"value": {
+
"kind": "FloatValue",
+
"value": "12",
+
},
+
},
+
{
+
"kind": "Argument",
+
"name": {
+
"kind": "Name",
+
"value": "obj",
+
},
+
"value": {
+
"fields": [
+
{
+
"kind": "ObjectField",
+
"name": {
+
"kind": "Name",
+
"value": "key",
+
},
+
"value": {
+
"block": false,
+
"kind": "StringValue",
+
"value": "value",
+
},
+
},
+
{
+
"kind": "ObjectField",
+
"name": {
+
"kind": "Name",
+
"value": "block",
+
},
+
"value": {
+
"block": true,
+
"kind": "StringValue",
+
"value": "block string uses \\\\\\"\\"\\"",
+
},
+
},
+
],
+
"kind": "ObjectValue",
+
},
+
},
+
],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "foo",
+
},
+
"selectionSet": undefined,
+
},
+
],
+
},
+
"typeCondition": {
+
"kind": "NamedType",
+
"name": {
+
"kind": "Name",
+
"value": "Friend",
+
},
+
},
+
},
+
{
+
"directives": [],
+
"kind": "OperationDefinition",
+
"name": {
+
"kind": "Name",
+
"value": "teeny",
+
},
+
"operation": "query",
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [
+
{
+
"kind": "Argument",
+
"name": {
+
"kind": "Name",
+
"value": "truthy",
+
},
+
"value": {
+
"kind": "BooleanValue",
+
"value": true,
+
},
+
},
+
{
+
"kind": "Argument",
+
"name": {
+
"kind": "Name",
+
"value": "falsey",
+
},
+
"value": {
+
"kind": "BooleanValue",
+
"value": false,
+
},
+
},
+
{
+
"kind": "Argument",
+
"name": {
+
"kind": "Name",
+
"value": "nullish",
+
},
+
"value": {
+
"kind": "NullValue",
+
},
+
},
+
],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "unnamed",
+
},
+
"selectionSet": undefined,
+
},
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "query",
+
},
+
"selectionSet": undefined,
+
},
+
],
+
},
+
"variableDefinitions": [],
+
},
+
{
+
"directives": [],
+
"kind": "OperationDefinition",
+
"name": {
+
"kind": "Name",
+
"value": "tiny",
+
},
+
"operation": "query",
+
"selectionSet": {
+
"kind": "SelectionSet",
+
"selections": [
+
{
+
"alias": undefined,
+
"arguments": [],
+
"directives": [],
+
"kind": "Field",
+
"name": {
+
"kind": "Name",
+
"value": "__typename",
+
},
+
"selectionSet": undefined,
+
},
+
],
+
},
+
"variableDefinitions": [],
+
},
+
],
+
"kind": "Document",
+
}
+
`;
+11
src/__tests__/parser.test.ts
···
+
import { describe, it, expect } from 'vitest';
+
import { readFileSync } from 'fs';
+
+
import { parse } from '../parser';
+
+
describe('parse', () => {
+
it('parses the kitchen sink query', () => {
+
const sink = readFileSync(__dirname + '/../../benchmark/kitchen_sink.graphql', { encoding: 'utf8' });
+
expect(parse(sink)).toMatchSnapshot();
+
})
+
});