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 on virtual documents generated by processor

See original GitHub issue

Describe the bug

Codefile with GraphQL operations:

import { gql } from "apollo-server-core";

export const OPERATION = gql`
    query operation($id: ID!) {
        operation(id: $id) {
            id
        }
    }
`;

Prettier try to convert it to:

import { gql } from "apollo-server-core";

export const OPERATION = gql`query operation($id: ID!) {
    operation(id: $id) {
        id
    }
}`;

To Reproduce

.prettierrc.json

{
  "printWidth": 120,
  "overrides": [
    {
      "files": "*.graphql",
      "options": {
        "parser": "graphql"
      }
    }
  ]
}

.eslintrc.json

{
  "root": true,
  "extends": [
    "eslint:recommended",
    "plugin:prettier/recommended"
  ],
  "processor": "@graphql-eslint/graphql",
  "overrides": [
    {
      "files": ["*.graphql"],
      "parser": "@graphql-eslint/eslint-plugin",
      "plugins": ["@graphql-eslint"],
      "rules": {
        "@graphql-eslint/require-id-when-available": ["error"]
      }
    }
  ]
}

Expected behavior

Keep codefile with GraphQL operations:

import { gql } from "apollo-server-core";

export const OPERATION = gql`
    query operation($id: ID!) {
        operation(id: $id) {
            id
        }
    }
`;

Environment:

  • OS: Linux 5.10.34-1-lts
  • @graphql-eslint/...: 0.9.1
  • NodeJS: 14.16.0

Additional context

I will try to explain what I think is happening adding new line characters \n to the document:

import { gql } from "apollo-server-core";\n
\n
export const OPERATION = gql`\n
    query operation($id: ID!) {\n
        operation(id: $id) {\n
            id\n
        }\n
    }\n
`;\n

The @graphql-eslint/eslint-plugin processor extract from “gql`” to “`;” so the generated virtual document begin with a new line:

\n
query operation($id: ID!) {\n
    operation(id: $id) {\n
        id\n
    }\n
}\n

I think is better extract from “gql`\n” to “`;” if the \n exists and my assumptions are correct…

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dotansimhacommented, May 18, 2021

Thanks @joual for reporting it, and @B2o5T for the help here! Awesome work 😃 I think we can safely close this one. @xeladejo if you think we need to reopen - just ping me! 😃

0reactions
alexojegucommented, May 16, 2021

Yeah, that seems to work fine.

If it were possible to use --fix in the problems detected in virtual documents it would be perfect.

Thanks you.

— EDITED —

The --fix trouble seems happen only on vscode, in the CLI the line is incorrect but it seems to be fixed correctly. I will try to test it better.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration File - Prettier
Overrides let you have different configuration for certain file extensions, folders and specific files. Prettier borrows ESLint's override format. ... files is ...
Read more >
How To Format Code with Prettier in Visual Studio Code
Step 1 — Using the Format Document Command · Step 2 — Formatting Code on Save · Step 3 — Changing the Prettier...
Read more >
prettier.configPath is ignored when current file is virtual (?)
Summary. When editing a file from GitHub Gist using GistPad, the prettier.configPath is ignored. Github Repository to Reproduce Issue.
Read more >
Contributing - Datasette documentation
This document describes how to contribute to Datasette core. ... The next step is to create a virtual environment for your project and...
Read more >
homebrew-core - Homebrew Formulae
a2ps 4.14 Any‑to‑PostScript filter aacgain 1.8 AAC‑supporting version of mp3gain aalib 1.4rc5 Portable ASCII art graphics library aamath 0.3 Renders mathematical expressions as ASCII art
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