1

Why should I use graphql if I setup a react frontend and mongo db backend? And Why should i put graphql server between mongo db and react?

povakizulu
  • 63
  • 7
  • There is no "should". GraphQL is a choice if it suits your needs. There is a plenty of good information [here](https://graphql.github.io/). – devserkan Dec 10 '18 at 13:43

1 Answers1

0

Since you didn't mention what is your alternative API style I will just assume it's REST. GraphQL gives you many features a plain old REST api won't have out of the box. This is probably the best answer listing advantages and disadvantages of both. You already have validation(via mongoose schemas), but using GQL you can get:

  • excellent documentation for your API generated for you
  • avoid underfetching/overfetching on frontend
  • ability to batch FE requests easily
  • you can tap into a very rich ecosystem of GraphQL tooling which only gets better as time passes
  • easier testing-you can just execute your graphql queries on backend even without sending them over the network saving a little bit of performance overhead

I believe you should use GraphQL for any non trivial API, because it adds ton of typesafety and the price you pay as a developer is very low.

Capaj
  • 4,024
  • 2
  • 43
  • 56