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...