{"id":16045,"library":"graphql-js-tree","title":"GraphQL JS Tree Parser","description":"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.","status":"active","version":"3.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/graphql-editor/graphql-js-tree","tags":["javascript","typescript"],"install":[{"cmd":"npm install graphql-js-tree","lang":"bash","label":"npm"},{"cmd":"yarn add graphql-js-tree","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphql-js-tree","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime peer dependency for core GraphQL parsing capabilities, specifically for AST manipulation and interpretation.","package":"graphql","optional":false}],"imports":[{"note":"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.","wrong":"const { Parser, TreeToGraphQL } = require('graphql-js-tree');","symbol":"Parser, TreeToGraphQL","correct":"import { Parser, TreeToGraphQL } from 'graphql-js-tree';"},{"note":"This is a named export for parsing GraphQL query strings against a schema. Do not use a default import.","wrong":"import parseGql from 'graphql-js-tree';","symbol":"parseGql","correct":"import { parseGql } from 'graphql-js-tree';"},{"note":"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.","wrong":"const gqlString = parseGqlTrees(parsedTrees); // Missing import","symbol":"parseGqlTrees","correct":"import { parseGqlTrees } from 'graphql-js-tree';"}],"quickstart":{"code":"import { Parser, TreeToGraphQL } from 'graphql-js-tree';\n\nconst schemaFileContents = `\ntype Query{\n    hello: String!\n    greeting(name: String!): String!\n}\ntype Mutation {\n    setName(name: String!): String!\n}\nschema{\n    query: Query\n    mutation: Mutation\n}\n`;\n\n// Parse a GraphQL SDL schema into the simplified tree structure\nconst parsedSchema = Parser.parse(schemaFileContents);\n\n// In a real application, you might process or transform 'parsedSchema' here.\n// For demonstration, we'll log a portion of it.\n// console.log(JSON.stringify(parsedSchema, null, 2));\n\n// Convert the simplified tree back into a GraphQL SDL string\nconst graphqlString = TreeToGraphQL.parse(parsedSchema);\n\nconsole.log(\"Original Schema:\\n\", schemaFileContents);\nconsole.log(\"----------------------------------\");\nconsole.log(\"Parsed and Reconstructed Schema:\\n\", graphqlString);\n\n// This demonstrates both parsing into the internal tree format and\n// reconstructing the SDL, validating the transformation process.\n","lang":"typescript","description":"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."},"warnings":[{"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.","message":"Upgrading 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.","severity":"breaking","affected_versions":">=2.0.0"},{"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.","message":"Ensure 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"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.","cause":"The `graphql-js-tree` package is not installed in the project, or the import path is incorrect, or TypeScript cannot find its declaration files.","error":"Cannot find module 'graphql-js-tree' or its corresponding type declarations."},{"fix":"Ensure `Parser` is imported as a named export: `import { Parser } from 'graphql-js-tree';` and then called as `Parser.parse(...)`.","cause":"Attempting to call `Parser` directly as a function or importing `Parser` incorrectly (e.g., as a default import when it's a named export).","error":"TypeError: Parser.parse is not a function"}],"ecosystem":"npm"}