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

Dataloaders for existing REST APIs as data source #1433

Closed
rshreemr12 opened this issue Jun 29, 2022 · 3 comments
Closed

Dataloaders for existing REST APIs as data source #1433

rshreemr12 opened this issue Jun 29, 2022 · 3 comments
Labels

Comments

@rshreemr12
Copy link

rshreemr12 commented Jun 29, 2022

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

@erikwrede
Copy link
Member

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

@ramya-lbg
Copy link

@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.

image

image

@erikwrede
Copy link
Member

erikwrede commented Jul 20, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants