GraphQL Schema Definition Language

GraphQL provides a language called Schema Definition Language (SDL) for describing an API schema.

A simple schema might look like this:

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

type Query {
  user(id: ID!): User
  users: [User!]!
}

SDL is declarative. It describes what the API looks like rather than how data is retrieved.

The User type describes a user object. The Query type describes read operations available to clients.

Notice the distinction between a schema definition and implementation logic. The SDL says that user exists and accepts an ID!. It does not say whether the user comes from MongoDB, PostgreSQL, Redis, another HTTP service, or an in-memory object.

This separation is powerful because the API contract can remain stable while the underlying implementation changes.

A schema is not merely documentation. It is executable metadata used by GraphQL to validate operations and determine how the requested selection should be executed.

Basic GraphQL SDL
type User {
  id: ID!
  name: String!
  email: String!
}

type Query {
  user(id: ID!): User
  users: [User!]!
}
💡 The schema defines a User object and a root Query object. ID! means the ID is non-null. [User!]! means the users field itself cannot be null, and each user element inside the list also cannot be null.
Key Takeaways
  • SDL describes the public GraphQL API contract.
  • Schema definitions are separate from resolver implementation.
  • The schema is used for validation and execution.
  • GraphQL types make API capabilities explicit.
Knowledge Check

What does GraphQL SDL primarily describe?