What is a GraphQL schema and what is the Schema Definition Language (SDL)?
Understand the GraphQL schema as a typed API contract and the Schema Definition Language (SDL) used to declare types, root operations, and inputs.
Expected Interview Answer
A GraphQL schema is the strongly typed contract that defines every type, field, and operation a GraphQL API supports, and the Schema Definition Language (SDL) is the human-readable, language-agnostic syntax used to write that schema.
The schema declares object types and their fields, plus the special root types Query, Mutation, and Subscription that serve as entry points. SDL expresses this with a simple declarative syntax — `type`, `input`, `enum`, `interface`, `union`, and scalar types — independent of any programming language. Because the schema is typed and introspectable, the server can validate every incoming operation against it before execution, and tools can auto-generate documentation and client types.
- Acts as a single source of truth for the API
- Enables validation of queries before execution
- Language-agnostic and easy to read
- Powers introspection, docs, and code generation
- Decouples front-end and back-end teams via a shared contract
AI Mentor Explanation
A GraphQL schema is like the official laws and scorecard template of cricket: it declares what a 'batter', an 'over', and a 'dismissal' are and which fields each carries. SDL is the printed rulebook written in plain language so any umpire, anywhere, reads the same definitions and can reject a scoring entry that breaks the format.
Step-by-Step Explanation
Step 1
Declare object types
Use `type` in SDL to define entities like User or Post and list each field with its type.
Step 2
Add scalars and enums
Use built-in scalars (String, Int, Boolean, ID) and custom enums to constrain field values.
Step 3
Define root types
Declare Query, Mutation, and Subscription types as the entry points clients can call.
Step 4
Use inputs for arguments
Define `input` types to pass structured arguments into queries and mutations.
Step 5
Wire resolvers
Back each field in the schema with a resolver so the server can produce its value at runtime.
What Interviewer Expects
- Definition of the schema as the typed API contract
- Understanding that SDL is the syntax used to write it
- Knowledge of the three root types (Query, Mutation, Subscription)
- Familiarity with type kinds: object, scalar, enum, input, interface, union
- Awareness that the schema powers validation and introspection
Common Mistakes
- Confusing the schema with resolvers or the database
- Thinking SDL is tied to a specific programming language
- Forgetting the non-null (!) and list ([]) type modifiers
- Mixing up `input` types with regular object types
- Not knowing Query is required while Mutation/Subscription are optional
Best Answer (HR Friendly)
“A GraphQL schema is the rulebook that says what data the API offers and how it is shaped. SDL is the simple, readable language used to write that rulebook, so both front-end and back-end teams agree on the same contract.”
Code Example
type User {
id: ID!
name: String!
email: String
posts: [Post!]!
}
type Post {
id: ID!
title: String!
author: User!
}
input CreateUserInput {
name: String!
email: String!
}
type Query {
user(id: ID!): User
}
type Mutation {
createUser(input: CreateUserInput!): User!
}Follow-up Questions
- What is the difference between an object type and an input type?
- What do the ! and [] modifiers mean in SDL?
- What are interfaces and unions used for in a schema?
- How does introspection use the schema?
- Which root type is mandatory in every GraphQL schema?
MCQ Practice
1. What does SDL stand for in GraphQL?
SDL is the Schema Definition Language — the readable, language-agnostic syntax used to declare a GraphQL schema.
2. In SDL, what does the '!' after a type mean, as in 'name: String!'?
A trailing '!' marks the field as non-nullable, meaning the server guarantees it will never return null for that field.
Flash Cards
What is a GraphQL schema? — The strongly typed contract defining all types, fields, and operations an API supports.
What is SDL? — Schema Definition Language — the readable, language-agnostic syntax used to write a GraphQL schema.
The three root types — Query (read), Mutation (write), and Subscription (real-time). Only Query is mandatory.
Meaning of String! vs [Post!]! — String! is a required string; [Post!]! is a required list whose items are each required Post objects.