pub fn minify<T: AsRef<str>>(value: T) -> Result<String, LexingError>
Expand description
Strips characters that are not significant to the validity or execution of a GraphQL document.
It is functionally equivalent to stripIgnoredCharacters
defined in the GraphQL spec.
This function takes a value that implements the AsRef<str>
trait, allowing for flexible input types
that can be treated as a string slice. It returns a Result
with the minified string or an error
if the lexing process fails.
§Examples
use graphql_minify::minify;
let original = r#"
query SomeQuery($foo: String!, $bar: String) {
someField(foo: $foo, bar: $bar) {
...fragmented
}
}
"#;
let minified = minify(original).unwrap();
assert_eq!(minified, "query SomeQuery($foo:String!$bar:String){someField(foo:$foo bar:$bar){...fragmented}}");
§Errors
This function will return an error if the lexing process encounters an unexpected character.
§Panics
This function does not panic.
§Safety
This function does not use any unsafe code.