GraphQL Basics: Pros and Cons

The views expressed in this post are the writer's and do not necessarily reflect the views of Aloa or AloaLabs, LLC.

GraphQL is a name you may hear from time to time. It isn’t a front-end language, nor a back-end language; so what is it?

GraphQL (Graph Query Language) as you may have guessed from the hint in parentheses, is a Query Language, specifically for APIs. A query language is a method of communication for retrieval of information from a database. In other words, GraphQL allows you to transfer information from a server to a frontend. What makes GraphQL a powerful tool is that it allows a frontend client to quickly and easily fetch data, especially in cases where you need to minimize bandwidth and latency.

Summary

GraphQL logo

GraphQL is a complement to the popular REST API. Where REST APIs requires users to follow a strict fixed data structure approach in retrieving information, GraphQL gives the user more flexibility and freedom. GraphQL allows the developer to request data from the server and receive just that; no more, no less. It can be used in combination with REST to provide both structure and flexibility when you need one or the other.

The user is provided with a pre-defined schema, a definition of the structure of data that can be requested from the server. GraphQL works by querying the defined schema against the backend of the application and populating the received data on the frontend. Rather than accessing the entire set of information to find what you are looking for, GraphQL allows you to only query for the exact documents and fields you want.

Pros of GraphQL

GraphQL is really fast

Compared to REST, GraphQL is much faster since you don't need to query for all of the data. You can choose to query for specific fields that you're looking for, allowing queries to be more efficient. GraphQL allows the developer to fetch data with a single API call rather than following a process of requests.

GraphQL auto-documents as you code

As you make changes to your API, your documentation will evolve with you, saving you valuable time.

Detailed error messages

This allows the developers easier understanding of what errors occur so they can resolve issues quicker.

Cons of GraphQL

GraphQL has a very high learning curve

It is an incredibly powerful piece of technology, so it inherently is tougher to learn.

GraphQL can get overwhelmed

If you make too many requests, GraphQL can get a bit overwhelmed. For example, if you're sending a lot of queries on nested fields, GraphQL may have performance issues.

GraphQL can be overkill

Since GraphQL is so complex and powerful, it can commonly be overkill for smaller applications. If you have a simple/straight-forward app in front of you, it will be easier to work with a REST API.

GraphQL doesn’t inherently allow for file uploads

There are ways you can bypass this, such as using a library or implementing another API, however as you can see, it just adds another step to the equation and forces you to use something besides GraphQL to handle file uploads.

Overall, GraphQL is a crazy strong tool that can be really helpful to use. If you’re working with a system with a large database and complex schema, it will likely be worth the time to learn GraphQL. Still have questions? Give us a shout at resources@aloa.co

Aloa is your trusted software development partner.

Hire your team
Tag:
Innovate freely ✌️
See why 300+ startups & enterprises trust Aloa with their software outsourcing.
Let's chatLet's chat

Ready to learn more? 
Hire software developers today.

Running a business is hard,
Software development shouldn't be ✌️