0

I am expecting to get data from multiple sources via single subscription if the data is not available in the source yield empty response, for certain number of retries


@strawberry.type
class DataFromSources:
    source_1 : JSON
    source_2 : JSON

@strawberry.type
class Subscription:
    @strawberry.subscription
    async def data_from_sources(self, target: int = 10) -> AsyncGenerator[DataFromSources, None]:
        source_1, source_2 = None, None
        for i in range(target):
            source_1 = await fetch_data_from_source_1()
            source_2 = await fetch_data_from_source_2()
            yield DataFromSources(source_1, source_2)
            if source_1 and source_2:
                break
            await asyncio.sleep(1)

0 Answers0