@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.
Layer contract
Section titled “Layer contract”When to use this module
Section titled “When to use this module”- 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.
Module boundary
Section titled “Module boundary”| Boundary | Description |
|---|---|
| Inputs | Uint8Array (source bytes) |
| Outputs | LexTree (flat AST) |
| Side effects | None |
| Determinism | Yes |
| External dependencies | @lanexio/parser-core |
| Never-throw guarantee | Yes |
| Security surface | None (parse only, no output generation) |
Installation
Section titled “Installation”-
Install the package.
Terminal window pnpm add @lanexio/parser-grammar-graphqlTerminal window npm install @lanexio/parser-grammar-graphqlTerminal window yarn add @lanexio/parser-grammar-graphql -
Import the named export.
import { parseGraphql } from '@lanexio/parser-grammar-graphql';
Peer dependencies
Section titled “Peer dependencies”| Requirement | Required | Layer | Notes |
|---|---|---|---|
@lanexio/parser-core | Yes | 1 | ^1.0.0 |
Basic Usage
Section titled “Basic Usage”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);SDL parsing
Section titled “SDL parsing”const encoder = new TextEncoder();const tree = parseGraphql(encoder.encode(` type Query { user(id: ID!): User }`));Exports
Section titled “Exports”| Export | Type | Description |
|---|---|---|
parseGraphql | (bytes: Uint8Array) => LexTree | Parse GraphQL. Never throws. Auto-detects executable vs SDL. |
GraphqlKind | const object | Numeric kind IDs for all GraphQL node types. |
GraphqlField | const object | Numeric field IDs for GraphQL slots. |
GRAPHQL_FIELD_NAMES_BY_ID | readonly string[] | Field name lookup by numeric field ID. |
GRAPHQL_KIND_NAMES_BY_ID | readonly Record<number, string> | Kind-name lookup by numeric ID. |
graphqlGrammar | LanexioParserPureGrammar | Grammar descriptor for use with parser-pure. |
graphqlRegistration | GrammarRegistration | Registration for the unified grammar registry. |
graphqlReuseOracle | ReuseOracle | Incremental reuse oracle. |
Options
Section titled “Options”No options object. The function signature is parseGraphql(bytes: Uint8Array): LexTree. Options are reserved for future extension.
Return shape
Section titled “Return shape”| Property | Type | Description |
|---|---|---|
root | LexNode | Root node of the document. |
nodeCount | number | Total nodes in the tree. |
source | Uint8Array | Original parsed bytes. |
Exported types
Section titled “Exported types”| Type | Purpose | Notes |
|---|---|---|
GraphqlKindType | Union of all GraphqlKind values | Type-safe kind reference |
GraphqlFieldType | Union of all GraphqlField values | Type-safe field reference |
Configuration and Extension
Section titled “Configuration and Extension”No configuration options. GraphQL documents are parsed with auto-detection between executable and SDL modes.
Accessibility
Section titled “Accessibility”Accessibility requirements
Section titled “Accessibility requirements”- No direct accessibility surface. The GraphQL parser produces flat AST data structures.
Accessibility checklist
Section titled “Accessibility checklist”| Concern | Status |
|---|---|
| Generated output semantics | Not applicable (query/schema format) |
| ARIA attributes in serialized output | Not applicable |
| Semantic element round-trip | Not applicable |
Security
Section titled “Security”Security considerations
Section titled “Security considerations”parseGraphqlnever throws on any byte sequence.
| Threat | Mitigation | Status |
|---|---|---|
| Malformed input byte sequence | Panic-free guarantee: all inputs accepted, errors produce LexError AST nodes | Implemented |
Companion packages
Section titled “Companion packages”| Package | Relationship | Layer | Notes |
|---|---|---|---|
@lanexio/parser-core | Requires | 1 | Provides LexTree, LexNode, LexCursor |
@lanexio/parser | Consumes | 6 | Unified entry point |
Changelog
Section titled “Changelog”| Version | Date | Status | Notable changes |
|---|---|---|---|
1.0.0 | 2026-05-29 | Current | Initial stable release. Apache-2.0. |
Migration notes
Section titled “Migration notes”- None.
Related Content
Section titled “Related Content” Flat AST How the 16-byte node layout works.
Stability Guarantees Never-throw, panic-free, and 3-token recovery.