apollographql / apollo-kotlin

:rocket:  A strongly-typed, caching GraphQL client for the JVM, Android, and Kotlin multiplatform.
https://www.apollographql.com/docs/kotlin
MIT License
3.73k stars 654 forks source link

[Plugin] SchemaPath property is not handled properly when generating classes #2579

Closed yakeem closed 3 years ago

yakeem commented 3 years ago

Summary When creating multiple services and defining path to schema, one needs to use schemaFile property instead of schemaPath

Version 2.3.1

Description I have following setup for my project:

apollo {

    service("proj1") {
        sourceFolder.set("src/main/graphql/proj1")  
        schemaPath.set("src/main/graphql/proj1/schema.json")
    }

    service("proj2") {
        sourceFolder.set("src/main/graphql/proj2")
        schemaPath.set("src/main/graphql/proj2/schema.json")
    }

However running above, it does not see my schema.json file and generates no java/kotlin classes.

When instead of schemaPath I'm using schemaFile props, then everything is generated perfectly:

apollo {

    service("proj1") {
        sourceFolder.set("src/main/graphql/proj1")  
        schemaFile.set(file("src/main/graphql/proj1/schema.json"))
    }

    service("proj2") {
        sourceFolder.set("src/main/graphql/proj2")
        schemaFile.set(file("src/main/graphql/proj2/schema.json"))
    }

Am I misusing somehow schemaPath or is it a bug?

martinbonnin commented 3 years ago

schemaPath is resolved differently than schemaFile for obscure Android Variants reasons (basically the plugin supports using different schemas for different android variants which I think no one uses and complexifies the code a lot...).

To use schemaPath, pass the path relative to src/main/graphql: schemaPath.set("proj1/schema.json"), this should work.

I'm planning to clean that up in the next major version but in the meantime the above should work. Let me know if it doesn't.

martinbonnin commented 3 years ago

Hi @yakeem , did using schemaPath help? Anything I can do here? If not, do you mind if I close this issue?

martinbonnin commented 3 years ago

I'm closing this issue, please leave a comment if you want me to reopen it.

Drjacky commented 2 years ago

@martinbonnin Do we still have schemaPath? My .graphql & schema.json are in another module and when I build the project, the plugin doesn't generate the kotlin classes.

martinbonnin commented 2 years ago

@Drjacky 3.x streamlined the Gradle configuration a lot and using schemaFile now covers all use cases.

Usually, it's a matter of doing

apollo {
  service("starwars") {
    srcDir("../otherModule/src/main/graphql/starwars")
    schemaFile.set(file("../otherModule/src/main/graphql/starwars/schema.graphqls"))
  }
}

(edit: added schema.graphqls)

You can read more about it there: https://www.apollographql.com/docs/kotlin/advanced/plugin-configuration/

Do not hesitate to open a new issue if that doesn't work.

Drjacky commented 2 years ago

@martinbonnin Can we define the location of generated classes? Imagine I want to generate the models in Module X. but I have hilt framework which needs to be in the App module. When I want to provide ApolloClient in a DI module in the App module, I need apollo dependency; As far as I see, wherever we have defined the plugin, the generated classes will be created there.


Update: I had to add the runtime dependency to the App module. "com.apollographql.apollo3:apollo-runtime:3.2.1"

martinbonnin commented 2 years ago

@Drjacky Can you open a separate issue to investigate this? I'd like to keep each issue focused on one problem else the SEO becomes really weird and people ending up here will be confused.