Documentation
    • graphql
    • graphql/error
      • Errors
    • graphql/execution
      • Execution
      • Subscriptions
      • Paths
      • Values
    • graphql/language
      • AST
      • AST Predicates
      • Kinds
      • Lexing
      • Parsing
      • Printing
      • Source
      • Visiting
    • graphql/subscription
      • Subscriptions
    • graphql/type
      • Definitions
      • Directives
      • Introspection
      • Names
      • Paths
      • Scalars
      • Schema
      • Validation
    • graphql/utilities
      • AST Utilities
      • Introspection
      • Operations
      • Schema Changes
      • Schema Construction
      • Schema Coordinates
      • Schema Printing
      • Type Comparisons
      • Type Info
      • Typed Documents
      • Validation
      • Values
    • graphql/validation
      • Custom Rules
      • Validation
      • Validation Context
      • Validation Rules
    • graphql
    • graphql/error
    • graphql/execution
    • graphql/language
    • graphql/type
    • graphql/utilities
    • graphql/validation

On This Page

  • Functions
  • print()
  • Arguments
  • Returns
  • Example
Question? Give us feedback →Edit this page
v16 APIgraphql/languagePrinting

graphql/language/printing

Functions

print()

Converts an AST into a string, using one set of reasonable formatting rules.

Signature:

print(ast: ASTNode): string

Arguments

NameTypeDescription
astASTNodeThe GraphQL AST node to print.

Returns

TypeDescription
stringA stable string representation of the AST.

Example

import { parse, print } from 'graphql';
 
const ast = parse('{ hero { name } }');
const text = print(ast);
 
// text:
// {
//   hero {
//     name
//   }
// }
ParsingSource

    Learn

  • Introduction to GraphQL
  • Frequently Asked Questions
  • Training Courses

    Code

  • GitHub
  • GraphQL Specification
  • Libraries & Tools
  • Services & Vendors

    Community

  • Resources
  • Events & Meetups
  • Contribute to GraphQL
  • Landscape
  • Shop

    & More

  • Blog
  • GraphQL Foundation
  • GraphQL Community Grant
  • Logo and Brand Guidelines
  • Code of Conduct

Copyright © 2026 The GraphQL Foundation. All rights reserved.
For web site terms of use, trademark policy and general project policies please see https://lfprojects.org

Powered by