GraphQL Guide

GraphQLQuery Language for APIs

Learn GraphQL schemas, queries, mutations, subscriptions, and building type-safe APIs.

Contents

GraphQL Basics

GraphQL is a query language for APIs and a runtime for executing those queries. It provides a complete description of the data in your API.

bash
# Installation (Apollo Server)
npm install apollo-server graphql
# or
npm install @apollo/server graphql

# Installation (Node.js with Express)
npm install express graphql express-graphql
graphql
# Basic GraphQL Query
query {
  user(id: "1") {
    id
    name
    email
    posts {
      title
      content
    }
  }
}

# Response
{
  "data": {
    "user": {
      "id": "1",
      "name": "John Doe",
      "email": "john@example.com",
      "posts": [
        {
          "title": "Post 1",
          "content": "Content 1"
        }
      ]
    }
  }
}