Repository: prettier/prettier (JavaScript)

Issue:
Bare embedded GQL string in e.g. JS is not formatted
**Prettier 3.2.4**
[Playground link](https://prettier.io/playground/#N4Igxg9gdgLgprEAuc0DOMAEAzCFMC8mA9AFSYDiATgIYAOAFgIoAympxmABgDpSaYAjgFc4VAJ448mYJgCWAE0wBfPlwDcfPmUq1Grdp178hoiVPyzFKtepAAaEBDow56ZKBpUqEAO4AFLwQ0ZBAaABtfGnEQxwAjWjAAazgYAGUaAFs4FjkoOGRsCLQ4eMSU9LoaMDyAc2QYKlFHEsy5BqbSkDgADzoxOWzYCIAVMSgvOTgQpCLwkpa68LgmYQh4QuKugCs0HrSllbWN2a3HEXW4fx86GbC0AFp8uAUXhxBGmjlwuoBhCEymRooQi4XeaEOAEEYI05HFhPB-GJcvlNvMugwYJlwgB1BhyeBoKpgOBpYIEuQANwJ4lCYDQsRAlNEAEkoK9YGkwFQ5C5Iey0jBxMs0QsQHQfCUcXpQhLpmJKQVHHkSlQYNcaLUgaKulUqKrQnEaHE4GDHBK8jAcYoYAxkAAOAAMjiocBEcldGq1wNO6McMGN1oUtuQACZHMISiNjTM5mK4JkTQpXgoWDQoLVhJq4AAxCBUIEwuoghEQEDKZRAA)
<!-- prettier-ignore -->
```sh
--parser babel
```

**Input:**
<!-- prettier-ignore -->
```jsx
const foo = /* GraphQL */ `
  query foo { id }
`;

foo(/* GraphQL */ `
  query foo { id }
`);

/* GraphQL */ `
  query foo { id }
`;
```

**Output:**
<!-- prettier-ignore -->
```jsx
const foo = /* GraphQL */ `
  query foo {
    id
  }
`;

foo(/* GraphQL */ `
  query foo {
    id
  }
`);

/* GraphQL */ `
  query foo { id }
`;
```

**Expected output:**
<!-- prettier-ignore -->
```jsx
const foo = /* GraphQL */ `
  query foo {
    id
  }
`;

foo(/* GraphQL */ `
  query foo {
    id
  }
`);

/* GraphQL */ `
  query foo {
    id
  }`;
```

**Why?**

We use GQL snippets in TS sometimes purely for codegen - these strings get stripped out during build. We don't need or want to assign to variables, so it would be nice to get these formatted by prettier.

I'd consider this to be a nice-to-have feature. I have no idea if this was a conscious decision, or if it's some kind of design limitation. I'd be willing to implement if this feature would be considered and somebody pointed me in the right direction.


Hints:
To the best of my recollection, I don't believe this is either an intentional design or a limitation.
If that's a real-world use case, I think we can accept it.
Thanks - this may be trivial for someone who knows the codebase and has time to look at it, but otherwise, any pointers on where to look? I confess I haven't looked yet. 
Also, I'm not clear on the scope of what I've requested - is this a generic thing that applies across embedded languages somehow, or limited to embedding languages in JS/TS, or specific to JS/TS/GQL? 

I know I need to do some reading of docs and code, but again, any pointers are welcome.
This function https://github.com/prettier/prettier/blob/99bc9d0b6d3a9bcc0de6e99786502fba2d29b4fe/src/language-js/embed/graphql.js#L108-L122 decides if the template should format as graphql. All you need to do is make it match your case.

Patch:
diff --git a/src/language-js/embed/utils.js b/src/language-js/embed/utils.js
--- a/src/language-js/embed/utils.js
+++ b/src/language-js/embed/utils.js
@@ -80,6 +80,8 @@ function hasLanguageComment({ node, parent }, languageName) {
   return (
     hasLeadingBlockCommentWithName(node, languageName) ||
     (isAsConstExpression(parent) &&
+      hasLeadingBlockCommentWithName(parent, languageName)) ||
+    (parent.type === "ExpressionStatement" &&
       hasLeadingBlockCommentWithName(parent, languageName))
   );
 }


Test patch:
diff --git a/tests/format/js/multiparser-graphql/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/multiparser-graphql/__snapshots__/jsfmt.spec.js.snap
--- a/tests/format/js/multiparser-graphql/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/multiparser-graphql/__snapshots__/jsfmt.spec.js.snap
@@ -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
+    }
+  }
+\`;
+
 ================================================================================
 `;
 
diff --git a/tests/format/js/multiparser-graphql/comment-tag.js b/tests/format/js/multiparser-graphql/comment-tag.js
--- a/tests/format/js/multiparser-graphql/comment-tag.js
+++ b/tests/format/js/multiparser-graphql/comment-tag.js
@@ -7,3 +7,14 @@ const query = /* GraphQL */`
     }
   }
 `;
+
+/* GraphQL */`
+      {
+    user(   id :   5 , type:
+    "without variable assignment"  )  {
+      firstName
+
+      lastName
+    }
+  }
+`;