Prettier assumes untagged template string parameter is graphql
See original GitHub issuePrettier 1.19.1 Playground link
--parser typescript
Input:
function graphql(notgql: string): string {
return notgql + ' something'
}
const x = graphql(`{id}`)
// following code will cause prettier error: Syntax Error: Unexpected Name "x" (1:1)
// const y = graphql(`x {id}`)
Output:
function graphql(notgql: string): string {
return notgql + " something";
}
const x = graphql(
`
{
id
}
`
);
// following code will cause prettier error: Syntax Error: Unexpected Name "x" (1:1)
// const y = graphql(`x {id}`)
Expected behavior:
The template strings passed to graphql()
should not be reformatted because there is no guarantee that they are graphql queries.
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (12 by maintainers)
Top Results From Across the Web
Prettier 1.13: Conquering the web!
We format GraphQL in tagged template literals but there are GraphQL libraries that use untagged template literals. Many GraphQL editor plugins ...
Read more >GraphQL just got a whole lot “Prettier”!
Using prettier for GraphQL is more than just hitting the “prettify” button in GraphiQL — it'll take into account things like maximum line-width, ......
Read more >Enhanced strings with tagged template literals
Tagged template literals follow a pretty consistent formula. It is a function where the first argument is all the strings in the template, ......
Read more >Format/Prettyprint gql `template strings` in GraphQL Apollo ...
You can install and configure prettier to your project. Then install the Prettier plugin for Webstorm, which will add a Reformat with ...
Read more >Resolver mapping template overview - AWS AppSync
The communication is typically through parameters or operations that are unique to the data source. Resolvers are the connectors between GraphQL and a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Okay, but calling it a bug is strange, given that it was intentionally implemented in https://github.com/prettier/prettier/issues/2781 as a solution for https://github.com/prettier/prettier/issues/2780. Conceptually, it’s the same feature as formatting tagged templates. As we don’t know how many users rely on this currently, we can’t just remove it, which means it needs configurability. So it’s really the same problem as #5588 / #6626.
@thorn0 Yep, but i think it is not high priority right now