Why, When and How of GraphQL – GraphQL FAQs
Since GraphQL is fast growing, the hype around is also increasing day by day. With popularity, the doubts and questions about it also grow. Here I present answers to most commonly asked questions in form of GraphQL Frequently Asked Questions (FAQs):
How to install GraphQL?
GraphQL is a node dependency. Hence you need to first make sure that node is installed in your system. GraphQL Official documentation suggests having Node v6+.
Chances are you already have Node.js installed. Check:
If the above command throws an error or you have lower Node version, download it from Node Official Website.
Next, create a new directory for GrahphQL Projects and create a
package.json file & follow the relevant steps.
You can now install GraphQL using npm:
npm install graphql --save
When will GraphQL be released?
Facebook is using GraphQL since 2012 and was open sourced in 2015 and was production ready by 2016. And the latest released version is v0.13.2 (as of writing this article). Also, the whole GraphQL release timeline is available on Github.
Is GraphQL free? OR Is GraphQL Open Source?
Yes. As mentioned on the official website,
“Facebook’s mobile apps have been powered by GraphQL since 2012. A GraphQL spec was open sourced in 2015 and is now available in many environments and used by teams of all sizes.”
When to use GraphQL?
Here are some of the instances when GraphQL can be useful:
- When you don’t have data spread among multiple domains, meaning, you must have a centralized database to take the full advantage of GraphQL features so as to prevent over fetching and under fetching and thus fetch required data from multiple resources at once.
- GraphQL can boost performance invariably for Mobile Application as it reduced payload size.
- For communication between data centers for service-to-service request-response cycle.
- When you do not look forward to caching data. Though this is possible in GraphQL but it may involve some efforts.
Is GraphQL Production Ready?
As of 2018, yes, GraphQL production ready. The official announcement regarding this was made back in 2016.
You can also go through the various case studies of products using GraphQL in production.
Is GraphQL Worth it?
Since GraphQL has substantial improvements over REST, it is undoubtedly considered to be widely used in the future. With GraphQL, future APIs would look like:
- Clean API on both Backend and Frontend
- Optimized, In-build documentations with API
- Quicker development and implementation curve
Is GraphQL a database?
My counter question to this is – Is REST a database? NO, right? GraphQL is NOT a database; it is a query language. Here’s how GraphQL official website describes it:
Why GraphQL over REST?
This has been the hot favorite topic over coffee desks and water coolers in the development workspace. GraphQL tends to solve some of the issues that REST causes.
You can read a post where I’ve pointed out the difference between GraphQL and REST in detail.
Will GraphQL replace REST?
GraphQL has immense potential and may be widely used in the future. But this won’t replace REST altogether as implementing GraphQL for minimal API requirements can be a huge overhead.
For simple API with limited endpoints, REST will be the going thing even in future as it is easy to implement and in blood of backend developers.
Is GraphQL better than REST?
GraphQL is an intelligent Query Language. It has various advantages over REST. But the critical thing to know is when to use GraphQL and when to use REST. Check out the difference between both and decide for yourself.
Is GraphQL faster than REST?
As GraphQL can fetch related data in a single request, it is faster. Also, GraphQL lets client fetch selective data without over-fetching, this particularly fastens the communication between client and server.
How GraphQL will change Backend Development?
GraphQL doesn’t really change the way backend or frontend is developed; it merely serves as a tool to query backend data. But this overall substance is a massive breakthrough as for years REST has been considered and used as the communication medium between two servers or client & server.
The advantages of GraphQL are of course compelling and eliminate the need to write complex code to fetch data from multiple resources.
Is GraphQL worth learning?
Though GraphQL is gaining immense popularity, this question is subjective. I would definitely stress on giving it a try to see whether it is particularly useful for you or not and discover the use cases where it can be fruitful.
But if you are already using REST multiple endpoints for specific data or you are worried about client data plan and data communication speed, GraphQL can surely be a huge breakthrough.
Does GraphQL replace Redux?
Though GraphQL is a query language and Redux is a state management library, popularly used with React.js, they are compared all the time.
Most of the developers who have shifted from REST to GraphQL API feel GraphQL reduce the need of Redux as GraphQL allows the client to fetch the desired data from the endpoints and React application no more needs to maintain complex state all by itself.
This may hold true, but that doesn’t depreciate Redux altogether. For React applications with the significant backend, Redux would still be prominent to save the user and application state.
Is graphql a Graph Database?
This is one of the most debated and confused questions in the industry. Everyone has a different opinion on it. Probably because the name GraphQL itself has a graph. But most of the people miss QL in GraphQL which is short for Query Language.
Hence, GraphQL isn’t a database at all. But it can be used to communicate with Graph Database like neo4j
Is GraphQL JSON?
GraphQL isn’t precisely JSON. Yet, looking at the overall syntax, we can assume it is inspired from JSON. Also, it isn’t JSON because comprehending schema, joins, nesting, etc. in JSON data object would actually degrade the charm of using JSON altogether.
How GraphQL Subscriptions work?
GraphQL has three integral part namely – query, mutation, and subscription. Subscriptions attract developers as they enable real-time data updates on server and client side. They use sockets and are highly useful. You can setup Subscriptions in GraphQL Apollo very easily.
Why GraphQL is bad?
- For complex projects, the schema can get really long and complicated to understand for newbies.
- GraphQL Logging System is hard to figure out. This wasn’t even a problem in REST. GraphQL core system doesn’t have a way to find out the actual problem for instance with 500 internal error. A simple workaround through this is to have a named query, mutation and subscription.
- Uploading File or Image with the GraphQL mutation is not as straight forward as it was with REST.
- Server-side Caching or reverse proxy implementation can be time-consuming.
Questions & Comments:
Thanks for reading. In this post we discussed GraphQL in and out. Though I tried to cover questions revolving around GraphQL, if you still have any doubts or questions about it, drop them in the comment section below..