Registry / testing / graphql-ast-types

graphql-ast-types

JSON →
library1.0.2jsnpmunverified

Auto-generated helper functions for building GraphQL AST nodes, mirroring the babel-types API. Version 1.0.2 is the latest stable release. It provides factory functions, type checkers (is*), and assertion methods (assert*) for all GraphQL AST node kinds defined by the graphql package. The library is useful for programmatic construction of GraphQL documents without manual object creation. It requires graphql@^0.11.7 as a peer dependency. Its key differentiator is auto-generation from the official GraphQL AST flow descriptions, ensuring correctness and completeness. Development appears inactive since 2018.

npm install graphql-ast-types
INSTALL
IMPORT
SIG · GRAPHQL-AST-TYPES
G
graphql-ast-types
testingjavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

t
import * as t from 'graphql-ast-types'
import t from 'graphql-ast-types'
The module exports a namespace object, so default import doesn't work. Use namespace import.
t.document
import { document } from 'graphql-ast-types'
const { document } = require('graphql-ast-types')
Named imports are available and work in both ESM and CJS environments.
t.isName
import { isName } from 'graphql-ast-types'
Named import for the isName utility function.

Demonstrates constructing a simple GraphQL query using factory functions and printing it.

import { document, operationDefinition, selectionSet, field, name } from 'graphql-ast-types'; import { print } from 'graphql/language'; const ast = document([ operationDefinition( 'query', selectionSet([ field(name('hello')), field(name('world')) ]) ) ]); console.log(print(ast)); // { // hello // world // }
Debug
Known issues
gotchaThe module is auto-generated and may not be updated for newer GraphQL spec versions (e.g., new node types like SchemaExtension).
fix
Check that all required node kinds exist; manually extend if necessary.
affects: >=1.0.0
deprecatedThe library depends on graphql@^0.11.7 which is outdated. Newer graphql versions (>=16) have different AST type structures.
fix
Use graphql@0.11.x or consider alternatives like graphql-tag or manual AST creation.
affects: >=1.0.0
gotchaFactory functions enforce strict validation; passing an invalid argument (e.g., wrong field name) will throw an error.
fix
Use the corresponding is* functions to validate before constructing.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'kind' of undefined
Passing undefined or missing required arguments to a factory function (e.g., selectionSet without selections).
fix
Ensure all required children are provided as arrays or valid AST nodes.
Error: Expected a valid GraphQL AST node, got <value>
Passing a value that is not a valid AST node to an assertion or factory function.
fix
Use the corresponding is* function to verify before using.
Module not found: Error: Can't resolve 'graphql/language'
graphql package is not installed or version mismatch.
fix
Run 'npm install graphql@^0.11.7' to install the correct peer dependency.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency: provides the graphql/language/AST types used by this library
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-ast-types — npm install graphql-ast-types · libregistry