Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,7 @@ impl<'a> Formatter<'a> {
}

pub fn write_quoted(&mut self, s: &str) {
let mut has_newline = false;
let mut has_nonprintable = false;
for c in s.chars() {
match c {
'\n' => has_newline = true,
'\r' | '\t' | '\u{0020}'..='\u{FFFF}' => {}
_ => has_nonprintable = true,
}
}
if !has_newline || has_nonprintable {
use std::fmt::Write;
if !s.contains('\n') {
self.buf.push('"');
for c in s.chars() {
match c {
Expand All @@ -143,8 +133,9 @@ impl<'a> Formatter<'a> {
'\t' => self.write(r"\t"),
'"' => self.write("\\\""),
'\\' => self.write(r"\\"),
'\u{0020}'..='\u{FFFF}' => self.buf.push(c),
_ => write!(&mut self.buf, "\\u{:04}", c as u32).unwrap(),
// This covers all Unicode scalar values (range U+0000..=U+D7FF | U+E000..=U+10FFFF)
// as permitted by Rust's char type and GraphQL's (September 2025 version) SourceCharacter
_ => self.buf.push(c),
}
}
self.buf.push('"');
Expand Down
2 changes: 1 addition & 1 deletion tests/queries/directive_args.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
query {
node @dir(a: 1, b: "2", c: true, d: false, e: null)
node @dir(a: 1, b: "2 🤓", c: true, d: false, e: null)
}
2 changes: 1 addition & 1 deletion tests/queries/directive_args_multiline.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
query {
node @dir(
a: 1,
b: "2",
b: "2 🤓",
c: true,
d: false,
e: null
Expand Down
2 changes: 1 addition & 1 deletion tests/queries/query_var_default_string.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
query Foo($site: String = "string") {
query Foo($site: String = "string 🤓") {
field
}
2 changes: 1 addition & 1 deletion tests/queries/string_literal.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
query {
node(id: "hello")
node(id: "hello 🤓")
}
2 changes: 1 addition & 1 deletion tests/queries/triple_quoted_literal.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
query {
node(id: """
Hello,
Hello 🤓,
world!
""")
}