Skip to content

Commit

Permalink
Merge pull request #1916 from HedvigInsurance/feature/octopus_chat_me…
Browse files Browse the repository at this point in the history
…rge_develop

Octopus chat
  • Loading branch information
StylianosGakis authored Dec 8, 2023
2 parents ff73033 + 993ec1c commit 08e37d8
Show file tree
Hide file tree
Showing 207 changed files with 3,474 additions and 4,816 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ ktlint_standard_multiline-expression-wrapping=disabled
# https://pinterest.github.io/ktlint/1.0.1/rules/standard/#string-template-indent
ktlint_standard_string-template-indent=disabled

[*.xml]
indent_size=2

[*.graphql]
indent_size=2
end_of_line=lf
Expand Down
1 change: 0 additions & 1 deletion app/apollo/apollo-auth-listeners/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ dependencies {
implementation(libs.apollo.normalizedCache)
implementation(libs.apollo.runtime)
implementation(libs.koin.core)
implementation(projects.apolloGiraffePublic)
implementation(projects.apolloOctopusPublic)
implementation(projects.authEventCore)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,14 @@ package com.hedvig.android.apollo.auth.listeners.di

import com.apollographql.apollo3.ApolloClient
import com.hedvig.android.apollo.auth.listeners.normalizedcache.ApolloNormalizedCacheAuthEventListener
import com.hedvig.android.apollo.auth.listeners.subscription.ApolloSubscriptionReconnectingAuthEventListener
import com.hedvig.android.apollo.giraffe.di.giraffeClient
import com.hedvig.android.apollo.octopus.di.octopusClient
import com.hedvig.android.auth.event.AuthEventListener
import org.koin.dsl.bind
import org.koin.dsl.module

val apolloAuthListenersModule = module {
single<ApolloNormalizedCacheAuthEventListener> {
ApolloNormalizedCacheAuthEventListener(
get<ApolloClient>(giraffeClient),
get<ApolloClient>(octopusClient),
)
} bind AuthEventListener::class
single<ApolloSubscriptionReconnectingAuthEventListener> {
ApolloSubscriptionReconnectingAuthEventListener(
get<ApolloClient>(giraffeClient),
get<ApolloClient>(),
)
} bind AuthEventListener::class
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import com.apollographql.apollo3.cache.normalized.apolloStore
import com.hedvig.android.auth.event.AuthEventListener

internal class ApolloNormalizedCacheAuthEventListener(
private val giraffeApolloClient: ApolloClient,
private val octopusApolloClient: ApolloClient,
private val apolloClient: ApolloClient,
) : AuthEventListener {
override suspend fun loggedIn(accessToken: String) {
giraffeApolloClient.apolloStore.clearAll()
octopusApolloClient.apolloStore.clearAll()
apolloClient.apolloStore.clearAll()
}

override suspend fun loggedOut() {
giraffeApolloClient.apolloStore.clearAll()
octopusApolloClient.apolloStore.clearAll()
apolloClient.apolloStore.clearAll()
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import arrow.core.Either
import com.apollographql.apollo3.ApolloCall
import com.apollographql.apollo3.api.ApolloResponse
import com.apollographql.apollo3.api.Operation
import com.apollographql.apollo3.api.Query
import com.apollographql.apollo3.cache.normalized.watch
import com.apollographql.apollo3.exception.ApolloException
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -40,27 +38,6 @@ fun <D : Operation.Data, ErrorType> ApolloCall<D>.safeFlow(
.map { it.toEither(ifEmpty) }
}

/**
* First tries to fetch the data from the network, and from then on looks into changes of the cache.
* If the first query from the internet fails, an exception is thrown internally and ends this flow by sending a last
* value of QueryResult.Error for the consumers to react appropriately.
* To then retry watching the query, this needs to be started and collected again. This can be done using
* [com.hedvig.android.core.common.RetryChannel] for example.
* If any subsequent cache reads fail simply nothing is emitted and the flow continues reading the cache. That is
* because at that point we do have data to work with so there's no need for the error to propagate.
*/
fun <D : Query.Data> ApolloCall<D>.safeWatch(): Flow<OperationResult<D>> {
return watch(fetchThrows = true)
.map(ApolloResponse<D>::toOperationResult)
.catch { exception ->
if (exception is ApolloException) {
emit(OperationResult.Error.NetworkError(exception))
} else {
emit(OperationResult.Error.GeneralError(exception))
}
}
}

private fun <D : Operation.Data> ApolloResponse<D>.toOperationResult(): OperationResult<D> {
val data = data
return when {
Expand Down

This file was deleted.

66 changes: 0 additions & 66 deletions app/apollo/apollo-giraffe-public/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 08e37d8

Please sign in to comment.