gardenbuilder-app / gardenbuilder-backend-python

Django-based REST API
6 stars 11 forks source link

Write query that pulls fruit/vegetable info from Trefle API #7

Open capndave opened 3 years ago

capndave commented 3 years ago

In Plants app, write handler to pull data from Trefle API. Ultimately we want a user of this (gardenbuilder-backend) to write a GraphQL query, passing in a fruit or vegetable name ("Tomato", for example). This handler/function would then query all of the tomato varieties from the Treffle API, return them, and then return all the tomato varieties to the user/graphql interface.

rexdivakar commented 3 years ago

Assign it to me @capndave

capndave commented 3 years ago

Will do! If you would, please just set up your own account for the Trefle API, and import the connection settings into Django with an environment variable from a .env file in the config directory. I can swap out my Trefle credentials later. Please let me know if you have any difficulties getting this up and running!

capndave commented 3 years ago

@rexdivakar let me know if you're still working on this, if not I'll unassign you

rexdivakar commented 3 years ago

Yes I'm working on it will update it soon @capndave

rexdivakar commented 3 years ago

hey @capndave Currently I'mpulling all the varieties of tomatoes, now i would like to know few details,

  1. What details should i pull out ?
  2. How do u want me to return the data (json or basic text) ?

image

capndave commented 3 years ago

Awesome! The parameters I'd like to return to the client are { id, common_name, slug, scientific_name, image_url } for all tomato varieties. Let me know if there are pagination issues, like if you're unable to get all varieties with one api call.

rexdivakar commented 3 years ago

no prob, i can get it done but do u want the output in the form of list or dictionary ?

capndave commented 3 years ago

Dictionary please. Basically you'll need to make a graphql query that accepts plantName (in the query itself) / plant_name (in python) and returns a bunch of items of class variety that include the parameters that you mention. The Trefle API call is just the intermediate step to actually fetch the data.

rexdivakar commented 3 years ago

I will raise the PR soon

rexdivakar commented 3 years ago

What do u think about dumping the data into a json file !! So we can even use it often with less network load ?

capndave commented 3 years ago

GREAT idea! I guess we could just check the .json on each request from the client, and call Trefle if a top-level variety key isn't in the .json? I wonder if Redis or Memcache or something would be useful here, or overkill.

rexdivakar commented 3 years ago

If u have a larger work load we can go with Redis or Memcache but with smaller use case we can use .json (feed files) what do u say ?

capndave commented 3 years ago

Sounds great!