Includes
Why Includes Exist
As schemas grow, it is useful to split them into focused files.
For example:
schema.vdl
shared.vdl
events.vdlUse include to bring definitions from another .vdl file into the same compilation context.
Basic Syntax
include "./shared.vdl"
type UserSession {
token string
account Account
}The included file can define types, enums, constants, or documentation used by the current file.
Example shared.vdl:
type Account {
id string
email string
}Example schema.vdl:
include "./shared.vdl"
type Session {
account Account
token string
}Session.account can use Account because schema.vdl includes shared.vdl.
Relative Paths
Include paths are resolved relative to the file that contains the include statement.
include "../shared/types.vdl"
include "./events/user_events.vdl"This makes each file self-contained: moving the entry point does not change how nested includes are resolved.
Include Graphs
Includes are recursive. If schema.vdl includes orders.vdl, and orders.vdl includes money.vdl, all three files are analyzed together.
include "./orders.vdl"
type Checkout {
order Order
}Each file is processed once. Circular includes are reported as diagnostics.
File Name Rules
Regular included schema files should have names matching this pattern:
[a-z0-9_]+.vdlGood names:
shared.vdl
order_events.vdl
api_v1.vdlAvoid names like:
Shared.vdl
order-events.vdl
schema.backup.vdlConfig Files Are Not Included
vdl.config.vdl is the project generation configuration file. It cannot be included as a normal schema file.
Keep language schemas and generation configuration separate:
schema.vdl # Your contracts
vdl.config.vdl # Plugin generation configurationPractical Advice
- Put shared primitives, aliases, and base objects in files like
shared.vdl. - Put event contracts in files like
events.vdloruser_events.vdl. - Keep the main entry file small and readable.
- Prefer shallow include graphs when possible.