
Using GraphQL with REST APIs - greencurry43
https://dev.to/smizell/using-graphql-with-rest-apis-2c4k
======
ezekg
Thanks, I hate it. :)

Why use arrays to represent singular values? Also, singular names for
potentially plural results is bad form, however you want to sugar coat it.
This might be cool for an API provider, but it looks like a nightmare to deal
on the API consumer side of things. I like the basic GraphQL results better
(still not sold on GraphQL as a whole, but alas). This offloads needless
complexity onto the consumer.

~~~
greencurry43
Author here. Sounds like I won you over :)

Thanks for the feedback here. I modified the post a bit to not show the arrays
because the library doesn't return arrays but rather aync generators. The
power of this is that you have a single interface for interacting with all
data no matter if there are zero or many results.

This is library is a proof of concept. In a perfect world, there would be a
nice wrapper around this query result for interacting with the data.

    
    
      queryResult.get('order').first()
    

This would provide a single order by calling the first yield for the
generator. No need to worry about the underlying result.

With all of this said, it doesn't have to be this way. I'm exploring ideas
here. The important concept is that GraphQL can be used to express the
expectations of the client and a library like Graphable JSON can go find the
needed data in the API. This gives the expressiveness of GraphQL with the
benefits of REST. The sky is the limit. Thanks again for the feedback!

