Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch speaker list from the network #239

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion shared/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ 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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍


// This header is not needed to fetch the schema but it's read by the Apollo IDE plugin which will inject it when executing queries
headers.set(mapOf("conference" to "androidmakers2024"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required for introspection? I would hope the schema does not depend on the conference

Copy link
Collaborator Author

@BoD BoD Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No but the IJ plugin also looks at these headers and inject them when running queries from the UI :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Well this is a bit surprising. Might adding a comment?

}
}
}
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()
}
}
Loading