Skip to content

Instantly share code, notes, and snippets.

@solomon-b
Created July 4, 2022 23:11
Show Gist options
  • Save solomon-b/9a1ba59ccddec6a770376fdcb52f0592 to your computer and use it in GitHub Desktop.
Save solomon-b/9a1ba59ccddec6a770376fdcb52f0592 to your computer and use it in GitHub Desktop.

Graphql Parser Stress Test RFC

## TL;DR

It would be really nice to have a set of GraphQL Documents which collectively express the entire GraphQL grammar. This would include atypical constructions such as random insertions of comma characters as whitespace.

## Problem Statement

The GraphQL query language is well specified with a formal grammar but is large enough that there can be subtle edge cases when constructing parsers, especially when the parser is hand written. The language also continues to be extended and library developers must stay on top of changes to the spec.

## Proposed Solution

In addition to the language spec, we should providee an official collection of GraphQL Documents which covers the entire grammar constructed in varying levels of term complexity.

This set of `Golden Documents` should also contain examples which attempt to trip up the parser implementation. For example, inconsistent use of commas or extra commas, complexities around block strings, and ambiguous parses such as:

type Query

{ foo: bar }

For every `Golden Document` representing a valid term we would provide a graphql-js AST. For those representing invalid terms we would provide the errors in GraphQL format.

Between the GraphQL Spec examples, the graphql-js test suite, and the nim-graphql test suite we have a large supply of test values. In addition I would also like to build a set of terms based on the chinook-database generated from the Hasura GraphQL Engine.

Such a collection of Documents would be extremely useful for golden testing GraphQL parsers and would help establish a higher standard for parsers across implementation languages.

This proposal is based on the discussion in this issue and combines the suggestions from a number of members of the community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment