Settings

Theme

Using GraphQL with REST APIs

dev.to

3 points by greencurry43 7 years ago · 2 comments

Reader

ezekg 7 years ago

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.

  • greencurry43OP 7 years ago

    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!

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection