Registry / serialization / graphql-js-tree

graphql-js-tree

JSON →
library3.0.4jsnpmunverified

graphql-js-tree is a JavaScript library for parsing GraphQL Schema Definition Language (SDL) and GraphQL queries into a simplified, pure graph JSON structure. Unlike the standard `graphql-js` parser, which retains extensive text-specific Abstract Syntax Tree (AST) information, `graphql-js-tree` focuses on generating a more streamlined representation. This simplified structure makes it significantly easier to work with programmatically, abstracting away much of the raw AST complexity. The current stable version is 3.0.4. It serves as a foundational component for larger projects like `graphql-zeus` and `graphql-editor`, providing a pragmatic approach to GraphQL parsing. While a precise release cadence isn't explicitly specified, its integral role in other active projects suggests ongoing maintenance and development.

npm install graphql-js-tree
INSTALL
IMPORT
SIG · GRAPHQL-JS-TREE
G
graphql-js-tree
serializationjavascriptv3.0.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Parser, TreeToGraphQL
import { Parser, TreeToGraphQL } from 'graphql-js-tree';
const { Parser, TreeToGraphQL } = require('graphql-js-tree');
The library primarily uses ES Module syntax. While CJS may work via transpilation in some setups, direct `require` is not the idiomatic way for modern applications and can lead to issues with type inference or bundling.
parseGql
import { parseGql } from 'graphql-js-tree';
import parseGql from 'graphql-js-tree';
This is a named export for parsing GraphQL query strings against a schema. Do not use a default import.
parseGqlTrees
import { parseGqlTrees } from 'graphql-js-tree';
const gqlString = parseGqlTrees(parsedTrees); // Missing import
While shown in README usage, `parseGqlTrees` must be explicitly imported as a named export. It is used to reconstruct a GraphQL query string from a parsed tree structure.

This quickstart demonstrates parsing a GraphQL SDL schema into `graphql-js-tree`'s simplified internal representation and then reconstructing it back into an SDL string, showcasing the core `Parser` and `TreeToGraphQL` functionalities.

import { Parser, TreeToGraphQL } from 'graphql-js-tree'; const schemaFileContents = ` type Query{ hello: String! greeting(name: String!): String! } type Mutation { setName(name: String!): String! } schema{ query: Query mutation: Mutation } `; // Parse a GraphQL SDL schema into the simplified tree structure const parsedSchema = Parser.parse(schemaFileContents); // In a real application, you might process or transform 'parsedSchema' here. // For demonstration, we'll log a portion of it. // console.log(JSON.stringify(parsedSchema, null, 2)); // Convert the simplified tree back into a GraphQL SDL string const graphqlString = TreeToGraphQL.parse(parsedSchema); console.log("Original Schema:\n", schemaFileContents); console.log("----------------------------------"); console.log("Parsed and Reconstructed Schema:\n", graphqlString); // This demonstrates both parsing into the internal tree format and // reconstructing the SDL, validating the transformation process.
Debug
Known issues
breakingUpgrading from `graphql-js-tree` v1.x to v3.x involves significant breaking changes. The internal API for `Parser` and related utilities has been refactored to achieve a 'simplier structure' as described in release notes. Code written for v1.x will likely require substantial updates.
fix
Consult the official GitHub repository's release notes or commit history for specific migration details between major versions. Update code to align with the new API surface and data structures.
affects: >=2.0.0
gotchaEnsure your project's `graphql` package version precisely matches the peer dependency requirement (`^16.0.0 || ^17.0.0`). Mismatches can lead to cryptic runtime errors due to different GraphQL AST node structures or API incompatibilities from the underlying `graphql-js` library.
fix
Install a compatible `graphql` version (e.g., `npm install graphql@17`). Use `npm ls graphql` or `yarn why graphql` to check for and resolve version conflicts in your dependency tree.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'graphql-js-tree' or its corresponding type declarations.
The `graphql-js-tree` package is not installed in the project, or the import path is incorrect, or TypeScript cannot find its declaration files.
fix
Ensure the package is installed: `npm install graphql-js-tree` or `yarn add graphql-js-tree`. Verify the import statement for correct path and symbol names.
TypeError: Parser.parse is not a function
Attempting to call `Parser` directly as a function or importing `Parser` incorrectly (e.g., as a default import when it's a named export).
fix
Ensure `Parser` is imported as a named export: `import { Parser } from 'graphql-js-tree';` and then called as `Parser.parse(...)`.
Upgrade
Version history
3.0.4latest on npm
Audit
Dependencies
graphqlrequiredRuntime peer dependency for core GraphQL parsing capabilities, specifically for AST manipulation and interpretation.
Agent activity
13 hits · last 30 days
node
12
Amazon
1
Resources
graphql-js-tree — npm install graphql-js-tree · libregistry