Using React
with GraphQL clients
like Apollo Client
is a good idea? The same results i can achieve with react
and new Context API
.
Basically i can consume GraphQL API
s using axios
or any other libraries like this. And for state management i can use react's new Context API
s which is really simple.
axios.get('localhost://4000?qraphql').then((res)=>{
//do something with the response.
})
Is there still any Advantages to go with Apollo Client
. Why would I really go for Apollo client
when i can achieve the same without it. It will help me to reduce my bundle
size.
Apollo client provides a ton of features above and beyond simply fetching data from the server. What follows is a non-exhaustive list:
apollo-link-error
loadMore
apollo-link-ws
apollo-link-state
@defer
directiveSee the extensive docs here for more details.
There are common patterns that result in having to write (and test) a bunch of boilerplate code, for example maintaining loading state so that your UI knows when a request is complete. Using Apollo, or any other similar client, eliminates the need to write all that boilerplate and provides a clean, well-tested API for you to work with. If you're working on a team, there's also something to be said for using a well-documented library that some of your team may already be familiar with, rather than having to learn some new API that was created just for a particular project.