Skip to content

GraphQL Introduction — A Query Language for Modern APIs

DodaTech Updated 2026-06-28 2 min read

In this tutorial, you will learn about Graphql Introduction. We cover key concepts, practical examples, and best practices to help you master this topic.

GraphQL is an API query language developed by Meta that allows clients to specify exactly what data they need in a single request, receiving predictable results without the over-fetching common in REST.

What You'll Learn

  • How GraphQL differs from REST in data fetching
  • The core concepts of queries, mutations, and subscriptions
  • When to choose GraphQL over REST

Why It Matters

GraphQL reduces the number of API calls needed for complex UIs and eliminates over-fetching. DodaTech's Durga Antivirus Pro dashboard uses GraphQL to let the UI request only the threat data it needs per view.

flowchart LR
    A["Client Query"] --> B["GraphQL API\n(Single Endpoint)"]
    B --> C["Type System\n(Schema)"]
    B --> D["Resolvers"]
    D --> E["Database"]
    D --> F["External API"]
    D --> G["Cache"]
    A --> H["Response:\nExactly What Was Requested"]
    style B fill:#dbeafe,stroke:#2563eb

Code Examples

# GraphQL query
query {
  user(id: "123") {
    name
    email
    posts {
      title
    }
  }
}
// Calling GraphQL from Node.js
const query = `
  query {
    user(id: "123") {
      name
      email
      posts {
        title
      }
    }
  }
`;

fetch('https://api.example.com/graphql', {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({query})
})
.then(res => res.json())
.then(data => console.log(data));
import requests

query = """
query {
  user(id: "123") {
    name
    email
  }
}
"""
response = requests.post(
    "https://api.example.com/graphql",
    json={"query": query}
)
print(response.json())

Common Mistakes

1. Not Using a Schema

GraphQL's power comes from its strongly typed schema. Without it, you lose validation and introspection.

2. Creating N+1 Queries

Without DataLoader or batching, each nested field can cause a separate database query.

3. Ignoring Authentication

GraphQL resolves all fields. Ensure authorization checks run per field.

4. Using GraphQL for Simple CRUD

REST is simpler for basic CRUD operations with no complex data requirements.

5. Not Limiting Query Depth

Malicious clients can create deeply nested queries that overwhelm the server.

Practice Questions

  1. What problem does GraphQL solve that REST doesn't?
  2. What are the three operation types in GraphQL?
  3. How does GraphQL know what data is available?
  4. What is a resolver in GraphQL?
  5. Why might you choose REST over GraphQL?

Answers:

  1. Over-fetching (getting too much data) and under-fetching (needing multiple requests).
  2. Query (read), Mutation (write), Subscription (real-time).
  3. Through the schema, which defines types, fields, and relationships.
  4. A resolver is a function that fetches data for a specific field in the schema.
  5. For simple CRUD APIs, when HTTP Caching is critical, or when the team isn't familiar with GraphQL.

Challenge: Design a GraphQL schema for a blog with users, posts, and comments. Include queries, mutations, and at least one subscription.

FAQ

Who created GraphQL?

: GraphQL was developed internally by Meta (Facebook) and open-sourced in 2015.

Is GraphQL a database language?

: No. GraphQL is an API query language. It communicates with databases through resolvers.

Can GraphQL replace REST entirely?

: Not entirely. REST is still better for simple CRUD, file uploads, and HTTP caching.

What's Next

Compare GraphQL with REST APIs, or explore the GraphQL Schema and Types system in depth.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro