Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not handle ${'$'} in kotlin multline strings when variable is used #717

Open
yanlin-yc opened this issue Jun 5, 2024 · 1 comment

Comments

@yanlin-yc
Copy link

yanlin-yc commented Jun 5, 2024

Before you create the issue

  • If you're using an EAP, try with a stable version. If that works, please mention it in the issue along with both versions
  • Please search the existing issues before opening a new issue
  • Review the developer guide

Describe the bug
A clear and concise description of what the bug is.

It's pretty common to use multiline strings in kotlin to write a graphql document in code. When a variable is needed, the only way to make $ (dollar sign) escaped in the multiline string is using the literal representation like the following:

// language=GraphQL
val document = """
query ExampleQuery(${'$'}email: String) {
    userByEmail(email: ${'$'}email) {
        id
        email
    }
}
""".trimIdent()

However when ${'$'} appears, the GraphQL IntelliJ plugin will no longer process the document and there is no syntax highlighting or autocompletion.

If no variable used, everything works as expected, e.g. the following is fine

// language=GraphQL
val document = """
query ExampleQuery {
    userByEmail(email: [email protected]) {
        id
        email
    }
}
""".trimIdent()

To Reproduce
Link to Repo with Reproduction or Steps to Reproduce:
(see the above example code)

Expected behavior
A clear and concise description of what you expected to happen.

The GraphQL IntelliJ plugin should be able to handle ${'$'} in kotlin multiline string as it's a very common use case.

Screenshots
If applicable, add screenshots to help explain your problem.

Version and Environment Details
Operation system: MacOS Sonoma Version 14.5
IDE name and version: IntelliJ IDEA 2024.1.2 (Ultimate Edition)
Plugin version: 241.14494.150

Additional context
Add any other context about the problem here.

@PvtPuddles
Copy link

I don't know if there is a separate issue for this for Dart, but it seems like this is a universal issue when one needs to escape the $ symbol.

In dart, $ has special meaning to insert a variable, so the following is likewise not valid:

final query = /* language=graphql */ """
    query ExampleQuery(\$email: String!) {
        userByEmail(email:\$email) { id, email }
    }
""";

This can be worked around by converting the string to a raw string (and removing the escape characters).

It seems as if there should be some sort of translation layer between the source code (Kotlin, Dart, etc) and the graphql that could be used to un-escape the string.

On a related note, it would be nice if we could use the plugin to write something like this (though this should probably be its own feature request):

final dynamicFields = "id, email";

final query = /* language=graphql */ """
    query ExampleQuery(\$email: String!) {
        userByEmail(email:\$email) { $dynamicFields }
    }
""";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants