Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move computing the alwaysGenerateTypesMatching to execution time #4578

Merged
merged 1 commit into from Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -42,6 +42,7 @@ import com.apollographql.apollo3.compiler.ScalarInfo
import com.apollographql.apollo3.compiler.TargetLanguage
import com.apollographql.apollo3.compiler.hooks.ApolloCompilerJavaHooks
import com.apollographql.apollo3.compiler.hooks.ApolloCompilerKotlinHooks
import com.apollographql.apollo3.compiler.toUsedCoordinates
import org.gradle.api.DefaultTask
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
Expand Down Expand Up @@ -73,6 +74,10 @@ abstract class ApolloGenerateSourcesTask : DefaultTask() {
@get:Optional
abstract val metadataOutputFile: RegularFileProperty

@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val usedCoordinates: ConfigurableFileCollection

@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val graphqlFiles: ConfigurableFileCollection
Expand Down Expand Up @@ -323,12 +328,17 @@ abstract class ApolloGenerateSourcesTask : DefaultTask() {
else -> commonMetadata.codegenModels
}

val alwaysGenerateTypesMatching = usedCoordinates.files.map { it.toUsedCoordinates() }
.fold(alwaysGenerateTypesMatching.getOrElse(defaultAlwaysGenerateTypesMatching)) { acc, new ->
acc + new
}

val options = Options(
executableFiles = graphqlFiles.files,
outputDir = outputDir.asFile.get(),
testDir = testDir.asFile.get(),
debugDir = debugDir.asFile.orNull,
alwaysGenerateTypesMatching = alwaysGenerateTypesMatching.getOrElse(defaultAlwaysGenerateTypesMatching),
alwaysGenerateTypesMatching = alwaysGenerateTypesMatching,
operationOutputFile = operationOutputFile.asFile.orNull,
operationOutputGenerator = operationOutputGenerator,
useSemanticNaming = useSemanticNaming.getOrElse(defaultUseSemanticNaming),
Expand Down
Expand Up @@ -746,17 +746,11 @@ abstract class DefaultApolloExtension(
}
task.packageNameGenerator = packageNameGenerator
task.generateFilterNotNull.set(project.isKotlinMultiplatform)
task.alwaysGenerateTypesMatching.set(project.provider {
val jsonFiles = if (service.usedCoordinates != null) {
listOf(service.usedCoordinates!!)
} else {
usedCoordinatesConsumerConfiguration.files
}
jsonFiles.map { it.toUsedCoordinates() }
.fold(service.alwaysGenerateTypesMatching.getOrElse(emptySet())) { acc, new ->
acc + new
}
})
task.usedCoordinates.from(usedCoordinatesConsumerConfiguration)
if (service.usedCoordinates != null) {
task.usedCoordinates.from(service.usedCoordinates)
}
task.alwaysGenerateTypesMatching.set(service.alwaysGenerateTypesMatching)
task.projectPath.set(project.path)
task.generateFragmentImplementations.set(service.generateFragmentImplementations)
task.generateQueryDocument.set(service.generateQueryDocument)
Expand Down