3 ms·
> 1. Clean RESTful URLs like the one you have doesn't make it easy to fetch { article, article.author.name, [user.comments.commenter] } in a _single call_. Grap
by curryst 11y ago
> 1. Clean RESTful URLs like the one you have doesn't make it easy to fetch { article, article.author.name, [user.comments.commenter] } in a _single call_. GraphQL let's you define the Shape you want.
/api/article/12/full to return the article with author and comments, and /api/article/12 for just the article text would work and aren't all that dirty. Could also be arguments to the REST call, but that makes it a little more ambiguous since you could have several different code paths for the same endpoint.
> 2. Updates spanning multiple resources aren't a good fit for a Resource Oriented pattern like REST. a) How do you delete multiple comments (Ids 1, 34, 44) in one shot? http://stackoverflow.com/questions/7511195/rest-architecture.. http://stackoverflow.com/questions/7511195/rest-architecture....
The article you linked has a pretty graceful answer, I'm not sure why you dislike it. REST is generally a hierarchical datasource. Implement an endpoint above users in a hierarchy, or give it it's own tree. I.e. /api/comment/multi/delete, or /api/comments/delete (vs /api/comment). It's really not all that bad to do, and in a lot of cases you could use the same code to actually do the action.
> 3. How do I edit /users/200 and /users/201 in one single call? Imagine a Grid with a Save Button. Also, this could be a transaction as well.
This is pretty much the same problem, you just have to handle more data. Again, /users/multi/update and POST your data.
The biggest place REST falls short of other HTTP-based API architectures is when you have a lot of different fields that need to be relatively randomly accessed. Sometimes you want the article with the authors name and date but no comments. Sometimes you just want the article name and author's name. Sometimes you just want the text. etc, etc. REST fails when you try to use it as SQL over HTTP, which looks to be what GraphQL is trying to do. And it's worth noting that it doesn't really "fail" per say, you just end up with a bloated mess of endpoints if you need to have 20 different variations on the data you need for an endpoint.