question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prettier assumes untagged template string parameter is graphql

See original GitHub issue

Prettier 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:open
  • Created 4 years ago
  • Comments:14 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
thorn0commented, Mar 20, 2020

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.

1reaction
alexander-akaitcommented, Mar 20, 2020

@thorn0 Yep, but i think it is not high priority right now

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found