Trying to add support for GraphQL Query in multili...
# apollo-kotlin
s
Trying to add support for GraphQL Query in multiline Kotlin string template to JS GraphQL plugin available thru Jetbrains Ide's. Getting a little lost in adapting the code which parses javaScript string template example to Kotlin or Unified Abstract Tree for Jvm, anyone familiar with an example of a library that can accomplish this? Something like https://github.com/apollographql/graphql-tag but for kotlin. I see tons of DSL builder implementations but haven't found the regular query embedded in string. E.g. const val query = """ query (...) {...} """
m
js-graphql-intellij-plugin uses graphql-java to parsegraphql, I guess you could do this ?
Is this to highlight errors in Kotlin string containing a graphql query ?
s
Yes, it should give full introspection and syntax highlighting as regular graphql, same as "js template literal tag". Don't have a great use case, more of I know it is possible and would be cool 😎
Would like to see jetbrains first class support for graphql and kotlin injected graphql strings too eventually of course
yeah maybe should look into graphql-java more, I have been trying to emulate the way the plugin builds a validated schema object from the psi file for Javascript, but adapt to Kotlin, getting pretty close but no cigar.
Ok I get how to do it manually now using a custom language injection setting in Intellij. Then I can add some logic while doing our kotlin poet codegen step add this to file
Copy code
import org.intellij.lang.annotations.Language
and annotation above the graphql injected string
Copy code
@Language("GraphQL")
const val myQuery = """query(...){...}"""
👍 1
m
Ah this is cool ! Do you get autocomplete inside the string litteral?
s
Yeah it's a start, it can trick JS GraphQL Plugin to use your schema.graphql file to introspect into this file fragment as if it were graphql, just have to use action inject language or reference and choose graphql.
😍 2