Reputation: 103
I am working on a Ecommerce Site which needs API's for its mobile application. Seeing the implementation issues at first of GraphQL made me think of integrating GraphQL for querying data and REST for the mutation operations (store, update, delete).
Is it ok to do these things or should I just stick with any one of them for complete operations?
Upvotes: 0
Views: 350
Reputation: 4136
I would recommend to stick with a single approach because of the following reasons
1) predictive changes to cached data after the operation otherwise you would have to write lot of duct tape code to ensure that the REST
based updates mutates the cached data on the client.
2) Single pattern for code maintenance and less overhead while reading code.
3) To have a schema
at a single place otherwise you might be duplicating code.
Upvotes: 0
Reputation: 84657
There's plenty of individual cases where it's more appropriate or even necessary to have separate endpoints. To name a few: authentication, file uploads, third-party webhooks, or any requests that should return something other than JSON.
Saying that all operations with side-effects should be done through separate endpoints seems like overkill. You'll not only lose the typical benefits associated with GraphQL (declarative data fetching, predictable responses, etc.) but you'll also be making things harder for front end developers, particularly if using Apollo. That's because cached query responses can be automatically updated based on the data returned in a mutation -- if you don't use GraphQL to mutate that data, though, you'll have to manually update the cache yourself.
Upvotes: 2