Nick
07/08/2022, 8:53 PMwatch
for cache changes from both queries, but I end up with a Flow<List<Flow<MyObject>>>
. I'd much rather have a Flow<List<MyObject>>
. Code in š§µapollo.query(LabReportsByPatientQuery(recordStoreId))
.fetchPolicy(fetchPolicy)
.watch()
.mapNotNull { it: ApolloResponse<LabReportsByPatientQuery.Data> ->
it.dataAssertNoErrors.patient.diagnosticReportSubject.edgesFilterNotNull()
?.map { edge ->
edge.node
}
}
.map { nodes: List<LabReportsByPatientQuery.Node> ->
nodes
.mapNotNull { node ->
try {
apollo.query(LabResultByIdQuery("DiagnosticReport/${node.labResultFragment.id}"))
.fetchPolicy(fetchPolicy)
.watch()
.map { ... convert to lab result }
} catch (ex: Exception) {
// If there's an error translating the data to a lab result, return null so its skipped
null
}
}
}
// This flow is a Flow<List<Flow<ApolloResponse<LabResultByIdQuery.Data>>>>
wasyl
07/08/2022, 10:12 PMflatMap
Nick
07/08/2022, 10:13 PMlist
, flatMap
won't work in this situation.bod
07/09/2022, 7:49 AMsuspend fun <T> Flow<List<Flow<T>>>.donkey(): Flow<T> = flow {
collect {
for (subFlow: Flow<T> in it) {
emitAll(subFlow)
}
}
}
ephemient
07/09/2022, 7:51 AM.flatMap { nodes: List<LabReportsByPatientQuery.Node> ->
combine(
nodes.mapNotNull { node ->
try {
apollo.query(LabResultByIdQuery("DiagnosticReport/${node.labResultFragment.id}"))
.fetchPolicy(fetchPolicy)
.watch()
.map { ... convert to lab result }
} catch (ex: Exception) {
// If there's an error translating the data to a lab result, return null so its skipped
null
}
}
) { it.toList() }
}
this should result in a Flow<List<ApolloResponse<LabResultByIdQuery.Data>>>
where each list is nodes.size
in size and contains one element from each inner flowNick
07/11/2022, 4:33 PM