Stylianos Gakis
02/24/2022, 9:42 AMStylianos Gakis
02/24/2022, 9:43 AMtasks.withType<com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask>().configureEach {
setFinalizedBy(listOf("updateSchema"))
}
tasks.register("updateSchema") {
val downloadedSchema = file("src/main/graphql/com/hedvig/android/owldroid/schema.graphqls")
val patchedSchema = file("src/main/graphql/com/hedvig/android/owldroid/schema.graphqls")
inputs.file(downloadedSchema)
outputs.file(patchedSchema)
doLast {
patchedSchema.writeText(
downloadedSchema.readText().replace(
oldValue = "\"\"\"${System.lineSeparator()} \"\"\"",
newValue = "\"\"\"",
ignoreCase = false
)
)
}
}
Which Iâd have hoped it works but doesnât seem to.Stylianos Gakis
02/24/2022, 9:45 AMdownloadGiraffeSchemaFromIntrospection
directly and have it work for hem, hence trying to go with the approach above. But I am not sure gradle likes that approach, googling online a bunch of people tell how one should always use the dependsOn instead, to depend on stuff done before and not after what youâre doing. If you have any idea how Iâd fix my code snippet above itâd be awesome!bod
02/24/2022, 9:53 AMtasks.withType(com.apollographql.apollo3.gradle.internal.ApolloDownloadSchemaTask::class.java) {
doLast {
// your custom code
}
}
(at least âyour custom codeâ was called when I tried it đ
)Stylianos Gakis
02/24/2022, 10:08 AMinputs.file(downloadedSchema)
outputs.file(patchedSchema)
canât exist in there like this.
And I canât figure out if itâs possible to instead inside the doLast{} lambda to actually call a whole task.
Current code that doesnât work for reference:
tasks.withType(com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask::class.java) {
doLast {
val downloadedSchema = file("src/main/graphql/com/hedvig/android/owldroid/schema.graphqls")
val patchedSchema = file("src/main/graphql/com/hedvig/android/owldroid/schema.graphqls")
inputs.file(downloadedSchema)
outputs.file(patchedSchema)
patchedSchema.writeText(
downloadedSchema.readText().replace(
oldValue = "\"\"\"${System.lineSeparator()} \"\"\"",
newValue = "\"\"\"",
ignoreCase = false
)
)
}
}
bod
02/24/2022, 10:12 AMStylianos Gakis
02/24/2022, 10:16 AMbod
02/24/2022, 10:20 AMStylianos Gakis
02/24/2022, 10:21 AMtasks.withType(com.apollographql.apollo3.gradle.internal.ApolloDownloadSchemaTask::class.java) {
doLast {
val downloadedSchema = file("src/commonMain/graphql/com/hedvig/embarkx/schema.graphqls")
val patchedSchema = file("src/commonMain/graphql/com/hedvig/embarkx/schema.graphqls")
patchedSchema.writeText(
downloadedSchema.readText()
.replace(
oldValue = "\"\"\"${System.lineSeparator()} \\\"\"\"",
newValue = "\"\"\"",
ignoreCase = false
)
.replace(
oldValue = "\\\"\"\"${System.lineSeparator()} \"\"\"",
newValue = "\"\"\"",
ignoreCase = false
)
)
}
}
(Notice a change in the replace methods, as in apollo 2 the comment gets generated as pic1 and in apollo 3 it gets generated as pic2 đbod
02/24/2022, 10:22 AMStylianos Gakis
02/24/2022, 10:23 AMtasks.withType(com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask::class.java) {
doLast {
val downloadedSchema = file("src/main/graphql/com/hedvig/android/owldroid/schema.graphqls")
val patchedSchema = file("src/main/graphql/com/hedvig/android/owldroid/schema.graphqls")
patchedSchema.writeText(
downloadedSchema.readText().replace(
oldValue = "\"\"\"${System.lineSeparator()} \"\"\"",
newValue = "\"\"\"",
ignoreCase = false
)
)
}
}
Nothing inside there runs ever. It feels like either I am using the wrong import somehow, or weâre changing the task somehow somewhere else? Not sure how thatâd be possible, but it is indeed very weirdStylianos Gakis
02/24/2022, 10:31 AMApolloDownloadSchemaTask
function right?
The only other difference that I can see if that in the v2.0 version I am calling just ./gradlew downloadApolloSchema
since weâre not using the service("name")
block in our apollo configuration
While in the 3.0 version I am calling ./gradlew :shared:downloadGiraffeApolloSchemaFromIntrospection
since we are using the service name there.
I canât see any other reason just a simple tasks.withType<>() on the DownloadTask would just not work. Maybe this isnât worth looking into anyway, since weâre eveeentually gonna go to 3.0 anyway, but itâs interesting nonethelessbod
02/24/2022, 10:34 AMStylianos Gakis
02/24/2022, 10:37 AMbod
02/24/2022, 10:39 AMmbonnin
02/24/2022, 1:17 PMThe only other difference that I can see if that in the v2.0 version I am calling justÂThis is the difference. 2.x has 2 classes: â˘./gradlew downloadApolloSchema
ApolloDownloadSchemaTask
: to download from introspection
⢠ApolloDownloadSchemaCliTask
: to download from the command linembonnin
02/24/2022, 1:17 PMmbonnin
02/24/2022, 1:23 PM# or ApolloDownloadSchemaCliTask if you're on 2.x and calling downloadApolloSchema
tasks.withType(com.apollographql.apollo3.gradle.internal.ApolloDownloadSchemaTask::class.java) {
doLast {
// your custom code
}
}
The only drawback is that it uses internal APIs.mbonnin
02/24/2022, 1:24 PMtasks.register("updateSchema") {
dependsOn("downloadGiraffeApolloSchemaFromIntrospection")
inputs.file(downloadedSchema)
outputs.file(patchedSchema)
doLast {
patchedSchema.writeText(downloadedSchema.readText().replace("\\\"\"\"", ""))
}
}
mbonnin
02/24/2022, 1:24 PMupdateSchema
instead of downloadGiraffeApolloSchemaFromIntrospection
mbonnin
02/24/2022, 1:25 PMFileProperty
that carries task dependenciesFabio
02/25/2022, 2:42 AMI like this snippet for different reasons, I've noticed I get lots of extraCopy codepatchedSchema.writeText(downloadedSchema.readText().replace("\\\"\"\"", ""))
\n
when I download schema for the first time with apollo v3. Haven't looked into it, but I'll assume I can revert to v2 behavior somehow? Something like replace ("\n\n", "\n" )
or easier ?
Otherwise I'm going to get a lot of flak from my team when I land my v3 upgrade.mbonnin
02/25/2022, 8:38 AMtype LaunchConnection {
cursor: String!
hasMore: Boolean!
launches: [Launch]!
}
instead of
type LaunchConnection {
cursor: String!
hasMore: Boolean!
launches: [Launch]!
}
mbonnin
02/25/2022, 8:39 AMreplace ("\n\n", "\n" )
will make everything more packedmbonnin
02/25/2022, 8:40 AMmbonnin
02/25/2022, 10:20 AMStylianos Gakis
02/25/2022, 11:32 AMStylianos Gakis
08/21/2022, 1:00 PMwithType
a configureEach
block to turn it into a lazy configuration.
For the sake of myself and whoever happens to see this thread in the future, wouldnât that mean that one should probably adjust the snippet provided here to add the configureEach block? Maybe the doLast
running every time isnât a big deal, but at the same time this probably doesnât need to run every time if youâre doing something unrelated right?bod
08/21/2022, 1:16 PMadjust the snippet provided here to add the configureEach block?I think, yes đ
Stylianos Gakis
08/21/2022, 1:18 PMbod
08/21/2022, 1:20 PMhow much there is I donât know about GradleSame here đ Gradle is huge! Probably because it's been around for a while.