Fix GraphQL dangling comment print (#18581)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-01-13 02:18:04 +08:00
1 parent 360b8681d9
commit 7a76a9b119
4 files changed
+72 -4

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
#### Fix comment print (#18581 by @fisker)
<!-- prettier-ignore -->
```gql
# Input
query {
search(filters: {
# TODO
}) {
id
}
}
# Prettier stable
Error: Comment "TODO" was not printed. Please report this error!
# Prettier main
query {
search(
filters: {
# TODO
}
) {
id
}
}
```
+10 -4
View File
@@ -7,6 +7,7 @@ import {
line,
softline,
} from "../document/index.js";
import { printDanglingComments } from "../main/comments/print.js";
import isNextLineEmpty from "../utilities/is-next-line-empty.js";
import isNonEmptyArray from "../utilities/is-non-empty-array.js";
import UnexpectedNodeError from "../utilities/unexpected-node-error.js";
@@ -145,10 +146,15 @@ function genericPrint(path, options, print) {
return group([
"{",
bracketSpace,
indent([
softline,
join([ifBreak("", ", "), softline], path.map(print, "fields")),
]),
printDanglingComments(path, options, { indent: true }),
isNonEmptyArray(node.fields)
? [
indent([
softline,
join([ifBreak("", ", "), softline], path.map(print, "fields")),
]),
]
: "",
softline,
ifBreak("", bracketSpace),
"}",
@@ -25,6 +25,34 @@ query (
================================================================================
`;
exports[`dangling.graphql format 1`] = `
====================================options=====================================
parsers: ["graphql"]
printWidth: 80
| printWidth
=====================================input======================================
query {
search(filters: {
# TODO
}) {
id
}
}
=====================================output=====================================
query {
search(
filters: {
# TODO
}
) {
id
}
}
================================================================================
`;
exports[`fields.graphql format 1`] = `
====================================options=====================================
parsers: ["graphql"]
@@ -0,0 +1,7 @@
query {
search(filters: {
# TODO
}) {
id
}
}