JetBrains / js-graphql-intellij-plugin

GraphQL language support for WebStorm, IntelliJ IDEA and other IDEs based on the IntelliJ Platform.
https://jimkyndemeyer.github.io/js-graphql-intellij-plugin/
MIT License
879 stars 97 forks source link

Mark a generated directory as a source root for detecting GraphQL schema #493

Closed eburke56 closed 2 years ago

eburke56 commented 2 years ago

We are trying to set up our Android Studio project so that the plugin can detect our schema. Because the schema lives in another artifact, we set up a Gradle task to copy the schema to our codegen directory. However, the plugin does not see this file, presumably because it is not a "project file".

Is there a way we can inform the plugin that it can find the file in a directory under build/generatedGraphQLData/schema? I've tried configuring a .graphqlconfig with no luck.

I created a symlink from the toplevel directory schema -> build/generatedGraphQLData/schema, and it works, but that is definitely not ideal.

vepanimas commented 2 years ago

@eburke56 hi! Do you have any .graphqlconfig files? Could you share them if so? I've tried to reproduce it, but in my case the schema from the generated root is successfully resolved in queries from the other modules. Maybe your project structure is more complicated than my example project. Also what plugin and IDE version do you use?

vepanimas commented 2 years ago

That's my example empty project, you can see that a query.graphql found a schema file in the generated root even without a provided .graphqlconfig.

gen-roots
eburke56 commented 2 years ago

Thanks for the reply! I think the difference is that my directory is not seen by AS as a "generated sources root". If I manually mark the directory as a sources root, it works.

vepanimas commented 2 years ago

@eburke56 was it marked as excluded before in your case? If so, you could simply do "Unmark as excluded" or "Mark as source directory". Or "Mark as generated root" should help too.

eburke56 commented 2 years ago

Yes, it was marked as excluded after being generated. I'm trying to find a way to have the Gradle task mark it as such automatically, e.g., by adding it to a sources root.

vepanimas commented 2 years ago

@eburke56 Have you managed to fix it on your side? I'm not a Gradle pro, but I can still ask the Gradle integration plugin maintainers about it if it's still a problem for you.

eburke56 commented 2 years ago

@vepanimas Yes, we were able to use Gradle scripting to indicate that the folder into which we copy the schema is a source folder. The plugin then picks it up!

def copySchemaTask = tasks.getByName("copySchema")
def schemaOutputDir = file(copySchemaTask.schemaOutputDir.get())
def graphqlSrcDir = file("src/main/graphql")
android.libraryVariants.all { variant ->
    variant.registerJavaGeneratingTask(copySchemaTask, schemaOutputDir)
    variant.addJavaSourceFoldersToModel(graphqlSrcDir)
}
vepanimas commented 2 years ago

Ok, thanks for the update 👍.