Posts

Lesson 2: Building a GraphQL API from Scratch

 📌 Goal: By the end of this, you'll have a working GraphQL API with queries, mutations, and resolvers. 🛠️ Step 1: Setting Up a GraphQL Server We’ll use Node.js with Apollo Server . If you haven't already, install dependencies: mkdir graphql-server && cd graphql-server npm init -y npm install apollo-server graphql Then, create a file index.js and set up a basic Apollo Server: const { ApolloServer , gql } = require ( 'apollo-server' ); // Define schema const typeDefs = gql` type Book { id : ID ! title : String ! author : String ! } type Query { books : [ Book ] } `; // Sample data const books = [ { id : "1" , title : "The Pragmatic Programmer" , author : "Andy Hunt" }, { id : "2" , title : "Clean Code" , author : "Robert C. Martin" } ]; // Define resolvers const resolvers = { Query : { books : () => books, }, }; // Start th...

The Story Begins: A World Drowning in REST

  📜 The Story Begins: A World Drowning in REST Once upon a time, developers ruled the digital lands using REST APIs to summon data from vast databases. These RESTful incantations worked… at first. But over time, the lands grew chaotic: Developers had to make multiple REST calls to different endpoints. Sometimes they received too much data , other times not enough . Frontend wizards grew tired of the inefficiencies. And from this frustration, a new magic was born— GraphQL , forged at Facebook in 2012 and made open to the world in 2015. 🔍 What is GraphQL? (Deductive Angle) Let’s reason it out. Think: Graph → a network of connected nodes (like entities and their relationships). QL = Query Language. So GraphQL is a query language for APIs that lets you: ✅ Request exactly what you need — no more, no less. ✅ Fetch multiple related resources in one request . ✅ Ask for nested data in a tree-like structure , closely resembling your UI. Reflect for a moment: What i...