Skip to content

Commit

Permalink
ìmprove downloadApolloSchema for projects with variants (#2712)
Browse files Browse the repository at this point in the history
* relax the condition on variant name to find the default schema
  location
* always allow to override it with the `--schema` option

closes #2710
  • Loading branch information
martinbonnin committed Nov 2, 2020
1 parent 48e756d commit ac41b67
Showing 1 changed file with 5 additions and 10 deletions.
Expand Up @@ -90,7 +90,7 @@ abstract class ApolloDownloadSchemaCliTask : DefaultTask() {
return@filter true
}

it.variantName == "main" || it.variantName == "release"
it.variantName == "main" || it.variantName.toLowerCase().contains("release")
}

val compilationUnit = if (service.isPresent) {
Expand All @@ -102,23 +102,18 @@ abstract class ApolloDownloadSchemaCliTask : DefaultTask() {
candidates.firstOrNull()
}

check(compilationUnit != null) {
val services = compilationUnits.map { it.serviceName }.distinct().sorted().joinToString("\n")
val variants = compilationUnits.map { it.variantName }.distinct().sorted().joinToString("\n")
"Cannot find compilation unit, check variant and service.\nPossible services:\n$services\nPossible variants:\n$variants"
}

val (compilerParams, _) = compilationUnit.resolveParams(project)
val compilerParams = compilationUnit?.resolveParams(project)?.first

var endpointUrl = endpoint.orProperty("endpoint") ?: compilationUnit.service.introspection?.endpointUrl?.get()
var endpointUrl = endpoint.orProperty("endpoint") ?: compilationUnit?.service?.introspection?.endpointUrl?.get()

val schema = schema.orProperty("schema")?.let {
if (schema.isPresent) {
File(it) // commandline is resolved relative to cwd
} else {
project.file(it) // relative to project. This is not super consistent but 🤷‍
}
} ?: compilerParams.schemaFile.asFile.get()
} ?: compilerParams?.schemaFile?.asFile?.get()
?: throw IllegalArgumentException("ApolloGraphQL: cannot determine where to save the schema. Specify --schema or --service")

val headersProp = project.findProperty("com.apollographql.apollo.headers") as? String
val headers = when {
Expand Down

0 comments on commit ac41b67

Please sign in to comment.