Build the mental model
An `enum` restricts a field to an exact set of allowed values, catching typos at the validation level instead of at runtime. An `interface` is a contract that lets multiple object types share common fields (such as `id` and `title`); a type promises to implement every interface field using the `implements` keyword. Clients can query interface fields and get common data even without knowing the concrete type.
Connect it to a real scenario
Define a `Difficulty` enum with `BEGINNER | INTERMEDIATE | ADVANCED` and use it on `Tutorial.difficulty`. Declare a `Content` interface with `id` and `title`, and have both `Tutorial` and `Exercise` implement it, so a homepage search-result list can render both content types through the same shared fields.
Try the working example
enum Difficulty {
BEGINNER
INTERMEDIATE
ADVANCED
}
interface Content {
id: ID!
title: String!
}
type Tutorial implements Content {
id: ID!
title: String!
difficulty: Difficulty!
}
type Exercise implements Content {
id: ID!
title: String!
points: Int!
}You can write enums and interfaces and share fields across types in a schema.5-minute try-it
Write a `Status` enum (`DRAFT | PUBLISHED | ARCHIVED`) and add a `status: Status!` field to `Tutorial`.
One important caution
Changing an interface field's shape in an implementing type (rather than only narrowing return type covariantly) causes a schema validation error.
GraphQL — Schemas and Types — GraphQL