What is GraphQL?
During my job search, I have noticed a lot of companies had one big thing in common: the usage of GraphQL. Upon first glance, I assumed it was another database management language, and while it does function predominately in the backend, that was not the case. GraphQL doesn’t have anything to do with databases or SQL (contrary to my belief!).
What is GraphQL?
Created by Facebook in 2012, GraphQL is a query language that works closely with APIs, and can be used as a standalone for backend purposes but also function harmoniously with languages such as Ruby on Rails. **Since a majority of my backend knowledge revolves around Rails, I will be comparing the two a little bit throughout this article. GraphQL is useful in the sense that it allows you to fetch the exact data that you need from the API, which allows for quicker loading times. Because of this, it functions optimally with mobile applications and is increasing in popularity among mobile cross-platform applications.
You can still use GET requests in order to fetch the data, and GraphQL utilizes these HTTP requests to grab data from single endpoints. Because of this, over-fetching and under-fetching issues are mitigated since the client can be specific with which data is being returned. In the relationships within the schema, it’s easy to traverse unnecessary data to fetch the requested data, where REST requires a little more effort to reach the fetch related resources.
Why is it important?
Now, why would we want to implement GraphQL if we already have REST that functions perfectly fine? Well, while this is true, the increase of mobile applications have also helped speed up the popularity of GraphQL. Because GraphQL only fetches the data it needs, it is the perfect partner in crime for mobile apps that need quick turnaround times for best performance. As the popularity of mobile apps rose, a lot of different front-end frameworks were also being developed. Due to REST’s lack of flexibility, it made it more difficult to build accompanying APIs. In addition, most modern applications have a lot of nested data that also can make data fetching difficult. There is no need for unnecessary data to be fetched. Because of this, Facebook began to develop GraphQL as the answer to this problem, and shortly after in 2015 became an open source project.
With that being said, REST and GraphQL do have some similarities. When fetching data with an HTTP get request, the requested data gets returned as JSON data. Both GraphQL and REST call functions on the server, and the ability to understand if an API is reading or writing data.
A really cool aspect of GraphQL is its IDE where you can test your API and endpoints to ensure your schema is correct, as well as running queries and mutations to your API.
In conclusion, GraphQL’s popularity makes it a great partner for languages such as Javascript and Go. The GraphQL documentation is a great resource to learn more about this young and budding technology.