Course contentsShow
← Software Engineering
Lesson 806 of 1,93325. RPC and GraphQL API DesignFree lesson

GraphQL Schema and Type System

Defining schemas with scalar types, object types, and the role of the schema as the API contract.

GraphQL Schema and Type System

You'll learn: How a GraphQL schema defines the complete contract between client and server using a strongly-typed system.

The Schema as API Contract

In GraphQL, the schema is the single source of truth—it's the formal contract that describes exactly what data clients can query and what operations they can perform. Think of it like a restaurant menu: it lists every dish available, what ingredients each contains, and what you can order. Clients can't request something that's not on the menu.

Unlike REST where you might discover endpoints through documentation (or trial and error), GraphQL's schema is machine-readable and self-documenting. Tools can introspect the schema to show developers exactly what's possible.

Building Blocks: Types

The schema is built from types. GraphQL provides several built-in scalar types that represent single values:

  • Int: Whole numbers
  • Float: Decimal numbers
  • String: Text
  • Boolean: true/false
  • ID: Unique identifier

Object types represent complex entities with multiple fields. For example, a User object type might have fields like id (ID), name (String), and age (Int). Each field has a specific type, creating a strongly-typed graph of related data.

The schema defines a root Query type listing all possible read operations—these are your entry points into the data graph.

Why This Matters

The schema enforces what queries are valid before execution. Invalid queries are rejected immediately. This catches errors early, enables powerful tooling (autocomplete, validation), and makes APIs self-explanatory. Both humans and machines can read the schema to understand capabilities without separate documentation.

Key Takeaway:
The GraphQL schema uses scalar and object types to create a strongly-typed contract that precisely defines what data clients can request and what shape responses will have.