namc-utah / NAMCr

NAMC Database and Analysis R API
MIT License
0 stars 0 forks source link

SetSiteCatchment #21

Open philipbaileynar opened 2 years ago

philipbaileynar commented 2 years ago

Attempting to set a site catchment with a simple GeoJSON rectangle:

NAMCr::query(api_endpoint="setSiteCatchment", args=list(siteId = 2000, catchment= json <- '{"type": "Polygon","coordinates": [[[-122.68,42.77],[-116.53,42.77],[-116.53,44.30],[-122.68,44.30],[-122.68,42.77]]]}'))
Screen Shot 2022-01-31 at 1 46 37 PM Screen Shot 2022-01-31 at 1 46 11 PM
philipbaileynar commented 2 years ago

Using the debugger I was able to pause NAMCr right before it attempts to call the API. This is the GraphQL string that it's attempting to send:

"query rQuery{\nsetSiteCatchment(siteId:2000 catchment:[\"{\"type\": \"Polygon\",\"coordinates\": [[[-122.68,42.77],[-116.53,42.77],[-116.53,44.30],[-122.68,44.30],[-122.68,42.77]]]}\"] ) {\n                    \n                }\n            }"

There are several things wrong with this string:

  1. The setSiteCatchment endpoint is a mutation not a query.
  2. There is a missing comma between the two arguments
  3. The string escaping is wrong (see below)
  4. The spare curly braces at the end of the query are not needed.

I manipulated the string from above until it worked. What follows successfully called the API:

 tpl_query = "mutation rQuery{\n                
setSiteCatchment(siteId:2000, catchment:\"{\\\"type\\\": \\\"Polygon\\\",\\\"coordinates\\\": [[[-122.68,42.77],[-116.53,42.77],[-116.53,44.30],[-122.68,44.30],[-122.68,42.77]]]}\")\n}"
philipbaileynar commented 2 years ago

The top priority is to get setSiteCatchment working from scripts using the NAMCr::save function. This is a higher priority than getting it working within the CLI.

Since setSiteCatchment is a mutation we intend for this call to be made through the save command, not the `query command.

NAMCr::save(api_endpoint="setSiteCatchment", args=list(siteId = 2000, catchment= json <- '{"type": "Polygon","coordinates": [[[-122.68,42.77],[-116.53,42.77],[-116.53,44.30],[-122.68,44.30],[-122.68,42.77]]]}'))

Other mutations that can be used for regression testing are:

NAMCr::save(api_endpoint="setSitePredictorValue", args=list(siteId = 2000, predictorId=1, value="test")