Course contentsShow
← Web Development
Lesson 1521 of 2,98228. GraphQL FundamentalsFree lesson

Schema Definition Language (SDL)

Writing GraphQL schemas using SDL syntax to describe types, fields, and their relationships.

Schema Definition Language (SDL)

You'll learn how to define a GraphQL API's structure using SDL, the declarative syntax that describes your data types, fields, and their relationships.

What is SDL?

Schema Definition Language (SDL) is GraphQL's built-in syntax for writing schemas—a blueprint that defines what data your API can provide and how it's structured. Think of it like creating a contract: you're declaring "Here's what exists, here's what fields each thing has, and here's how they connect."

Unlike REST where your API structure is often implicit (buried in code and documentation), SDL makes everything explicit and human-readable.

Core SDL Concepts

SDL uses a simple, declarative syntax to define types. Each type has a name and fields, and each field has a specific data type.

The most common pattern looks like this:

type User {
  id: ID!
  name: String!
  email: String
  age: Int
}

The exclamation mark (!) means a field is required (non-nullable). Without it, the field is optional.

Relationships Between Types

SDL really shines when you define how types connect to each other:

type Post {
  id: ID!
  title: String!
  author: User!
}

Here, every Post has an author field that references a User type. This creates a clear relationship graph.

You can also define lists:

type User {
  id: ID!
  name: String!
  posts: [Post!]!
}

This means a user has a list of posts (the outer ! means the list itself is required, the inner ! means no null items in the list).

Key Takeaway: SDL provides a clear, type-safe way to declare your API's entire data structure using simple, readable syntax that defines types, fields, and their relationships—making your API self-documenting and predictable.