@graphjson/printer
v0.0.1
Published
> Print GraphQL queries as formatted strings
Readme
@graphjson/printer
Print GraphQL queries as formatted strings
GraphJSON Printer provides utilities for converting GraphQL AST nodes back into formatted query strings.
Why Use This?
- 📄 Pretty Printing - Format GraphQL queries beautifully
- 🎨 Customizable - Control formatting options
- 🔧 AST-Based - Works with GraphQL AST nodes
- 🚀 Fast - Optimized printing algorithm
- 📦 Lightweight - Minimal dependencies
Installation
npm install @graphjson/printerQuick Start
import { print } from 'graphql';
import { generateDocument } from '@graphjson/core';
const { ast } = generateDocument({
query: {
users: {
select: {
id: true,
name: true
}
}
}
});
// Print the query
console.log(print(ast));Output:
query {
users {
id
name
}
}Usage
The printer is based on GraphQL's built-in print function and works with any GraphQL DocumentNode or AST node.
Basic Printing
import { print } from 'graphql';
const queryString = print(ast);With Formatting
import { print } from 'graphql';
const formatted = print(ast);
// Result is automatically formatted with:
// - Proper indentation
// - Consistent spacing
// - Readable structureGraphJSON Ecosystem
| Package | Description | NPM |
|---------|-------------|-----|
| @graphjson/core | Core document generation | |
| @graphjson/ast | AST building utilities |
|
Examples
See the examples directory for usage examples.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md.
License
MIT © NexaLeaf
