Stylianos Gakis
03/07/2023, 12:32 PMclass ApolloConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
val libs = the<LibrariesForLibs>()
with(pluginManager) { apply(libs.plugins.apollo.get().pluginId) }
...
tasks.register("downloadApolloSchemasFromIntrospection") {
dependsOn(tasks.withType<com.apollographql.apollo3.gradle.internal.ApolloDownloadSchemaTask>())
}
}
}
}
but interestingly, when I run
./gradlew downloadApolloSchemasFromIntrospection
I get the error:
A problem was found with the configuration of task ':apollo:giraffe:downloadApolloSchema' (type 'ApolloDownloadSchemaTask').
- In plugin 'com.apollographql.apollo3' type 'com.apollographql.apollo3.gradle.internal.ApolloDownloadSchemaTask' property 'schema' doesn't have a configured value.
Yet the schemas are downloaded perfectly fine, even though both apollo:module1:downloadApolloSchema
and apollo:module2:downloadApolloSchema
says that it failed for both.
My assumption here is that there’s multiple tasks of type ApolloDownloadSchemaTask, and I want to run the task which uses the type generated in DefaultApolloExtension instead maybe?
Any thoughts why the task says it fails but it doesn’t actually. Or if I can somehow target specifically that task, so that it doesn’t run the generic downloadApolloSchema
I think optimally I’d want it to run apollo:module1:downloadService1ApolloSchemaFromIntrospection
and apollo:module2:downloadService2ApolloSchemaFromIntrospection
insteadtasks.withType<com.apollographql.apollo3.gradle.internal.ApolloDownloadSchemaTask>().configureEach {
doLast {
val schemaPath = schema.get()
val schemaFile = file(schemaPath)
val textWithoutDoubleLineBreaks = schemaFile.readText().replace("\n\n", "\n")
schemaFile.writeText(textWithoutDoubleLineBreaks)
}
}
and to give a simple task to run once, both for CI to only have to call 1 gradle task, and to make it easier for my colleagues instead of running two things at the same time. So if there’s some existing task that downloads all those schemas that I am missing I’d love to just use that instead.bod
03/07/2023, 1:06 PMtasks.withType<com.apollographql.apollo3.gradle.internal.ApolloDownloadSchemaTask>()
returns the one that's configured explicitly, and the generic one that expects to pass a schema as a parameter...mbonnin
03/07/2023, 1:07 PMStylianos Gakis
03/07/2023, 1:07 PMtasks.register("downloadApolloSchemasFromIntrospection") {
dependsOn(tasks.withName("downloadServiceNameApolloSchemaFromIntrospection"))
}
and call top level downloadApolloSchemasFromIntrospection
as it should call both of themmbonnin
03/07/2023, 1:12 PMtasks.withType<com.apollographql.apollo3.gradle.internal.ApolloDownloadSchemaTask>().configureEach {
doLast {
if (schema.isPresent) {
val schemaPath = schema.get()
val schemaFile = file(schemaPath)
val textWithoutDoubleLineBreaks = schemaFile.readText().replace("\n\n", "\n")
schemaFile.writeText(textWithoutDoubleLineBreaks)
}
}
}
Stylianos Gakis
03/07/2023, 1:16 PMtasks.register("downloadApolloSchemasFromIntrospection") {
dependsOn(tasks.findByName("downloadOctopusApolloSchemaFromIntrospection"))
}
apollo:giraffe
tasks.register("downloadApolloSchemasFromIntrospection") {
dependsOn(tasks.findByName("downloadGiraffeApolloSchemaFromIntrospection"))
}
And then just call top level downloadApolloSchemasFromIntrospection
on CI and it seems to work fine.mbonnin
03/07/2023, 1:17 PMStylianos Gakis
03/07/2023, 1:17 PMmbonnin
03/07/2023, 1:18 PMisPresent
is not enough because adding the CLI task as a dependency will try to execute itschema.isPresent
but that's not great eithertasks.register("downloadApolloSchemasFromIntrospection") {
dependsOn(tasks.findByName("downloadOctopusApolloSchemaFromIntrospection"))
}
I also like that it puts all the graph creation closer togetheroutputDirConnection{}
. Using ApolloDownloadSchemaTask
works but isn't great because it's "internal"Stylianos Gakis
03/07/2023, 1:24 PM2. We should ship a proper CLI instead of relying on Gradle to do some CLI stuffWhat would those things be? I find myself comfortable with handling most things with gradle lately, especially with the more familiar I get with gradle itself. How would this world with this CLI look like?
mbonnin
03/07/2023, 1:27 PM$ brew install apollok (apollo kotlin cli)
$ apollok download --endpoint "https://..." --schema schema.graphqls
$ apollok validate --schema schema.graphqls --operation operation.graphl
$ apollok codegen --schema schema.graphqls --operation operation.graphl --out outdir
$ apollok stats --schema schema.graphqls --operation operation.graphl
$ apollok diff --schema1 schema1.graphqls --schema2 schema2.graphqls
Sky is the limitdownloadOctopusApolloSchemaFromIntrospection
but that would remove Gradle downloadApolloSchema
that is only to be used from the CLI (and which causes your original unset property issue)Stylianos Gakis
03/07/2023, 1:31 PMdownloadApolloSchema
is something I’ve never used nor will use as I like to do this through gradle instead.
I really am not a CLI type of person, I like the autocompletion that gradle gives me and all those guarantees that I am not messing up as I typically do with CLIs 😅mbonnin
03/07/2023, 1:32 PMStylianos Gakis
03/07/2023, 1:36 PMtasks.register("downloadApolloSchemasFromIntrospection") {
tasks.findByName("downloadGiraffeApolloSchemaFromIntrospection")?.let { downloadTask ->
dependsOn(downloadTask)
}
tasks.findByName("downloadOctopusApolloSchemaFromIntrospection")?.let { downloadTask ->
dependsOn(downloadTask)
}
}
And this also works. Not even sure I like it, but at least it keeps the gradle.kts file of each individual module smaller and has the convention plugin contain this kind of logic. Which I typically like but now the convention relies on the sub-modules and what service name they specify which is definitely not good :face_with_peeking_eye:
I’ll just stop overthinking this and let it be 😅mbonnin
03/07/2023, 1:38 PMInsomnia/Postman instead of curlI recently switched from Postman to okhttp in Kotlin scripts 🤓
Stylianos Gakis
03/07/2023, 1:40 PMcom.squareup.okhttp3:logging-interceptor:4.10.0
transitively brings in the rest of okhttp right?mbonnin
03/07/2023, 1:41 PMbod
03/07/2023, 1:41 PM\n\n
?)Stylianos Gakis
03/07/2023, 1:45 PMbod
03/07/2023, 1:46 PMStylianos Gakis
03/07/2023, 1:47 PMbod
03/07/2023, 1:49 PMmbonnin
03/08/2023, 7:56 PMStylianos Gakis
03/08/2023, 9:15 PMmbonnin
03/08/2023, 9:18 PMStylianos Gakis
03/08/2023, 9:28 PMdocs
directory 😅 Thanks a lot 😊
I see the “Better support for Jetpack Compose” point there, is there any place where you elaborate a bit further on what this entails? What improvements you want to see there?mbonnin
03/08/2023, 9:36 PMStylianos Gakis
03/08/2023, 9:42 PMmbonnin
03/08/2023, 9:44 PMbod
03/09/2023, 7:31 AMStylianos Gakis
03/09/2023, 7:39 AM