🦥 GraphQL for Dummies

Hello friends!

Welcome to this week’s Sloth Bytes. I hope you had a great week 😁 

Start learning AI in 2025

Keeping up with AI is hard – we get it!

That’s why over 1M professionals read Superhuman AI to stay ahead.

  • Get daily AI news, tools, and tutorials

  • Learn new AI skills you can use at work in 3 mins a day

  • Become 10X more productive

🦥 GraphQL for Dummies

Facebook started developing GraphQL in 2012.

At first it was an internal alternative to REST.

The goal was to overcome issues like over-fetching and under-fetching, which resulted in slow network performance and poor user experience. 

Later on in 2015 Facebook open-sourced it and now everyone from GitHub to Shopify uses it.

What Is GraphQL?

It's just a different way to build APIs.

REST: Multiple endpoints, fixed responses

`GET /users/123` → Returns ALL user fields
`GET /posts/456` → Returns ALL post fields

GraphQL: One endpoint, custom responses

query {
  user(id: 123) {
    name    # Only get what
    posts { # you actually need.
      title
    }
  }
}

The 3 Concepts You Need To Know

1. Schema (The Menu)

type User {
  id: ID!          # ! means required
  name: String!
  posts: [Post!]!  # [] means list
}

2. Queries (Getting Stuff)

query {
  user(id: 123) {
    name
    posts {
      title
    }
  }
}

3. Mutations (Changing Stuff)

mutation {
  createPost(title: "Hello") {
    id
  }
}

That's it. You now understand most of GraphQL.

Why GraphQL is Useful

Instead of having to do something like this with REST:

// REST: 4 requests 
await fetch('/api/users/123')
await fetch('/api/users/123/posts')
await fetch('/api/users/123/followers')
await fetch('/api/users/123/likes')

You get this:

# GraphQL: 1 request 
query {
  user(id: 123) {
    name
    posts { title }
    followers { count }
    likes { total }
  }
}

The Gotchas

Caching: REST can caches URLs automatically. GraphQL needs special clients like Apollo.

N+1 Queries: One innocent request can spawn 100 database queries if you're not careful.

When to Use GraphQL Vs REST

GraphQL:

  • Multiple clients (mobile/web) need different data

  • Deeply nested data

  • Tired of over-fetching or under-fetching.

REST:

  • Need simple HTTP caching

  • Public API

  • Team already productive with REST

The Truth

GraphQL isn't better than REST. It solves different problems.

Facebook didn't invent it because REST sucks, they invented it because they had Facebook-scale problems.

Most apps? REST works fine. But if you're making 10 API calls per page? Time to look at GraphQL.

If you want to try using GraphQL, I think the best place to start is here:

Amazing feedback as always!

Den: All of your chats, docs and agents in one place.

I thought this looked really cool and I hope this succeeds!

What is it?

Den is basically a platform that combines your chats, docs, and AI agents into one place.

Think Slack + Notion + AI agents/workflows.

Instead of copy-pasting between ChatGPT, Slack, and your documents/notes, you can have everything in one place.

You and your team can also create AI agents/workflows to automate tasks all without switching tabs.

They currently have over 50+ integrations and these agents keep working in the background even if you log off.

Which means you can multi-task or sleep, and come back to updated docs, analyzed data, and completed tasks.

Thanks to everyone who submitted!

The Actual Memory Size of Your USB Flash Drive

Create a function that takes the memory size (ms) as an argument and returns the actual memory size.

Examples

actualMemorySize("32GB")
output = "29.76GB"

actualMemorySize("2GB")
output = "1.86GB"

actualMemorySize("512MB")
output = "476MB"

Notes

  • The actual storage loss on a USB device is 7% of the overall memory size!

  • If the actual memory size was greater than 1 GB, round your result to two decimal places.

  • If the memory size after adjustment is smaller then 1 GB, return the result in MB.

  • For the purposes of this challenge, there are 1000 MB in a Gigabyte.

How To Submit Answers

Reply with

  • A link to your solution (github, twitter, personal blog, portfolio, replit, etc)

  • or if you’re on the web version leave a comment!

  • If you want to be mentioned here, I’d prefer if you sent a GitHub link or Replit!

New video coming out this week!

I’m almost done with it, hopefully I have it ready Thursday.

That’s all from me!

Have a great week, be safe, make good choices, and have fun coding.

If I made a mistake or you have any questions, feel free to comment below or reply to the email!

See you all next week.

What'd you think of today's email?

Login or Subscribe to participate in polls.

Want to advertise in Sloth Bytes?

If your company is interested in reaching an audience of developers and programming enthusiasts, you may want to advertise with us here.

Reply

or to participate.