Skip to content

Commit

Permalink
Fetch speakers from the network
Browse files Browse the repository at this point in the history
  • Loading branch information
BoD committed Apr 4, 2024
1 parent 18a1780 commit e9b3fc9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
3 changes: 2 additions & 1 deletion shared/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ apollo {

introspection {
schemaFile.set(file("src/commonMain/graphql/schema.graphqls"))
endpointUrl.set("https://androidmakers-2023.ew.r.appspot.com/graphql")
endpointUrl.set("https://confetti-app.dev/graphql")
headers.set(mapOf("conference" to "androidmakers2024"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,28 @@ import fr.androidmakers.domain.repo.SpeakersRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

class SpeakersGraphQLRepository(private val apolloClient: ApolloClient): SpeakersRepository {
class SpeakersGraphQLRepository(private val apolloClient: ApolloClient) : SpeakersRepository {

override fun getSpeakers(): Flow<Result<List<Speaker>>> {
return apolloClient.query(GetSpeakersQuery())
.watch()
.ignoreCacheMisses()
.map {
it.dataAssertNoErrors.speakers.map { it.speakerDetails.toSpeaker() }
}.toResultFlow()
.fetchPolicy(FetchPolicy.CacheAndNetwork)
.watch()
.ignoreCacheMisses()
.map {
it.dataAssertNoErrors.speakers.map { it.speakerDetails.toSpeaker() }
}.toResultFlow()
}

override fun getSpeaker(id: String): Flow<Result<Speaker>> {
return apolloClient.query(GetSpeakersQuery())
.fetchPolicy(FetchPolicy.CacheAndNetwork)
.watch()
.ignoreCacheMisses()
.map {
it.dataAssertNoErrors.speakers.map { it.speakerDetails }.singleOrNull { it.id == id }?.toSpeaker()
?: error("no speaker")
}
.toResultFlow()
.fetchPolicy(FetchPolicy.CacheAndNetwork)
.watch()
.ignoreCacheMisses()
.map {
it.dataAssertNoErrors.speakers.map { it.speakerDetails }.singleOrNull { it.id == id }
?.toSpeaker()
?: error("no speaker")
}
.toResultFlow()
}
}

0 comments on commit e9b3fc9

Please sign in to comment.