js-graphql-intellij-plugin icon indicating copy to clipboard operation
js-graphql-intellij-plugin copied to clipboard

Fragments are not recognised inside strings with injected GraphQL language in some cases

Open arlampin opened this issue 2 years ago • 2 comments

Describe the bug Fragments are not recognised inside strings with injected GraphQL language in some cases.

To Reproduce Using the following text block in TS file

`
    query {
      me {
        ...AuthFragment
      }
    }

    fragment AuthFragment on User {
      email
    }
`;

and then from context actions selecting "Inject language" -> GraphQL.

Everything should be valid, but ...AuthFragment is highlighted with Unknown fragment spread "AuthFragment".

Adding explicit

// language=GraphQL

to the top fixes the issue.

  // language=GraphQL
`
    query {
      me {
        ...AuthFragment
      }
    }

    fragment AuthFragment on User {
      email
    }
`;

The same thing happens in Java files, but there adding language=GraphQL or org.intellij.lang.annotations.Language("GraphQL") annotation doesn't fix the issue.

Expected behavior Valid GraphQL queries should not be marked with errors

Version and Environment Details IDE name and version: IntelliJ IDEA 2023.1.2 (Ultimate Edition) Plugin version: 4.0.1

arlampin avatar Jun 16 '23 13:06 arlampin

I've just run into this problem after adding GraphQL support for my .NET package ShopifySharp. Using Rider, fragments aren't recognized inside strings that use .NET's StringSyntaxAttribute, nor does adding the //lang=graphql comment work.

Image

Version and Environment Details IDE name and version: JetBrains Rider 2024.3.5 Plugin version: 243.24978.46

nozzlegear avatar Feb 22 '25 01:02 nozzlegear

I'm hit by this, too. Using F# with StringSyntaxAttribute to trigger language injection. I also get the error if I use Rider's "Edit GraphQL fragment" feature on the injected string.

cmeeren avatar Apr 02 '25 09:04 cmeeren

Having the same issue in Rider 2025.2.3, plugin version 252.25557.23. Can't seem to suppress the error either.

erikljung avatar Oct 13 '25 06:10 erikljung