Crates.io | pretty_graphql |
lib.rs | pretty_graphql |
version | 0.2.1 |
source | src |
created_at | 2024-08-22 12:08:42.300117 |
updated_at | 2024-10-21 14:50:10.482971 |
description | GraphQL formatter. |
homepage | |
repository | https://github.com/g-plane/pretty_graphql |
max_upload_size | |
id | 1347635 |
size | 117,736 |
pretty_graphql
is a configurable GraphQL formatter.
You can format source code string by using [format_text
] function.
use pretty_graphql::{config::FormatOptions, format_text};
let options = FormatOptions::default();
assert_eq!("{\n field\n}\n", &format_text("{ field }", &options).unwrap());
For detailed documentation of configuration, please read configuration documentation.
If there're syntax errors in source code, it will return Err
:
use pretty_graphql::{config::FormatOptions, format_text};
let options = FormatOptions::default();
assert!(format_text("{", &options).is_err());
If you have already parsed the syntax tree from apollo-parser
,
you can use [print_tree
] to print it.
use pretty_graphql::{config::FormatOptions, print_tree};
use apollo_parser::{cst::Document, Parser};
let input = "{ field }";
let parser = Parser::new(input);
let cst = parser.parse();
let options = FormatOptions::default();
assert_eq!("{\n field\n}\n", &print_tree(&cst.document(), &options));