-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6329209
commit f9bbb43
Showing
9 changed files
with
54 additions
and
105 deletions.
There are no files selected for viewing
51 changes: 0 additions & 51 deletions
51
...data/src/androidMain/kotlin/fr/androidmakers/store/graphql/ApolloClientBuilder.android.kt
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
shared/data/src/commonMain/kotlin/fr/androidmakers/store/graphql/ApolloClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package fr.androidmakers.store.graphql | ||
|
||
import com.apollographql.apollo3.ApolloClient | ||
import com.apollographql.apollo3.api.http.HttpRequest | ||
import com.apollographql.apollo3.api.http.HttpResponse | ||
import com.apollographql.apollo3.cache.normalized.api.MemoryCacheFactory | ||
import com.apollographql.apollo3.cache.normalized.normalizedCache | ||
import com.apollographql.apollo3.cache.normalized.sql.SqlNormalizedCacheFactory | ||
import com.apollographql.apollo3.network.http.HttpInterceptor | ||
import com.apollographql.apollo3.network.http.HttpInterceptorChain | ||
import fr.androidmakers.domain.repo.UserRepository | ||
|
||
fun ApolloClient( | ||
sqlNormalizedCacheFactory: SqlNormalizedCacheFactory, | ||
userRepository: UserRepository, | ||
): ApolloClient { | ||
val memoryCacheFactory = MemoryCacheFactory(20_000_000).chain(sqlNormalizedCacheFactory) | ||
return ApolloClient.Builder() | ||
.serverUrl("https://androidmakers.fr/graphql") | ||
.addHttpInterceptor(object : HttpInterceptor { | ||
override suspend fun intercept(request: HttpRequest, chain: HttpInterceptorChain): HttpResponse { | ||
return chain.proceed( | ||
request.newBuilder() | ||
.apply { | ||
/** | ||
* | ||
*/ | ||
val token = userRepository.getIdToken() | ||
if (token != null) { | ||
addHeader("Authorization", "Bearer $token") | ||
} | ||
} | ||
.build() | ||
) | ||
} | ||
}) | ||
.normalizedCache(memoryCacheFactory) | ||
.build() | ||
} |
7 changes: 0 additions & 7 deletions
7
shared/data/src/commonMain/kotlin/fr/androidmakers/store/graphql/ApolloClientBuilder.kt
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
shared/data/src/iosMain/kotlin/fr/androidmakers/store/graphql/ApolloClientBuilder.ios.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters