CyberCode Academy

Course 37 - Building Web Apps with Ruby On Rails | Episode 18:Navigating GraphQL and the Graphiti Middle Ground


Listen Later

In this lesson, you’ll learn about: REST limitations, GraphQL fundamentals, and the hybrid approach with Graphiti1. The Problem with REST APIsUsing REST:🔹 Key limitations:
  • Overfetching
    • Client receives more data than needed
  • Underfetching
    • Requires multiple requests to get all data
  • No strict typing
    • Errors happen at runtime
    • Heavy reliance on documentation
👉 Key Insight
REST is simple and scalable—but not always efficient2. Example of Overfetching🔹 Request:GET /users/1 🔹 Response:{ "id": 1, "name": "John", "email": "[email protected]", "address": "...", "preferences": "...", "settings": "..." } 👉 Problem:
  • Client may only need name
👉 Key Insight
REST responses are fixed by the server, not flexible for clients3. Introducing GraphQLUsing GraphQL:🔹 What it solves:
  • Clients request exactly what they need
🔹 Example query:{ user(id: 1) { name } } 👉 Response:{ "data": { "user": { "name": "John" } } } 👉 Key Insight
GraphQL eliminates overfetching and underfetching4. GraphQL Schema (Core Concept)🔹 Schema:
  • Defines types and relationships
  • Acts as a contract between client and server
🔹 Example:type User { id: ID name: String email: String } 👉 Key Insight
GraphQL is strongly typed, unlike REST5. Queries vs Mutations🔹 Queries (read data):{ users { name } } 🔹 Mutations (write data):mutation { createUser(name: "John") { id } } 👉 Key Insight
GraphQL separates read and write operations clearly6. Testing with GraphiQL🔹 Tool:
  • GraphiQL
🔹 Features:
  • Run queries in browser
  • Explore schema
  • Debug 
👉 Key Insight
GraphiQL improves developer experience significantly7. Downsides of GraphQL🔹 Trade-offs:
  • No native HTTP caching
  • More complex setup
  • Boilerplate code
  • No strict naming conventions
👉 Key Insight
GraphQL flexibility comes with added complexity8. Introducing Graphiti (Hybrid Approach)Using Graphiti:🔹 Goal:
  • Combine REST simplicity + GraphQL flexibility
🔹 Features:
  • Filtering
  • Sorting
  • Including relationships
👉 Key Insight
Graphiti gives you flexibility without abandoning REST9. Graphiti Resources🔹 Concept:
  • Define API behavior using “Resources”
🔹 Example:class UserResource < ApplicationResource attribute :name, :string end 👉 Key Insight
Resources act like a structured API layer10. REST vs GraphQL vs Graphiti🔹 REST:
  • Simple
  • Fast
  • Limited flexibility
🔹 GraphQL:
  • Flexible
  • Precise data fetching
  • More complex
🔹 Graphiti:
  • Balanced approach
  • Keeps HTTP benefits
  • Adds flexibility
👉 Key Insight
There is no perfect solution—only trade-offs11. When to Use Each🔹 Use REST:
  • Simple APIs
  • Standard CRUD apps
🔹 Use GraphQL:
  • Complex frontend needs
  • Multiple data sources
🔹 Use Graphiti:
  • Want flexibility + REST structure
👉 Key Insight
Choose based on project complexity and team needsKey Takeaways
  • REST suffers from overfetching and lack of typing
  • GraphQL provides flexible, precise queries
  • GraphQL introduces complexity and trade-offs
  • Graphiti offers a middle-ground solution
  • API design is about balancing performance, flexibility, and simplicity


You can listen and download our episodes for free on more than 10 different platforms:
https://linktr.ee/cybercode_academy
...more
View all episodesView all episodes
Download on the App Store

CyberCode AcademyBy CyberCode Academy