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

Add initial template test

+796 -1
+4
package.json
··· 74 74 "eslint-config-prettier": "^8.7.0", 75 75 "eslint-plugin-prettier": "^4.2.1", 76 76 "eslint-plugin-tsdoc": "^0.2.17", 77 + "graphql": "^16.6.0", 77 78 "husky-v4": "^4.3.8", 78 79 "lint-staged": "^13.2.0", 79 80 "npm-run-all": "^4.1.5", ··· 85 86 "terser": "^5.16.6", 86 87 "typescript": "^5.0.2", 87 88 "vitest": "^0.29.3" 89 + }, 90 + "publishConfig": { 91 + "access": "public" 88 92 } 89 93 }
+2 -1
pnpm-lock.yaml
··· 17 17 eslint-config-prettier: ^8.7.0 18 18 eslint-plugin-prettier: ^4.2.1 19 19 eslint-plugin-tsdoc: ^0.2.17 20 + graphql: ^16.6.0 20 21 husky-v4: ^4.3.8 21 22 lint-staged: ^13.2.0 22 23 npm-run-all: ^4.1.5 ··· 42 43 eslint-config-prettier: 8.7.0_eslint@8.36.0 43 44 eslint-plugin-prettier: 4.2.1_eqzx3hpkgx5nnvxls3azrcc7dm 44 45 eslint-plugin-tsdoc: 0.2.17 46 + graphql: 16.6.0 45 47 husky-v4: 4.3.8 46 48 lint-staged: 13.2.0 47 49 npm-run-all: 4.1.5 ··· 2110 2112 /graphql/16.6.0: 2111 2113 resolution: {integrity: sha512-KPIBPDlW7NxrbT/eh4qPXz5FiFdL5UbaA0XUNz2Rp3Z3hqBSkbj0GVjwFDztsWVauZUWsbKHgMg++sk8UX0bkw==} 2112 2114 engines: {node: ^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0} 2113 - dev: false 2114 2115 2115 2116 /hard-rejection/2.1.0: 2116 2117 resolution: {integrity: sha512-VIZB+ibDhx7ObhAe7OVtoEbuP4h/MuOTHJ+J8h/eBXotJYl0fBgR72xDFCKgIh22OJZIOVNxBMWuhAr10r8HdA==}
+779
src/__tests__/__snapshots__/parser.test.ts.snap
··· 1 + // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html 2 + 3 + exports[`parse > parses the kitchen sink query 1`] = ` 4 + { 5 + "definitions": [ 6 + { 7 + "directives": [ 8 + { 9 + "arguments": [], 10 + "kind": "Directive", 11 + "name": { 12 + "kind": "Name", 13 + "value": "onQuery", 14 + }, 15 + }, 16 + ], 17 + "kind": "OperationDefinition", 18 + "name": { 19 + "kind": "Name", 20 + "value": "queryName", 21 + }, 22 + "operation": "query", 23 + "selectionSet": { 24 + "kind": "SelectionSet", 25 + "selections": [ 26 + { 27 + "alias": { 28 + "kind": "Name", 29 + "value": "whoever123is", 30 + }, 31 + "arguments": [ 32 + { 33 + "kind": "Argument", 34 + "name": { 35 + "kind": "Name", 36 + "value": "id", 37 + }, 38 + "value": { 39 + "kind": "ListValue", 40 + "values": [ 41 + { 42 + "kind": "FloatValue", 43 + "value": "123", 44 + }, 45 + { 46 + "kind": "FloatValue", 47 + "value": "456", 48 + }, 49 + ], 50 + }, 51 + }, 52 + ], 53 + "directives": [], 54 + "kind": "Field", 55 + "name": { 56 + "kind": "Name", 57 + "value": "node", 58 + }, 59 + "selectionSet": { 60 + "kind": "SelectionSet", 61 + "selections": [ 62 + { 63 + "alias": undefined, 64 + "arguments": [], 65 + "directives": [], 66 + "kind": "Field", 67 + "name": { 68 + "kind": "Name", 69 + "value": "id", 70 + }, 71 + "selectionSet": undefined, 72 + }, 73 + { 74 + "directives": [], 75 + "kind": "FragmentSpread", 76 + "name": { 77 + "kind": "Name", 78 + "value": "on", 79 + }, 80 + }, 81 + { 82 + "alias": undefined, 83 + "arguments": [], 84 + "directives": [ 85 + { 86 + "arguments": [], 87 + "kind": "Directive", 88 + "name": { 89 + "kind": "Name", 90 + "value": "onInlineFragment", 91 + }, 92 + }, 93 + ], 94 + "kind": "Field", 95 + "name": { 96 + "kind": "Name", 97 + "value": "User", 98 + }, 99 + "selectionSet": { 100 + "kind": "SelectionSet", 101 + "selections": [ 102 + { 103 + "alias": undefined, 104 + "arguments": [], 105 + "directives": [], 106 + "kind": "Field", 107 + "name": { 108 + "kind": "Name", 109 + "value": "field2", 110 + }, 111 + "selectionSet": { 112 + "kind": "SelectionSet", 113 + "selections": [ 114 + { 115 + "alias": undefined, 116 + "arguments": [], 117 + "directives": [], 118 + "kind": "Field", 119 + "name": { 120 + "kind": "Name", 121 + "value": "id", 122 + }, 123 + "selectionSet": undefined, 124 + }, 125 + { 126 + "alias": { 127 + "kind": "Name", 128 + "value": "alias", 129 + }, 130 + "arguments": [ 131 + { 132 + "kind": "Argument", 133 + "name": { 134 + "kind": "Name", 135 + "value": "first", 136 + }, 137 + "value": { 138 + "kind": "FloatValue", 139 + "value": "10", 140 + }, 141 + }, 142 + { 143 + "kind": "Argument", 144 + "name": { 145 + "kind": "Name", 146 + "value": "after", 147 + }, 148 + "value": { 149 + "kind": "Variable", 150 + "name": { 151 + "kind": "Name", 152 + "value": "foo", 153 + }, 154 + }, 155 + }, 156 + ], 157 + "directives": [ 158 + { 159 + "arguments": [ 160 + { 161 + "kind": "Argument", 162 + "name": { 163 + "kind": "Name", 164 + "value": "if", 165 + }, 166 + "value": { 167 + "kind": "Variable", 168 + "name": { 169 + "kind": "Name", 170 + "value": "foo", 171 + }, 172 + }, 173 + }, 174 + ], 175 + "kind": "Directive", 176 + "name": { 177 + "kind": "Name", 178 + "value": "include", 179 + }, 180 + }, 181 + ], 182 + "kind": "Field", 183 + "name": { 184 + "kind": "Name", 185 + "value": "field1", 186 + }, 187 + "selectionSet": { 188 + "kind": "SelectionSet", 189 + "selections": [ 190 + { 191 + "alias": undefined, 192 + "arguments": [], 193 + "directives": [], 194 + "kind": "Field", 195 + "name": { 196 + "kind": "Name", 197 + "value": "id", 198 + }, 199 + "selectionSet": undefined, 200 + }, 201 + { 202 + "directives": [ 203 + { 204 + "arguments": [], 205 + "kind": "Directive", 206 + "name": { 207 + "kind": "Name", 208 + "value": "onFragmentSpread", 209 + }, 210 + }, 211 + ], 212 + "kind": "FragmentSpread", 213 + "name": { 214 + "kind": "Name", 215 + "value": "frag", 216 + }, 217 + }, 218 + ], 219 + }, 220 + }, 221 + ], 222 + }, 223 + }, 224 + ], 225 + }, 226 + }, 227 + { 228 + "directives": [ 229 + { 230 + "arguments": [ 231 + { 232 + "kind": "Argument", 233 + "name": { 234 + "kind": "Name", 235 + "value": "unless", 236 + }, 237 + "value": { 238 + "kind": "Variable", 239 + "name": { 240 + "kind": "Name", 241 + "value": "foo", 242 + }, 243 + }, 244 + }, 245 + ], 246 + "kind": "Directive", 247 + "name": { 248 + "kind": "Name", 249 + "value": "skip", 250 + }, 251 + }, 252 + ], 253 + "kind": "InlineFragment", 254 + "selectionSet": { 255 + "kind": "SelectionSet", 256 + "selections": [ 257 + { 258 + "alias": undefined, 259 + "arguments": [], 260 + "directives": [], 261 + "kind": "Field", 262 + "name": { 263 + "kind": "Name", 264 + "value": "id", 265 + }, 266 + "selectionSet": undefined, 267 + }, 268 + ], 269 + }, 270 + "typeCondition": undefined, 271 + }, 272 + { 273 + "directives": [], 274 + "kind": "InlineFragment", 275 + "selectionSet": { 276 + "kind": "SelectionSet", 277 + "selections": [ 278 + { 279 + "alias": undefined, 280 + "arguments": [], 281 + "directives": [], 282 + "kind": "Field", 283 + "name": { 284 + "kind": "Name", 285 + "value": "id", 286 + }, 287 + "selectionSet": undefined, 288 + }, 289 + ], 290 + }, 291 + "typeCondition": undefined, 292 + }, 293 + ], 294 + }, 295 + }, 296 + ], 297 + }, 298 + "variableDefinitions": [ 299 + { 300 + "defaultValue": undefined, 301 + "directives": [], 302 + "kind": "VariableDefinition", 303 + "type": { 304 + "kind": "NamedType", 305 + "name": { 306 + "kind": "Name", 307 + "value": "ComplexType", 308 + }, 309 + }, 310 + "variable": { 311 + "kind": "Variable", 312 + "name": { 313 + "kind": "Name", 314 + "value": "foo", 315 + }, 316 + }, 317 + }, 318 + { 319 + "defaultValue": { 320 + "kind": "EnumValue", 321 + "value": "MOBILE", 322 + }, 323 + "directives": [], 324 + "kind": "VariableDefinition", 325 + "type": { 326 + "kind": "NamedType", 327 + "name": { 328 + "kind": "Name", 329 + "value": "Site", 330 + }, 331 + }, 332 + "variable": { 333 + "kind": "Variable", 334 + "name": { 335 + "kind": "Name", 336 + "value": "site", 337 + }, 338 + }, 339 + }, 340 + ], 341 + }, 342 + { 343 + "directives": [ 344 + { 345 + "arguments": [], 346 + "kind": "Directive", 347 + "name": { 348 + "kind": "Name", 349 + "value": "onMutation", 350 + }, 351 + }, 352 + ], 353 + "kind": "OperationDefinition", 354 + "name": { 355 + "kind": "Name", 356 + "value": "likeStory", 357 + }, 358 + "operation": "mutation", 359 + "selectionSet": { 360 + "kind": "SelectionSet", 361 + "selections": [ 362 + { 363 + "alias": undefined, 364 + "arguments": [ 365 + { 366 + "kind": "Argument", 367 + "name": { 368 + "kind": "Name", 369 + "value": "story", 370 + }, 371 + "value": { 372 + "kind": "FloatValue", 373 + "value": "123", 374 + }, 375 + }, 376 + ], 377 + "directives": [ 378 + { 379 + "arguments": [], 380 + "kind": "Directive", 381 + "name": { 382 + "kind": "Name", 383 + "value": "onField", 384 + }, 385 + }, 386 + ], 387 + "kind": "Field", 388 + "name": { 389 + "kind": "Name", 390 + "value": "like", 391 + }, 392 + "selectionSet": { 393 + "kind": "SelectionSet", 394 + "selections": [ 395 + { 396 + "alias": undefined, 397 + "arguments": [], 398 + "directives": [], 399 + "kind": "Field", 400 + "name": { 401 + "kind": "Name", 402 + "value": "story", 403 + }, 404 + "selectionSet": { 405 + "kind": "SelectionSet", 406 + "selections": [ 407 + { 408 + "alias": undefined, 409 + "arguments": [], 410 + "directives": [ 411 + { 412 + "arguments": [], 413 + "kind": "Directive", 414 + "name": { 415 + "kind": "Name", 416 + "value": "onField", 417 + }, 418 + }, 419 + ], 420 + "kind": "Field", 421 + "name": { 422 + "kind": "Name", 423 + "value": "id", 424 + }, 425 + "selectionSet": undefined, 426 + }, 427 + ], 428 + }, 429 + }, 430 + ], 431 + }, 432 + }, 433 + ], 434 + }, 435 + "variableDefinitions": [], 436 + }, 437 + { 438 + "directives": [ 439 + { 440 + "arguments": [], 441 + "kind": "Directive", 442 + "name": { 443 + "kind": "Name", 444 + "value": "onSubscription", 445 + }, 446 + }, 447 + ], 448 + "kind": "OperationDefinition", 449 + "name": { 450 + "kind": "Name", 451 + "value": "StoryLikeSubscription", 452 + }, 453 + "operation": "subscription", 454 + "selectionSet": { 455 + "kind": "SelectionSet", 456 + "selections": [ 457 + { 458 + "alias": undefined, 459 + "arguments": [ 460 + { 461 + "kind": "Argument", 462 + "name": { 463 + "kind": "Name", 464 + "value": "input", 465 + }, 466 + "value": { 467 + "kind": "Variable", 468 + "name": { 469 + "kind": "Name", 470 + "value": "input", 471 + }, 472 + }, 473 + }, 474 + ], 475 + "directives": [], 476 + "kind": "Field", 477 + "name": { 478 + "kind": "Name", 479 + "value": "storyLikeSubscribe", 480 + }, 481 + "selectionSet": { 482 + "kind": "SelectionSet", 483 + "selections": [ 484 + { 485 + "alias": undefined, 486 + "arguments": [], 487 + "directives": [], 488 + "kind": "Field", 489 + "name": { 490 + "kind": "Name", 491 + "value": "story", 492 + }, 493 + "selectionSet": { 494 + "kind": "SelectionSet", 495 + "selections": [ 496 + { 497 + "alias": undefined, 498 + "arguments": [], 499 + "directives": [], 500 + "kind": "Field", 501 + "name": { 502 + "kind": "Name", 503 + "value": "likers", 504 + }, 505 + "selectionSet": { 506 + "kind": "SelectionSet", 507 + "selections": [ 508 + { 509 + "alias": undefined, 510 + "arguments": [], 511 + "directives": [], 512 + "kind": "Field", 513 + "name": { 514 + "kind": "Name", 515 + "value": "count", 516 + }, 517 + "selectionSet": undefined, 518 + }, 519 + ], 520 + }, 521 + }, 522 + { 523 + "alias": undefined, 524 + "arguments": [], 525 + "directives": [], 526 + "kind": "Field", 527 + "name": { 528 + "kind": "Name", 529 + "value": "likeSentence", 530 + }, 531 + "selectionSet": { 532 + "kind": "SelectionSet", 533 + "selections": [ 534 + { 535 + "alias": undefined, 536 + "arguments": [], 537 + "directives": [], 538 + "kind": "Field", 539 + "name": { 540 + "kind": "Name", 541 + "value": "text", 542 + }, 543 + "selectionSet": undefined, 544 + }, 545 + ], 546 + }, 547 + }, 548 + ], 549 + }, 550 + }, 551 + ], 552 + }, 553 + }, 554 + ], 555 + }, 556 + "variableDefinitions": [ 557 + { 558 + "defaultValue": undefined, 559 + "directives": [], 560 + "kind": "VariableDefinition", 561 + "type": { 562 + "kind": "NamedType", 563 + "name": { 564 + "kind": "Name", 565 + "value": "StoryLikeSubscribeInput", 566 + }, 567 + }, 568 + "variable": { 569 + "kind": "Variable", 570 + "name": { 571 + "kind": "Name", 572 + "value": "input", 573 + }, 574 + }, 575 + }, 576 + ], 577 + }, 578 + { 579 + "directives": [ 580 + { 581 + "arguments": [], 582 + "kind": "Directive", 583 + "name": { 584 + "kind": "Name", 585 + "value": "onFragmentDefinition", 586 + }, 587 + }, 588 + ], 589 + "kind": "FragmentDefinition", 590 + "name": { 591 + "kind": "Name", 592 + "value": "frag", 593 + }, 594 + "selectionSet": { 595 + "kind": "SelectionSet", 596 + "selections": [ 597 + { 598 + "alias": undefined, 599 + "arguments": [ 600 + { 601 + "kind": "Argument", 602 + "name": { 603 + "kind": "Name", 604 + "value": "size", 605 + }, 606 + "value": { 607 + "kind": "Variable", 608 + "name": { 609 + "kind": "Name", 610 + "value": "site", 611 + }, 612 + }, 613 + }, 614 + { 615 + "kind": "Argument", 616 + "name": { 617 + "kind": "Name", 618 + "value": "bar", 619 + }, 620 + "value": { 621 + "kind": "FloatValue", 622 + "value": "12", 623 + }, 624 + }, 625 + { 626 + "kind": "Argument", 627 + "name": { 628 + "kind": "Name", 629 + "value": "obj", 630 + }, 631 + "value": { 632 + "fields": [ 633 + { 634 + "kind": "ObjectField", 635 + "name": { 636 + "kind": "Name", 637 + "value": "key", 638 + }, 639 + "value": { 640 + "block": false, 641 + "kind": "StringValue", 642 + "value": "value", 643 + }, 644 + }, 645 + { 646 + "kind": "ObjectField", 647 + "name": { 648 + "kind": "Name", 649 + "value": "block", 650 + }, 651 + "value": { 652 + "block": true, 653 + "kind": "StringValue", 654 + "value": "block string uses \\\\\\"\\"\\"", 655 + }, 656 + }, 657 + ], 658 + "kind": "ObjectValue", 659 + }, 660 + }, 661 + ], 662 + "directives": [], 663 + "kind": "Field", 664 + "name": { 665 + "kind": "Name", 666 + "value": "foo", 667 + }, 668 + "selectionSet": undefined, 669 + }, 670 + ], 671 + }, 672 + "typeCondition": { 673 + "kind": "NamedType", 674 + "name": { 675 + "kind": "Name", 676 + "value": "Friend", 677 + }, 678 + }, 679 + }, 680 + { 681 + "directives": [], 682 + "kind": "OperationDefinition", 683 + "name": { 684 + "kind": "Name", 685 + "value": "teeny", 686 + }, 687 + "operation": "query", 688 + "selectionSet": { 689 + "kind": "SelectionSet", 690 + "selections": [ 691 + { 692 + "alias": undefined, 693 + "arguments": [ 694 + { 695 + "kind": "Argument", 696 + "name": { 697 + "kind": "Name", 698 + "value": "truthy", 699 + }, 700 + "value": { 701 + "kind": "BooleanValue", 702 + "value": true, 703 + }, 704 + }, 705 + { 706 + "kind": "Argument", 707 + "name": { 708 + "kind": "Name", 709 + "value": "falsey", 710 + }, 711 + "value": { 712 + "kind": "BooleanValue", 713 + "value": false, 714 + }, 715 + }, 716 + { 717 + "kind": "Argument", 718 + "name": { 719 + "kind": "Name", 720 + "value": "nullish", 721 + }, 722 + "value": { 723 + "kind": "NullValue", 724 + }, 725 + }, 726 + ], 727 + "directives": [], 728 + "kind": "Field", 729 + "name": { 730 + "kind": "Name", 731 + "value": "unnamed", 732 + }, 733 + "selectionSet": undefined, 734 + }, 735 + { 736 + "alias": undefined, 737 + "arguments": [], 738 + "directives": [], 739 + "kind": "Field", 740 + "name": { 741 + "kind": "Name", 742 + "value": "query", 743 + }, 744 + "selectionSet": undefined, 745 + }, 746 + ], 747 + }, 748 + "variableDefinitions": [], 749 + }, 750 + { 751 + "directives": [], 752 + "kind": "OperationDefinition", 753 + "name": { 754 + "kind": "Name", 755 + "value": "tiny", 756 + }, 757 + "operation": "query", 758 + "selectionSet": { 759 + "kind": "SelectionSet", 760 + "selections": [ 761 + { 762 + "alias": undefined, 763 + "arguments": [], 764 + "directives": [], 765 + "kind": "Field", 766 + "name": { 767 + "kind": "Name", 768 + "value": "__typename", 769 + }, 770 + "selectionSet": undefined, 771 + }, 772 + ], 773 + }, 774 + "variableDefinitions": [], 775 + }, 776 + ], 777 + "kind": "Document", 778 + } 779 + `;
+11
src/__tests__/parser.test.ts
··· 1 + import { describe, it, expect } from 'vitest'; 2 + import { readFileSync } from 'fs'; 3 + 4 + import { parse } from '../parser'; 5 + 6 + describe('parse', () => { 7 + it('parses the kitchen sink query', () => { 8 + const sink = readFileSync(__dirname + '/../../benchmark/kitchen_sink.graphql', { encoding: 'utf8' }); 9 + expect(parse(sink)).toMatchSnapshot(); 10 + }) 11 + });