Format embedded GQL in template literal statements (#16064)

Fixes #16007
This commit is contained in:
Keith Layne authored and GitHub committed 2024-03-11 13:48:29 +09:00
1 parent d50a4e4639
commit f62bf4a191
4 files changed
+55

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
#### Format embedded GQL in template literal statements (#16064 by @keithlayne)
<!-- prettier-ignore -->
```jsx
// Input
/* GraphQL */ `
query foo { id }
`;
// Prettier stable
/* GraphQL */ `
query foo { id }
`;
// Prettier main
/* GraphQL */ `
query foo {
id
}
`;
```
+2
View File
@@ -80,6 +80,8 @@ function hasLanguageComment({ node, parent }, languageName) {
return (
hasLeadingBlockCommentWithName(node, languageName) ||
(isAsConstExpression(parent) &&
hasLeadingBlockCommentWithName(parent, languageName)) ||
(parent.type === "ExpressionStatement" &&
hasLeadingBlockCommentWithName(parent, languageName))
);
}
@@ -16,6 +16,17 @@ const query = /* GraphQL */\`
}
\`;
/* GraphQL */\`
{
user( id : 5 , type:
"without variable assignment" ) {
firstName
lastName
}
}
\`;
=====================================output=====================================
const query = /* GraphQL */ \`
{
@@ -27,6 +38,16 @@ const query = /* GraphQL */ \`
}
\`;
/* GraphQL */ \`
{
user(id: 5, type: "without variable assignment") {
firstName
lastName
}
}
\`;
================================================================================
`;
@@ -7,3 +7,14 @@ const query = /* GraphQL */`
}
}
`;
/* GraphQL */`
{
user( id : 5 , type:
"without variable assignment" ) {
firstName
lastName
}
}
`;