Skip to content

@lanexio/parser-grammar-graphql

This page documents @lanexio/parser-grammar-graphql, the GraphQL grammar package implementing the GraphQL October 2021 specification with auto-detection of executable documents vs schema definition language (SDL).

  • Version: Stable
  • Module name: parser-grammar-graphql
  • Package: @lanexio/parser-grammar-graphql
  • Import path: @lanexio/parser-grammar-graphql
  • Layer: 2 (Grammar)
  • Runtime: Universal
  • Module format: ESM
  • Stability: Stable
  • Primary use case: Parse GraphQL documents (queries, mutations, subscriptions, SDL) into a flat AST.
  • You need to parse GraphQL query documents into a traversable AST.
  • You need to parse GraphQL SDL (schema definition language) documents.
  • You need auto-detection between executable and schema documents.
BoundaryDescription
InputsUint8Array (source bytes)
OutputsLexTree (flat AST)
Side effectsNone
DeterminismYes
External dependencies@lanexio/parser-core
Never-throw guaranteeYes
Security surfaceNone (parse only, no output generation)
  1. Install the package.

    Terminal window
    pnpm add @lanexio/parser-grammar-graphql
  2. Import the named export.

    import { parseGraphql } from '@lanexio/parser-grammar-graphql';
RequirementRequiredLayerNotes
@lanexio/parser-coreYes1^1.0.0
import { parseGraphql } from '@lanexio/parser-grammar-graphql';
const encoder = new TextEncoder();
const bytes = encoder.encode('{ user { name email } }');
const tree = parseGraphql(bytes);
console.log(tree.nodeCount);
const encoder = new TextEncoder();
const tree = parseGraphql(encoder.encode(`
type Query {
user(id: ID!): User
}
`));
ExportTypeDescription
parseGraphql(bytes: Uint8Array) => LexTreeParse GraphQL. Never throws. Auto-detects executable vs SDL.
GraphqlKindconst objectNumeric kind IDs for all GraphQL node types.
GraphqlFieldconst objectNumeric field IDs for GraphQL slots.
GRAPHQL_FIELD_NAMES_BY_IDreadonly string[]Field name lookup by numeric field ID.
GRAPHQL_KIND_NAMES_BY_IDreadonly Record<number, string>Kind-name lookup by numeric ID.
graphqlGrammarLanexioParserPureGrammarGrammar descriptor for use with parser-pure.
graphqlRegistrationGrammarRegistrationRegistration for the unified grammar registry.
graphqlReuseOracleReuseOracleIncremental reuse oracle.

No options object. The function signature is parseGraphql(bytes: Uint8Array): LexTree. Options are reserved for future extension.

PropertyTypeDescription
rootLexNodeRoot node of the document.
nodeCountnumberTotal nodes in the tree.
sourceUint8ArrayOriginal parsed bytes.
TypePurposeNotes
GraphqlKindTypeUnion of all GraphqlKind valuesType-safe kind reference
GraphqlFieldTypeUnion of all GraphqlField valuesType-safe field reference

No configuration options. GraphQL documents are parsed with auto-detection between executable and SDL modes.

  • No direct accessibility surface. The GraphQL parser produces flat AST data structures.
ConcernStatus
Generated output semanticsNot applicable (query/schema format)
ARIA attributes in serialized outputNot applicable
Semantic element round-tripNot applicable
  • parseGraphql never throws on any byte sequence.
ThreatMitigationStatus
Malformed input byte sequencePanic-free guarantee: all inputs accepted, errors produce LexError AST nodesImplemented
PackageRelationshipLayerNotes
@lanexio/parser-coreRequires1Provides LexTree, LexNode, LexCursor
@lanexio/parserConsumes6Unified entry point
VersionDateStatusNotable changes
1.0.02026-05-29CurrentInitial stable release. Apache-2.0.
  • None.