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.75k stars 651 forks source link

Download schema as described in docs does not work #5613

Closed dannylagrouw closed 8 months ago

dannylagrouw commented 8 months ago

Version

3.8.2

Summary

Downloading a schema, as described in the docs (https://www.apollographql.com/docs/kotlin/advanced/plugin-configuration) results in an error because of a missing schema property. Creating my own download task shows that the projectRootDir property is also missing.

Steps to reproduce the behavior

When trying to download a schema, as described in the docs (https://www.apollographql.com/docs/kotlin/advanced/plugin-configuration):

apollo {
  service("starwars") {
    packageName.set("com.starwars")
    introspection {
      endpointUrl.set("https://your.domain/graphql/endpoint")
      schemaFile.set(file("src/main/graphql/com/example/schema.graphqls"))
    }
  }
}

I get an error:

In plugin 'com.apollographql.apollo3' type 'com.apollographql.apollo3.gradle.internal.ApolloDownloadSchemaTask' property 'schema' doesn't have a configured value.

Maybe because the schema property in the download task is not being set in DefaultApolloExtension?

Alternatively, I tried creating my own task:

project.tasks.register("downloadSchema", ApolloDownloadSchemaTask::class.java) {
    endpoint.set("https://some.url")
    schema.set("src/main/graphql/schema.graphqls")
}

This results in a cryptic:

java.lang.NullPointerException (no error message)

In the end I found from the source that the projectRootDir property in ApolloDownloadSchemaTask is not initialized either. When I add projectRootDir = project.projectDir.absolutePath to my task, it finally works.

Logs

No response

martinbonnin commented 8 months ago

Hi 👋

apollo {
  service("starwars") {
    packageName.set("com.starwars")
    introspection {
      endpointUrl.set("https://your.domain/graphql/endpoint")
      schemaFile.set(file("src/main/graphql/com/example/schema.graphqls"))
    }
  }
}

Could it be that schemaFile here resolves to something else than introspection.schemaFile? There is also a service.schemaFile so it's easy to have scoping errors here. If not, could you share a small reproducer? I tried to reproduce here without success so far.

martinbonnin commented 8 months ago

Ah, nevermind, I think I have it. 2 tasks are created:

./gradlew downloadApolloSchema --schema schema.graphqls --endpoint https://example.com/graphql
./gradlew downloadStarwarsApolloSchemaFromIntrospection

Can you confirm if it's what's happening?

Agree this is confusing and in the long run I'd like to remove the CLI one for a proper one alas removing stuff always take times so we'll get there. In the meantime, I'll add a note in the docs to guard against this.

dannylagrouw commented 8 months ago

Hmm, I don't have a downloadStarwarsApolloSchemaFromIntrospection (or any task download...FromIntrospection), just the downloadApolloSchema.

martinbonnin commented 8 months ago

Can you share your Gradle configuration?

dannylagrouw commented 8 months ago

Interesting. I went back to re-create the introspection setup so I could show you and... the ...FromIntrospection task appeared. And worked fine as well. So just a clarification in the docs would probably clear all this up. Thanks for helping!

martinbonnin commented 8 months ago

👍 thanks for the update. Note added in the docs there

martinbonnin commented 8 months ago

I'll close this one for now, please let us know if you bump into other issues.