graphene
graphene copied to clipboard
Dataloaders for existing REST APIs as data source
Is there a feature already existing for dataLoaders to load graphene RESTFUL APIs as datasource
current Behaviour https://docs.graphene-python.org/en/latest/execution/dataloader/#using-with-graphene Existing docs provide info to load the data from database and load dataloaders by filtering id.
Please suggest if there a way to use dataloaders for existing REST APIs as data source. Couldn't find it anywhere in docs
https://stackoverflow.com/questions/48541204/graphene-relation-using-restfull-api-as-data-source https://stackoverflow.com/questions/72544729/graphql-wrapper-for-rest-apis-with-django?noredirect=1&lq=1
If you're referring to a mapper from existing APIs to graphene types similar to the sqlalchemy django and mongodb integrations, then no there is nothing like that. Additionally, I'd advise you to use aiodataloader + graphene v3 since the old promise library can be considered legacy. Sadly, the graphene docs are outdated and don't incorporate the new dataloader. You can check out examples here: https://github.com/syrusakbary/aiodataloader
@erikwrede : Thanks for your response. I am looking for an implementation very similar to this. current implementation they have is in Java script.
https://graphql.org/blog/rest-api-graphql-wrapper/
I tried to replicate it in Django graphene(Python implementation) and was successful in making requests in schema query and mapping it to graphene.ObjectType like this. https://stackoverflow.com/questions/48541204/graphene-relation-using-restfull-api-as-data-source
Like in the graphql Javascript demo would like to add data loaders.


This works very similar to the JS tutorial. As mentioned above, you will need to use aiodataloader. Now you need to create your graphene object types with the correctly typed fields. Then create data loaders for all the object types. These should return an instance of the object type based on the object id. Inside of the dataloaders you can use httpx, requests or other HTTP clients to make your rest calls. Let me know if that works for you.