namc-utah / NAMCr

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

Object Arguments? (Re: samples -> QueryDistance) #11

Open MattReimer opened 3 years ago

MattReimer commented 3 years ago

I don't think this is a bug. I just don't know how to do it.

from the API docs for samples:

NAMC API:
samples ------------------------------

    Description:    List of all samples in the system, including high level information about the associated box and customer.:

    Input Parameters:
        sampleIds:
            data type:  Int
            is numeric: TRUE
            is array:   TRUE
            is required:    FALSE
            is for paging:  FALSE

        boxIds:
            data type:  Int
            is numeric: TRUE
            is array:   TRUE
            is required:    FALSE
            is for paging:  FALSE

        projectIds:
            data type:  Int
            is numeric: TRUE
            is array:   TRUE
            is required:    FALSE
            is for paging:  FALSE

        entityIds:
            data type:  Int
            is numeric: TRUE
            is array:   TRUE
            is required:    FALSE
            is for paging:  FALSE

        siteIds:
            data type:  Int
            is numeric: TRUE
            is array:   TRUE
            is required:    FALSE
            is for paging:  FALSE

        polygon:
            data type:  String
            is numeric: FALSE
            is array:   FALSE
            is required:    FALSE
            is for paging:  FALSE

        pointDistance:
            data type:  QueryDistance
            is numeric: FALSE
            is array:   FALSE
            is required:    FALSE
            is for paging:  FALSE

QueryDistance

QueryDistance is an object like

{
"latitude": 40,
"longitude": -108,
"distance": 50000
}

So I would expect this to go into the query like:

data = query("samples", limit: 10, offset: 0, pointDistance: {"latitude": 40, "longitude": -108, "distance": 50000})

But that doesn't work and I'm not an R expert. thoughts @David-Fowler ?

David-Fowler commented 3 years ago

I am not in front of my computer at the moment but the syntax should be: data = query("samples", limit=10, offset= 0, pointDistance= list(latitude=40, longitude= -108, distance= 50000))

I will test this when I get back.

MattReimer commented 3 years ago

Yeah, I thought it would be something like that too. I just found the list syntax but I get:

data = query("samples", limit=10, offset= 0, pointDistance= list(latitude=40, longitude= -108, distance= 50000))
Retrieving data: Error: Query Execution Error:
    Expected type QueryDistance, found ["40", "-108", "50000"].

Must be a typing issue. No idea how that works in R. Sorry I can't be more useful

David-Fowler commented 3 years ago

I will also add the logic required to have objects as arguments to endpoints which will push that to the docs.

David-Fowler commented 3 years ago

Ok so QueryDistance is a defined graphql type. I knew that would come back to bite me. I limited the graphql parameter and field types to a set of basic types of instead of introspecting the additional type layer. I left it at the name and did not introspect the next level knowing if we were to have any complex type requirements it would need adjusting. I will add that to the introspection and everything will fall into place once that is complete.

MattReimer commented 3 years ago

Thanks @David-Fowler. Yeah QueryDistance is a type we define . We should have warned you that non-simple input types were coming. I hope it doesn't introduce too much of a headache.

That said, having GraphQL InputTypes supported was always going to be needed sooner or later, especially when mutations start gaining complexity so better now than later.

Let me know if I can provide anything more to help.