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

[apollo-tooling] bump bootstraped version of Apollo to 4.0.0-beta.3 #5452

Merged
merged 14 commits into from
Dec 15, 2023
Merged
2 changes: 1 addition & 1 deletion gradle/libraries.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ androidx-sqlite = "2.3.1"
# This is used by the gradle integration tests to get the artifacts locally
apollo = "4.0.0-beta.4-SNAPSHOT"
# Used by the apollo-tooling project which uses a published version of Apollo
apollo-published = "4.0.0-beta.2"
apollo-published = "4.0.0-beta.3"
cache = "2.0.2"
# See https://developer.android.com/jetpack/androidx/releases/compose-kotlin
compose-compiler = "1.5.5-dev-k2.0.0-Beta1-06b8ae672a4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
type Query {
apolloClients: [ApolloClient!]!
"""
Returns null if an ApolloClient with the given id is not found.
"""
apolloClient(id: ID!): ApolloClient
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extend schema @link(url: "https://specs.apollo.dev/nullability/v0.1", import: ["@catch", "CatchTo"])
extend schema @catch(to: THROW)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extend schema @link(url: "https://specs.apollo.dev/nullability/v0.1", import: ["@semanticNonNull", "@catch", "CatchTo"])
extend schema @catch(to: THROW)

extend type Service @semanticNonNull(field: "statsWindow")
extend type ServiceMutation @semanticNonNull(field: "registerOperationsWithResponse")
extend type ServiceStatsWindow @semanticNonNull(field: "fieldLatencies")
extend type RegisterOperationsMutationResponse @semanticNonNull(field: "invalidOperations")
# Not sure if errors can be null or not
# extend type InvalidOperation @semanticNonNull(field: "errors")
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extend schema @link(url: "https://specs.apollo.dev/nullability/v0.1", import: ["@semanticNonNull", "@catch", "CatchTo"])
extend schema @catch(to: THROW)

extend type GraphMutation @semanticNonNull(field: "uploadSchema")
extend type GraphMutation @semanticNonNull(field: "publishSubgraph")
extend type GraphVariant @semanticNonNull(field: "latestPublication")
extend type SchemaPublication @semanticNonNull(field: "schema")
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.apollographql.apollo3.tooling

import com.apollographql.apollo3.annotations.ApolloExperimental
import com.apollographql.apollo3.exception.ApolloGraphQLException
import com.apollographql.apollo3.exception.ApolloHttpException
import com.apollographql.apollo3.tooling.platformapi.internal.FieldLatenciesQuery
import java.time.Instant
Expand Down Expand Up @@ -33,31 +32,10 @@ object FieldInsights {
)
).execute()
val data = response.data
return when {
data == null -> {
val cause = when (val e = response.exception!!) {
is ApolloHttpException -> {
val body = e.body?.use { it.readUtf8() } ?: ""
Exception("Cannot fetch field latencies: (code: ${e.statusCode})\n$body", e)
}

is ApolloGraphQLException -> {
Exception("Cannot fetch field latencies: ${e.errors.joinToString { it.message }}")
}

else -> {
Exception("Cannot fetch field latencies: ${e.message}", e)
}
}
FieldLatenciesResult.Error(cause = cause)
}

data.service == null && response.hasErrors() -> {
FieldLatenciesResult.Error(cause = Exception("Cannot fetch field latencies: ${response.errors!!.joinToString { it.message }}"))
}

else -> {
FieldLatencies(fieldLatencies = data.service?.statsWindow?.fieldLatencies?.mapNotNull {
if (data != null) {
val service = data.service
return if (service != null) {
FieldLatencies(fieldLatencies = service.statsWindow.fieldLatencies.mapNotNull {
val parentType = it.groupBy.parentType ?: return@mapNotNull null
val fieldName = it.groupBy.fieldName ?: return@mapNotNull null
val durationMs = it.metrics.fieldHistogram.durationMs ?: return@mapNotNull null
Expand All @@ -66,9 +44,27 @@ object FieldInsights {
fieldName = fieldName,
durationMs = durationMs
)
} ?: emptyList())
})
} else {
FieldLatenciesResult.Error(cause = Exception("Cannot find service $serviceId: ${response.errors?.joinToString { it.message }}}"))
}
}

val cause = when (val e = response.exception) {
is ApolloHttpException -> {
val body = e.body?.use { it.readUtf8() } ?: ""
Exception("Cannot fetch field latencies: (code: ${e.statusCode})\n$body", e)
}

null -> {
Exception("Cannot fetch field latencies: ${response.errors?.joinToString { it.message }}")
}

else -> {
Exception("Cannot fetch field latencies: ${e.message}")
}
}
return FieldLatenciesResult.Error(cause = cause)
}

@ApolloExperimental
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,39 @@ fun publishOperations(
.execute()
}

val graph1 = response.dataOrThrow().graph
if (graph1 == null) {
return GraphNotFound
}

val ops = graph1.persistedQueryList.publishOperations
return when {
ops.onPublishOperationsResult != null -> {
val counts = ops.onPublishOperationsResult.build.publish.operationCounts
PublishOperationsSuccess(
counts.added,
counts.removed,
counts.identical,
counts.updated,
counts.unaffected,
ops.onPublishOperationsResult.build.list.name,
ops.onPublishOperationsResult.build.revision
)
}
ops.onPermissionError != null -> {
PermissionError(ops.onPermissionError.message)
val data = response.data
if (data != null) {
val graph1 = data.graph
if (graph1 == null) {
return GraphNotFound
}
ops.onCannotModifyOperationBodyError != null -> {
CannotModifyOperationBody(ops.onCannotModifyOperationBodyError.message)
val ops = graph1.persistedQueryList.publishOperations
return when {
ops.onPublishOperationsResult != null -> {
val counts = ops.onPublishOperationsResult.build.publish.operationCounts
PublishOperationsSuccess(
counts.added,
counts.removed,
counts.identical,
counts.updated,
counts.unaffected,
ops.onPublishOperationsResult.build.list.name,
ops.onPublishOperationsResult.build.revision
)
}
ops.onPermissionError != null -> {
PermissionError(ops.onPermissionError.message)
}
ops.onCannotModifyOperationBodyError != null -> {
CannotModifyOperationBody(ops.onCannotModifyOperationBodyError.message)
}
else -> error("Unknown ops: ${ops.__typename}")
}
else -> error("")
}

if (response.exception != null) {
throw Exception("Cannot publish operations", response.exception)
}

throw Exception("Cannot publish operations: ${response.errors?.joinToString { it.message }}")
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.apollographql.apollo3.ast.transform
import com.apollographql.apollo3.compiler.APOLLO_VERSION
import com.apollographql.apollo3.compiler.OperationIdGenerator
import com.apollographql.apollo3.compiler.operationoutput.OperationOutput
import com.apollographql.apollo3.exception.ApolloGraphQLException
import com.apollographql.apollo3.exception.ApolloHttpException
import com.apollographql.apollo3.tooling.platformapi.internal.RegisterOperationsMutation
import com.apollographql.apollo3.tooling.platformapi.internal.type.RegisteredClientIdentityInput
Expand Down Expand Up @@ -255,30 +254,34 @@ object RegisterOperations {

val response = runBlocking { call.execute() }
val data = response.data
if (data == null) {
when (val e = response.exception!!) {
is ApolloHttpException -> {
val body = e.body?.use { it.readUtf8() } ?: ""
throw Exception("Cannot push operations: (code: ${e.statusCode})\n$body", e)
}

is ApolloGraphQLException -> {
throw Exception("Cannot push operations: ${e.errors.joinToString { it.message }}")
}

else -> {
throw Exception("Cannot push operations: ${e.message}", e)
}
if (data != null) {
val service = data.service
if (service == null) {
throw Exception("Cannot push operations: cannot find service '$graphID': ${response.errors?.joinToString { it.message }}")
martinbonnin marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
val errors = data.service?.registerOperationsWithResponse?.invalidOperations?.flatMap {
val errors = data.service.registerOperationsWithResponse.invalidOperations.flatMap {
it.errors ?: emptyList()
} ?: emptyList()
}

check(errors.isEmpty()) {
"Cannot push operations:\n${errors.joinToString("\n")}"
if(errors.isNotEmpty()) {
throw Exception("Cannot push operations:\n${errors.joinToString("\n")}")
}
println("Operations pushed successfully")
return
}
when (val e = response.exception) {
is ApolloHttpException -> {
val body = e.body?.use { it.readUtf8() } ?: ""
throw Exception("Cannot push operations: (code: ${e.statusCode})\n$body", e)
}

null -> {
throw Exception("Cannot push operations: ${response.errors?.joinToString { it.message }}")
}

else -> {
throw Exception("Cannot push operations: ${e.message}", e)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,23 @@ object SchemaDownloader {
.httpHeaders(headers.map { HttpHeader(it.key, it.value) } + HttpHeader("x-api-key", key))
.execute()
}
if (response.exception != null) throw response.exception!!
if (response.errors?.isNotEmpty() == true) {
throw Exception("Cannot retrieve document from $endpoint: ${response.errors!!.joinToString { it.message }}\nCheck graph id and variant")
val data = response.data

if (data != null) {
if (data.graph == null) {
throw Exception("Cannot retrieve graph '$graph': ${response.errors?.joinToString { it.message }}")
}
if (data.graph.variant == null) {
throw Exception("Cannot retrieve variant '$variant': ${response.errors?.joinToString { it.message }}")
}
return data.graph.variant.latestPublication.schema.document
}
val document = response.data?.graph?.variant?.latestPublication?.schema?.document
check(document != null) {
"Cannot retrieve document from $endpoint\nCheck graph id and variant"

if (response.exception != null) {
throw response.exception!!
}
return document

throw Exception("Cannot retrieve document from $endpoint: ${response.errors?.joinToString { it.message }}\nCheck graph id and variant")
}

inline fun <reified T> Any?.cast() = this as? T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,22 @@ internal object SchemaHelper {
.httpHeaders(headers.map { HttpHeader(it.key, it.value) })
.execute()
}
response.exception?.let { e ->
if (e is ApolloHttpException) {
val data = response.data
if (data != null) {
return data
}
when (val e = response.exception) {
is ApolloHttpException -> {
val body = e.body?.use { it.readUtf8() } ?: ""
throw Exception("Cannot execute pre-introspection query from $endpoint: (code: ${e.statusCode})\n$body", e)
}
throw e
}
if (response.errors?.isNotEmpty() == true) {
throw Exception("Cannot execute pre-introspection query from $endpoint: ${response.errors!!.joinToString { it.message }}")
null -> {
throw Exception("Cannot execute pre-introspection query from $endpoint: ${response.errors?.joinToString { it.message }}")
}
else -> {
throw Exception("Cannot execute pre-introspection query from $endpoint", e)
}
}
return response.data!!
}

internal fun executeIntrospectionQuery(
Expand Down