Yeah but they just seem way more complex with GraphQL. I would prefer doing "mutations" the RESTful way if I don't need that feature of only returning part of the response. But still keep GraphQL for the GET endpoint.
GraphQL can be as complex or simple as you design it to be. The benefit is when you start getting into a situation where you have a very complex data model, say 20+ related tables. In this case, if you want to load and then modify a bunch of interrelated tables all in one network round-trip, a mutation can do that. And the return data can include all the potentially derivative changed data, IDs, etc. in the returned query which nicely keeps the client cache up to date.
Now, if I only had one or three tables or a NoSQL data back end, a REST API might be faster / simpler to implement.
I get using GraphQL for GETs. But what are its advantages over REST for POST/PUT/DELETE? Is it appropriate to use both in one API?
POST / PUT / DELETE actions are handled by mutations in GraphQL
there you can also (if you want) only pick your needed result values like:
"add a message, but only return the created ID" (or anything else you need)
Yeah but they just seem way more complex with GraphQL. I would prefer doing "mutations" the RESTful way if I don't need that feature of only returning part of the response. But still keep GraphQL for the GET endpoint.
I think it does mean that the contracts are no so strict and have a dynamic part. Is it?
GraphQL can be as complex or simple as you design it to be. The benefit is when you start getting into a situation where you have a very complex data model, say 20+ related tables. In this case, if you want to load and then modify a bunch of interrelated tables all in one network round-trip, a mutation can do that. And the return data can include all the potentially derivative changed data, IDs, etc. in the returned query which nicely keeps the client cache up to date.
Now, if I only had one or three tables or a NoSQL data back end, a REST API might be faster / simpler to implement.
This is a really helpful answer, thank you.