diff --git a/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/ApolloKotlinService.kt b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/ApolloKotlinService.kt index 10841424d56..7edc462b274 100644 --- a/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/ApolloKotlinService.kt +++ b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/ApolloKotlinService.kt @@ -43,6 +43,9 @@ data class ApolloKotlinService( @XCollection val endpointHeaders: Map? = null, + + @XCollection + val upstreamServiceIds: List = emptyList(), ) { data class Id( @Attribute @@ -52,21 +55,19 @@ data class ApolloKotlinService( val serviceName: String = "", ) { override fun toString(): String { - val formattedPath = gradleProjectPath.split(":").filterNot { it.isEmpty() }.joinToString("-") - return "$formattedPath/$serviceName" + return "$gradleProjectPath/$serviceName" } companion object { fun fromString(string: String): Id? { - val split = string.split("/") + val split = string.split("/", limit = 2) if (split.size != 2) return null return Id(split[0], split[1]) } } } - val id + val id: Id @Transient get() = Id(gradleProjectPath, serviceName) - } diff --git a/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/GradleToolingModelService.kt b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/GradleToolingModelService.kt index c3809e4e4ac..c9951707036 100644 --- a/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/GradleToolingModelService.kt +++ b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/GradleToolingModelService.kt @@ -257,6 +257,7 @@ class GradleToolingModelService( .distinct(), endpointUrl = serviceInfo.endpointUrlCompat(toolingModel), endpointHeaders = serviceInfo.endpointHeadersCompat(toolingModel), + upstreamServiceIds = upstreamApolloKotlinServices.map { it.id } ) } } diff --git a/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/studio/fieldinsights/FieldInsightsService.kt b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/studio/fieldinsights/FieldInsightsService.kt index 5ef300e37e4..9fe8942dd9d 100644 --- a/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/studio/fieldinsights/FieldInsightsService.kt +++ b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/studio/fieldinsights/FieldInsightsService.kt @@ -126,8 +126,20 @@ class FieldInsightsServiceImpl(private val project: Project) : FieldInsightsServ return fieldLatenciesByService.isNotEmpty() } + private fun getFieldLatenciesForService(serviceId: ApolloKotlinService.Id): FieldInsights.FieldLatencies? { + if (fieldLatenciesByService.containsKey(serviceId)) { + return fieldLatenciesByService[serviceId] + } + // Try upstream services + val apolloKotlinService = GradleToolingModelService.getApolloKotlinServices(project).firstOrNull { it.id == serviceId } ?: return null + for (upstreamServiceId in apolloKotlinService.upstreamServiceIds) { + return getFieldLatenciesForService(upstreamServiceId) ?: continue + } + return null + } + override fun getLatency(serviceId: ApolloKotlinService.Id, typeName: String, fieldName: String): Double? { - return fieldLatenciesByService[serviceId]?.getLatency(parentType = typeName, fieldName = fieldName) + return getFieldLatenciesForService(serviceId)?.getLatency(parentType = typeName, fieldName = fieldName) } private fun refreshInspections() {