is it possible to have a single subscription waiting for data from multiple sources using graphql strawberry?

is it possible to have a single subscription waiting for data from multiple sources using graphql strawberry?


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)

Share

New contributor

Rakesh Reddy Sama is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


Load 2 more related questions


Show fewer related questions

0

Reset to default



Leave a Reply

Your email address will not be published. Required fields are marked *