Schema Definition Language (SDL) in GraphQL
From the GraphQL cheat sheet · Setup & Basics · verified Jul 2026
Schema Definition Language (SDL)
graphql
# Scalar types
scalar Date
scalar JSON
# Enums
enum Role {
ADMIN
USER
GUEST
}
# Object types
type User {
id: ID! # Non-nullable ID
name: String! # Required string
email: String # Optional string
age: Int
isActive: Boolean!
role: Role!
createdAt: Date!
metadata: JSON
posts: [Post!]! # Non-null list of non-null Posts
friends: [User] # Nullable list of nullable Users
}
type Post {
id: ID!
title: String!
content: String!
published: Boolean!
author: User! # Relationship
comments: [Comment!]!
tags: [String!]!
}
# Input types for mutations
input CreateUserInput {
name: String!
email: String!
password: String!
role: Role = USER # Default value
}
input UpdateUserInput {
name: String
email: String
isActive: Boolean
}
# Interfaces
interface Node {
id: ID!
}
# Union types
union SearchResult = User | Post | Comment
# Root types
type Query {
# User queries
users(limit: Int = 10, offset: Int = 0): [User!]!
user(id: ID!): User
currentUser: User
# Post queries
posts(published: Boolean): [Post!]!
post(id: ID!): Post
# Search
search(query: String!): [SearchResult!]!
}
type Mutation {
# User mutations
createUser(input: CreateUserInput!): User!
updateUser(id: ID!, input: UpdateUserInput!): User
deleteUser(id: ID!): Boolean!
# Post mutations
createPost(title: String!, content: String!): Post!
publishPost(id: ID!): Post
}
type Subscription {
# Real-time updates
userAdded: User!
postPublished: Post!
commentAdded(postId: ID!): Comment!
}💡 Schema defines API structure and types
⚡ ! means non-nullable, [] means list
📌 Scalar types: Int, Float, String, Boolean, ID
🔥 Custom scalars for dates, JSON, etc.