Aashish K
Aashish K

Reputation: 103

Is it preferred to use GraphQL for querying and REST for mutation operations in the same project?

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

Answers (2)

harshitpthk
harshitpthk

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

Daniel Rearden
Daniel Rearden

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

Related Questions