Hey all! I realize it’s been a while since I last posted. Amidst the chaos of the last weeks of bootcamp, the beginning of a new career (yay!), and adjusting to a WFH routine during a pandemic, I chose to take a step away from the blog for a bit. Now I’m back, and ready to share some advice, stories, guides, and bits of knowledge I’ve gained as I work to improve my technical skills post-graduation. I hope you find it helpful!
A few weeks into contributing to the landing page written in React, I began helping to redesign our database as we took a serverless approach with the help of AWS tools like AppSync and DynamoDB. In a few weeks, I hope to have some in-depth guides to share about what I’ve learned about these tools, but for now I’d like to take a step back to the fundamentals. In the next few posts I’ll introduce you to GraphQL, a query language used to retrieve and manipulate data from an API (and known by some as “The Better REST”1).
So, why do many devs prefer GraphQL to REST APIs? Short answer: Efficiency.
It replaces the need for multiple queries that generally will always return more data than necessary, with the ability to request info via single specific query to the GraphQL server.
For example: Imagine I’m a blog author (just imagine, guys) and you were to look at my profile. On the main page of my site, you’d see a list of my posts, recent subscribers, and my user photo + bio + display name. With REST, you’d have three GET requests right off the bat: /users/:id, /users/:id/blog-posts, and /users/:id/subscribers.

With GraphQL, you’d send a single query that included my display information (photo, bio, name), the usernames of the last 5 subscribers to my page, and the last three posts I published (titles + publish date + text snippet). You would get back exactly what you asked for: no more, no less. Here’s an example of a GraphQL query I created within AWS AppSync recently:

Here, I’m asking for rating data that includes an overall rating, the username of the person who gave the business that rating, and the name of the business being rated. This kind of specificity comes in handy when you’re trying to optimize performance and want more insightful analytics on highly interactive sites.
Hopefully this gives a little insight as to the advantages of building a GraphQL API. Check in next week for an overview of the GraphQL Type system!
Sources:
1. https://www.howtographql.com/basics/1-graphql-is-the-better-rest
2. https://www.rubrik.com/blog/graphql-vs-rest-apis/
