From 81627d6b7cd2e4d0f55cdceb164c254bd31f2413 Mon Sep 17 00:00:00 2001 From: beetzung Date: Sat, 28 Feb 2026 22:44:27 +0100 Subject: [PATCH] Add Apollo-level logging and Kotlin-driven map filter. Pass the map marker online filter as a GraphQL variable from Kotlin so offline-inclusive behavior is controllable in code, and add a shared Apollo interceptor to log each request payload and response outcome for all operations. Made-with: Cursor --- sdk/src/main/graphql/MapLocations.graphql | 4 +- .../kotlin/org/db3/airmq/sdk/di/SDKModule.kt | 6 ++- ...{ApolloMapService.kt => MapServiceImpl.kt} | 6 ++- .../sdk/network/ApolloLoggingInterceptor.kt | 39 +++++++++++++++++++ 4 files changed, 49 insertions(+), 6 deletions(-) rename sdk/src/main/kotlin/org/db3/airmq/sdk/map/{ApolloMapService.kt => MapServiceImpl.kt} (86%) create mode 100644 sdk/src/main/kotlin/org/db3/airmq/sdk/network/ApolloLoggingInterceptor.kt diff --git a/sdk/src/main/graphql/MapLocations.graphql b/sdk/src/main/graphql/MapLocations.graphql index 811e503..e1b3bf3 100644 --- a/sdk/src/main/graphql/MapLocations.graphql +++ b/sdk/src/main/graphql/MapLocations.graphql @@ -1,5 +1,5 @@ -query MapMarkers { - getMarkers { +query MapMarkers($isOnline: Boolean!) { + getMarkers(filter: { isOnline: $isOnline }) { _id name latitude diff --git a/sdk/src/main/kotlin/org/db3/airmq/sdk/di/SDKModule.kt b/sdk/src/main/kotlin/org/db3/airmq/sdk/di/SDKModule.kt index 60af50e..b8460b7 100644 --- a/sdk/src/main/kotlin/org/db3/airmq/sdk/di/SDKModule.kt +++ b/sdk/src/main/kotlin/org/db3/airmq/sdk/di/SDKModule.kt @@ -7,8 +7,9 @@ import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import javax.inject.Singleton -import org.db3.airmq.sdk.map.ApolloMapService +import org.db3.airmq.sdk.map.MapServiceImpl import org.db3.airmq.sdk.map.MapService +import org.db3.airmq.sdk.network.ApolloLoggingInterceptor @Module @InstallIn(SingletonComponent::class) @@ -20,6 +21,7 @@ object SDKModule { fun provideApolloClient(): ApolloClient { return ApolloClient.Builder() .serverUrl(API_URL) + .addInterceptor(ApolloLoggingInterceptor()) .build() } } @@ -29,5 +31,5 @@ object SDKModule { abstract class SDKBindModule { @Binds @Singleton - abstract fun bindMapService(impl: ApolloMapService): MapService + abstract fun bindMapService(impl: MapServiceImpl): MapService } diff --git a/sdk/src/main/kotlin/org/db3/airmq/sdk/map/ApolloMapService.kt b/sdk/src/main/kotlin/org/db3/airmq/sdk/map/MapServiceImpl.kt similarity index 86% rename from sdk/src/main/kotlin/org/db3/airmq/sdk/map/ApolloMapService.kt rename to sdk/src/main/kotlin/org/db3/airmq/sdk/map/MapServiceImpl.kt index e9507bc..74c5856 100644 --- a/sdk/src/main/kotlin/org/db3/airmq/sdk/map/ApolloMapService.kt +++ b/sdk/src/main/kotlin/org/db3/airmq/sdk/map/MapServiceImpl.kt @@ -6,13 +6,15 @@ import javax.inject.Inject import org.db3.airmq.sdk.MapMarkersQuery import org.db3.airmq.sdk.map.domain.MapItem -class ApolloMapService @Inject constructor( +class MapServiceImpl @Inject constructor( private val apolloClient: ApolloClient, private val mapper: ApolloMapItemMapper ) : MapService { override suspend fun fetchMapItems(): List { Log.d(TAG, "Executing MapMarkers Apollo query") - val response = apolloClient.query(MapMarkersQuery()).execute() + val response = apolloClient + .query(MapMarkersQuery(isOnline = false)) + .execute() response.errors?.firstOrNull()?.let { gqlError -> Log.e(TAG, "MapMarkers Apollo query failed: ${gqlError.message}") diff --git a/sdk/src/main/kotlin/org/db3/airmq/sdk/network/ApolloLoggingInterceptor.kt b/sdk/src/main/kotlin/org/db3/airmq/sdk/network/ApolloLoggingInterceptor.kt new file mode 100644 index 0000000..e10e1a6 --- /dev/null +++ b/sdk/src/main/kotlin/org/db3/airmq/sdk/network/ApolloLoggingInterceptor.kt @@ -0,0 +1,39 @@ +package org.db3.airmq.sdk.network + +import android.util.Log +import com.apollographql.apollo.api.ApolloRequest +import com.apollographql.apollo.api.ApolloResponse +import com.apollographql.apollo.api.Operation +import com.apollographql.apollo.interceptor.ApolloInterceptor +import com.apollographql.apollo.interceptor.ApolloInterceptorChain +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.onEach + +class ApolloLoggingInterceptor : ApolloInterceptor { + override fun intercept( + request: ApolloRequest, + chain: ApolloInterceptorChain + ): Flow> { + val operationName = request.operation.name() + val requestData = request.operation.toString() + Log.d(TAG, "Apollo request -> $operationName, data=$requestData") + return chain.proceed(request).onEach { response -> + val errorsCount = response.errors?.size ?: 0 + if (response.exception != null) { + Log.e( + TAG, + "Apollo response <- $operationName failed: ${response.exception?.message}" + ) + } else { + Log.d( + TAG, + "Apollo response <- $operationName success, errors=$errorsCount, data=${response.data}" + ) + } + } + } + + private companion object { + private const val TAG = "ApolloNetwork" + } +}