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
This commit is contained in:
2026-02-28 22:44:27 +01:00
parent 5cfd32639b
commit 81627d6b7c
4 changed files with 49 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
query MapMarkers { query MapMarkers($isOnline: Boolean!) {
getMarkers { getMarkers(filter: { isOnline: $isOnline }) {
_id _id
name name
latitude latitude

View File

@@ -7,8 +7,9 @@ import dagger.Provides
import dagger.hilt.InstallIn import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton 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.map.MapService
import org.db3.airmq.sdk.network.ApolloLoggingInterceptor
@Module @Module
@InstallIn(SingletonComponent::class) @InstallIn(SingletonComponent::class)
@@ -20,6 +21,7 @@ object SDKModule {
fun provideApolloClient(): ApolloClient { fun provideApolloClient(): ApolloClient {
return ApolloClient.Builder() return ApolloClient.Builder()
.serverUrl(API_URL) .serverUrl(API_URL)
.addInterceptor(ApolloLoggingInterceptor())
.build() .build()
} }
} }
@@ -29,5 +31,5 @@ object SDKModule {
abstract class SDKBindModule { abstract class SDKBindModule {
@Binds @Binds
@Singleton @Singleton
abstract fun bindMapService(impl: ApolloMapService): MapService abstract fun bindMapService(impl: MapServiceImpl): MapService
} }

View File

@@ -6,13 +6,15 @@ import javax.inject.Inject
import org.db3.airmq.sdk.MapMarkersQuery import org.db3.airmq.sdk.MapMarkersQuery
import org.db3.airmq.sdk.map.domain.MapItem import org.db3.airmq.sdk.map.domain.MapItem
class ApolloMapService @Inject constructor( class MapServiceImpl @Inject constructor(
private val apolloClient: ApolloClient, private val apolloClient: ApolloClient,
private val mapper: ApolloMapItemMapper private val mapper: ApolloMapItemMapper
) : MapService { ) : MapService {
override suspend fun fetchMapItems(): List<MapItem> { override suspend fun fetchMapItems(): List<MapItem> {
Log.d(TAG, "Executing MapMarkers Apollo query") 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 -> response.errors?.firstOrNull()?.let { gqlError ->
Log.e(TAG, "MapMarkers Apollo query failed: ${gqlError.message}") Log.e(TAG, "MapMarkers Apollo query failed: ${gqlError.message}")

View File

@@ -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 <D : Operation.Data> intercept(
request: ApolloRequest<D>,
chain: ApolloInterceptorChain
): Flow<ApolloResponse<D>> {
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"
}
}