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

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

Closed
eburke56 opened this issue Sep 16, 2021 · 8 comments
Closed

Comments

@eburke56
Copy link

eburke56 commented Sep 16, 2021

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
Copy link
Collaborator

@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
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Collaborator

@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
Copy link
Author

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
Copy link
Collaborator

@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
Copy link
Author

eburke56 commented Oct 18, 2021

@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
Copy link
Collaborator

Ok, thanks for the update 👍.

@vepanimas vepanimas changed the title Detecting GraphQL schema files in a generated directory? Mark a generated directory as a source root for detecting GraphQL schema Oct 18, 2021
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