Bytesized - Bytesized #005 — GraphQL 📈

Bytesized Newsletter
Bytesized
Ideas for technologists

Hey, it's Kristian πŸ‘‹

Real quick, before we get to today's newsletter -- we're giving away six copies of Colby Fayock's Jamstack Handbook at the end of this month. There's two ways to enter, and all you have to do is share the newsletter with your friends! Check out the bottom of this email to learn more.

With that, enjoy this week's Bytesized!

#005 β€” GraphQL πŸ“ˆ

πŸŽ“ What is it?

A query language for your API. GraphQL allows you to query any of your application's data from a single endpoint, using a typed query language.

GIF

GraphQL queries, which allow you to request data, kind of look like JSON. You can query anything and everything with a single query -- things like a single field or object:

GraphQL Query

You can build more complicated queries, like an object and all of the associated records it has for subfields:

GraphQL Types

GraphQL is typed. Everything you query in GraphQL has a definite type, like String, or for more complex values, you can define custom types, as seen above.

Mutations describe how and what to change data in your application. They look just like queries, but with the addition of data:

GraphQL Mutations

GraphQL queries and mutations are handled by resolvers. These are functions that are handled by your GraphQL server and look up the corresponding data that you're requesting.

βŒ› The past

GraphQL was built by Facebook as they built their News Feed feature. Per Brenda Clark:

The main problem with Facebook’s News Feed implementation on mobile: it wasn’t as simple as retrieving a story, who wrote it, what it says, the list of comments, and who liked the post. Each story was interconnected, nested, and recursive. The existing APIs weren’t designed to allow developers to expose a rich, news feed-like experience on mobile. They didn’t have a hierarchical nature, let developers select what they needed, or the capability to display a list of heterogeneous feed stories.

As tools like React and other powerful frontend user interface tools make it easier to build compelling, interactive applications, existing REST APIs are increasingly a performance liability. Given the News Feed example above, a REST API might make requests for a story, the comments, and profiles of the accounts who commented on the story:

GET /stories/1
GET /stories/comments
GET /users/1
GET /users/2
GET /users/3

With GraphQL, developers could just query for the story, and everything else they needed to render the News Feed components:

GET /graphql
Body:
  {
    story(id: 1) {
      text
      url
      comments {
        body
        user {
          name
          avatar
        }
      }
    }
  }

From Brenda Clark's above article:

Say, you have a vending machine. With traditional REST, you press one button on the vending machine and get one thing. So, you have to press lots of buttons one at a time to get everything you need. This process is slow.
But if you have special purpose buttons, you can get multiple things at once. So, for example, you could press a special purpose button and get four things from the vending machine.
A mix of these two approaches is to have a vending machine where you can press exactly the buttons you want in combination and get everything you need in one go. This is what GraphQL does.

πŸ€” Why it matters

GraphQL is one of many attempts to figure out what the future of APIs might look like. (For an alternative approach, read more about HATEOAS)

GraphQL is building for developer experience. This 2020 paper from the Universidade Federal de Minas Gerais in Brazil found that GraphQL offers substantial benefits in developer experience, regardless of experience level:

As our key finding, we found that GraphQL requires less effort to implement API queries, when compared with REST. We also showed that (i) queries whith many parameters are particularly more difficult to implement in REST than in GraphQL; (ii) we also observe that GraphQL requires less effort even for developers that have no previous experience which this technology. Also, interestingly, experts in REST APIs can also write GraphQL queries with less effort.

GraphQL is trying to reduce the number of barriers for front-end developers to build data-driven applications. Instead of needing to rely on backend developers to build APIs, frontend developers can build full-stack apps completely on their own.

πŸ‘Ά Where to start

  • "Learn GraphQL in 10 minutes" on our YouTube channel.
  • How to GraphQL is an extremely comprehensive guide to understanding GraphQL, both from the client and server perspectives.
  • Eve Porcello's upcoming GraphQL Workshop is poised to become a definitive resource for developers learning how to build and scale GraphQL applications.

πŸ“Œ Players

Here's a crucial thing to know: GraphQL is a spec, not a framework. This means that there are competing frameworks, tools, and solutions to help you get from start to finish with your GraphQL project. Here's some of the key players:

  • The Apollo GraphQL team is building what is probably the most popular GraphQL implementation in use by developers. They offer a fully-featured client and a Node.js server backend for deployment, so you can go from start to finish with their great tutorial to learn how to build with GraphQL. (note: this is what I did!)
  • FaunaDB combines a NoSQL database with a GraphQL API to make it easy to get up and running with a production-scale database for your apps. (They also sponsored this week's Bytesized -- thanks!)
  • Hasura wraps a world-class database (PostgreSQL) with a GraphQL API. Check out the demo they did on the Bytesized YouTube channel .
  • Prisma exposes a TypeScript ORM (object-relational mapping) for managing your data in Node. It generates an automatic GraphQL API for querying it.
  • OneGraph is building a GraphQL service that wraps APIs like Salesforce and Stripe into a single endpoint, so you can build SaaS tools using GraphQL.

πŸ™…β€β™€οΈ Criticisms

This Hacker News discussion covers the good, the bad and the ugly of moving to GraphQL from REST: "Ask HN: Were you happy moving your API from REST to GraphQL?"

LogRocket's blog post "5 Reasons You Shouldn't Be Using GraphQL" covers some common criticisms of GraphQL -- the disadvantages around adopting a ton of new tooling, caching behaviors, and more.

The Players section above reveals something interesting about GraphQL: it's a fairly fractured ecosystem. Apollo has a substantial advantage in developer mindshare over other GraphQL platforms. In particular, their JavaScript client is substantially more popular than anything else available. Alternative clients like urql exist, and it's worth checking them out to bring more people to the table answering the question "What should GraphQL clients look like?"

πŸ™‹ Who to know

And a funny tweet to sign off this week:

GraphQL Tweet

What did you think of Bytesized #5? Let us know by clicking a reaction below ⏬

😍 🀯 😴 😑 πŸ‘ πŸ‘Ž

Bytesized is a weekly newsletter exploring ideas for developers. Join us on our Discord server πŸ‘‹

Refer your friends to our newsletter!

You'll get rewards and swag as you refer more people to Bytesized :)

It’s easy, just copy and paste your unique link and share it in an email, on Twitter, or wherever you like. Thanks for spreading the word!

Your referral link: https://bytesized-newsletter.carrd.co?rh_ref=d69b9b2f

Bytesized is produced by Kristian Freeman (hello!)

You can unsubscribe from our emails here.

10025 Wind Cave Trail, Austin, TX 78747

Older messages

Bytesized #001 — Human-computer interfaces

Sunday, December 6, 2020

Bytesized Ideas for technologists 🔐 Overwhelmed by auth? Auth0 lets you quickly and easily add rock-solid authentication to your applications, including universal login, multi-factor authentication,

Bytesized #002 — Svelte.js ⚡️

Sunday, December 6, 2020

Bytesized Ideas for technologists 🔐 Overwhelmed by auth? Auth0 lets you quickly and easily add rock-solid authentication to your applications, including universal login, multi-factor authentication,

Bytesized #003 — Serverless 📦

Sunday, December 6, 2020

Bytesized Ideas for technologists 🔐 Overwhelmed by auth? Auth0 lets you quickly and easily add rock-solid authentication to your applications, including universal login, multi-factor authentication,

This is what happens when software developers run Black Friday deals

Sunday, December 6, 2020

​ I know that you're going to get a thousand of these kind of emails today, so I'll keep it short and sweet. We're working with eight excellent authors and educators over the next few days

This is what happens when software developers run Cyber Monday deals

Sunday, December 6, 2020

​ Happy Cyber Monday 🤖 I know that you're going to get a thousand of these kind of emails today, so I'll keep it short and sweet. We're working with eight excellent authors and educators

You Might Also Like

Dark forest, bad art and paying to bike

Saturday, December 28, 2024

Neologism #24, 28.12.2024 ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏

Weekend Reading — Happy New Year! 🥳

Saturday, December 28, 2024

Vitalis 🇺🇦 The most original and unusual landmark in Odesa, which has become a symbol of the creativity of Odesa residents. Tech Stuff Cursor I really really like Cursor. I had a great time using VS

Daily Coding Problem: Problem #1651 [Hard]

Saturday, December 28, 2024

Daily Coding Problem Good morning! Here's your coding interview problem for today. This problem was asked by Apple. You are going on a road trip, and would like to create a suitable music playlist.

📺 There's Still A Place for Universal Remotes — 10 Apps I Always Install on a New Mac

Saturday, December 28, 2024

Also: How to Add Emails to Your Tasks To-Do List in Gmail, and More! How-To Geek Logo December 28, 2024 Did You Know In December 2014, two con men from Girona, Spain, agreed to sell a fake Francisco de

Ranked | The World's Top 30 Countries, by Automobiles Manufactured 🚙

Saturday, December 28, 2024

In 2023, China led global car production, contributing nearly a third of total output. Which countries followed in this competitive industry? View Online | Subscribe | Download Our App FEATURED STORY

🐍 New Python tutorials on Real Python

Saturday, December 28, 2024

Hey there, There's always something going on over at Real Python as far as Python tutorials go. Here's what you may have missed this past week: Learn From 2024's Most Popular Python

15,000+ Four-Faith Routers Exposed to New Exploit Due to Default Credentials

Saturday, December 28, 2024

THN Daily Updates Newsletter cover Resilient Cybersecurity ($39.99 Value) FREE for a Limited Time Reconstruct your defense strategy in an evolving cyber world Download Now Sponsored LATEST NEWS Dec 28,

Hands Down One Of The Best Cards For 2025 Offering 0% interest until 2026

Saturday, December 28, 2024

iPhoneLife Logo Sponsored email sent by iPhone Life Hands Down One Of The Best Cards For 2025 Offering 0% interest until 2026 If you have outstanding credit card debt, getting a new 0% intro APR credit

📧 What Rewriting a 40-Year-Old Project Taught Me About Software Development

Saturday, December 28, 2024

​ What Rewriting a 40-Year-Old Project Taught Me About Software Development Read on: m​y website / Read time: 7 minutes The .NET Weekly is brought to you by: As the year wraps up, it's clear API

This Week in Rust #579

Saturday, December 28, 2024

Email isn't displaying correctly? Read this e-mail on the Web This Week in Rust issue 579 — 25 DEC 2024 Hello and welcome to another issue of This Week in Rust! Rust is a programming language