I create task to download schema when gradle is build.
task downloadSchem (type: Exec) {
commandLine './gradlew', "downloadApolloSchema -Pcom.apollographql.apollo.endpoint=myurl -Pcom.apollographql.apollo.schema=my_path/schema.json"
}
But after executing this task I got below error
Task ''downloadApolloSchema' '-Pcom.apollographql.apollo.endpoint=myurl -Pcom.apollographql.apollo.schema=my_path/schema.json'' not found in root project 'android-XXX'.
Do you apply the apollo plugin in the rootProject ? If not, you might have to specify the module:
./gradlew :module:downloadApolloSchema
In all cases, if you're doing this from your gradle scripts, you can use the Task directly:
tasks.register("downloadSchema", ApolloDownloadSchemaTask::class.java) {
endpointUrl.set("https://")
schemaFilePath.set("src/main/graphql/com/example/schema.json")
}
What is 'ApolloDownloadSchemaTask' class. It is not not available in gradle script. Or I must create that class. If it is so from which Apollo class I must extend it.
Note: The apollo client works fine in project. I have properly configure it. I just want automatically download schema.json.
Do you have some example for that?
What is 'ApolloDownloadSchemaTask' class. It is not not available in gradle script.
ApolloDownloadSchemaTask is the task that takes care of executing the introspection query and saving the result to a schema.json file. It should be available from your Gradle scripts. Maybe try with the fully qualified name:
tasks.register("downloadSchema", com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask::class.java) {
endpointUrl.set("https://")
schemaFilePath.set("src/main/graphql/com/example/schema.json")
}
There are no any 'internal' package only this two

and both with this classes

What version of apollo-android are you using ? The ApolloDownloadSchemaTask is only available with version 1.3+.

and
apply plugin: 'com.apollographql.apollo'
AndroidTaskConfiguratorFactory was a class from the old Gradle plugin, it shouldn't be there in 2.0.3 anymore. So I guess something is wrong in your IDE/Gradle configuration.
com.apollographql.apollo is the new plugin ID so that part looks good. Do you have the old plugin dependency in your buildscript {} block or buildSrc/build.gradle.kts maybe ?
A example of how it should work: https://github.com/martinbonnin/github-graphql-sample/blob/f9ac731b61208daf1558fd0328069896b2f01f42/app/build.gradle.kts#L92
> git clone https://github.com/martinbonnin/github-graphql-sample
> cd github-graphql-sample/
> git checkout f9ac731b61208daf1558fd0328069896b2f01f42
> echo "ext.githubToken='YOUR_GITHUB_TOKEN'" > app/github.properties
> ./gradlew downloadSchema
I'm closing this issue, please leave a message if you want me to reopen it.
Sorry for late answer.
I checked your example. But I can not register below task
tasks.register("downloadSchema", com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask::class.java) {
endpointUrl.set("https://api.github.com/graphql")
schemaFilePath.set("src/main/graphql/net/mbonnin/githubgraphqlsample/schema.json")
headers.set(mapOf("Authorization" to "Bearer ${githubToken()}"))
}
Below Is my gradle configuration apollo plugin updated as well.

and below what is only available

A sample is there: https://github.com/martinbonnin/apollo-android-samples/blob/8320bb095671d8d06dc5c78306e9b31cb5e4a0c7/download-schema-task/build.gradle#L10:
tasks.register("downloadSchema", com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask) {
endpoint = "https://apollo-fullstack-tutorial.herokuapp.com/"
schemaRelativeToProject = "src/main/graphql/net/sample/schema.json"
}
But if you're mainly looking for a way to download the schema.json from the command-line, I recommend you use the task that is registered by the plugin automatically:
./gradlew downloadApolloSchema --endpoint "https://apollo-fullstack-tutorial.herokuapp.com/" --schema src/main/graphql/net/sample/schema.json
Thanks after moving this part to top-level gradle file I can dowload the schema.json file.
I've implemented something similar but stumbled upon some weird gradle issue
java.lang.NoClassDefFoundError: Could not initialize class okhttp3.internal.Util
I've got this code
tasks.register("downloadSchema", com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask) {
it.endpoint = "http://localhost:3000/graph/token"
it.schemaRelativeToProject = "app/src/main/graphql/baba.json"
it.setHeader(["Authorization: Bearer${obtainToken()}".toString()])
}
I've tried with the latest gradle plugin version - 6.8.3 and still no success, any suggestions?
@teodorpenkov that sounds like Gradle has 2 different versions of OkHttp in the classpath. If you're using buildSrc, make sure to put com.apollographql.apollo:apollo-gradle-plugin in the buildSrc dependencies so that dependency resolution can happen. If not, try ./gradlew buildEnvironment to check where the two OkHttp versions might come from.
@martinbonnin that's what I thought too but unfortunately there is only 1 version :(
The funny thing is I tried with a previous version of gradle and it worked fine, but then compose didn't work 馃し
Have you tried Android studio that includes the beta of jetpack compose + apollo's schema introspection task?
Gradle version - 6.8.2
Android Gradle Plugin - 7.0.0-alpha10
I also found this issue here which seems related https://github.com/JetBrains/gradle-intellij-plugin/issues/522
unfortunately there is only 1 version
Yeaaa, buildEnvironment might be wrong sometimes (see https://github.com/gradle/gradle/issues/8301). Also, there are 2 build environments: ./gradlew buildEnvironment and ./gradlew :app:buildEnvironment.
My guess is that your root project has okio 1.x (most likely 1.13.0 ?). And this get loaded in the build classpath before the one from the apollo plugin (requires 2.x something)?
If that's still happening, can you upload a small reproducer somewhere?
@teodorpenkov this should fix it: https://github.com/martinbonnin/BuildEnvironmentIssue/commit/af3ee390635ceb049835a1244b16e33d35344605
totally fixed it, thanks :)
Any ideas why does this happen? It's working on previous gradle version 馃し
@teodorpenkov it's linked to how Gradle deals with classloaders. I'm not 100% sure how that works. There's some info in the links below:
Most helpful comment
A sample is there: https://github.com/martinbonnin/apollo-android-samples/blob/8320bb095671d8d06dc5c78306e9b31cb5e4a0c7/download-schema-task/build.gradle#L10:
But if you're mainly looking for a way to download the schema.json from the command-line, I recommend you use the task that is registered by the plugin automatically: