A collection groups entries with shared metadata. Export your collections from contentgraph.config.ts at the application root.

Define a collection

import { defineCollection } from "contentgraph";
import { z } from "zod";

export const collections = {
  posts: defineCollection({
    source: "./content/posts",
    schema: z.object({
      title: z.string(),
      draft: z.boolean().default(false),
    }),
  }),
};

Validation and types

Schemas follow Standard Schema V1; these examples use Zod. Validation runs during preparation, and validated outputs determine the query types. Async validation is supported.

Each entry has a top-level id. Keep id out of the metadata schema, and use distinct names for source fields, computed fields, and relationships.

Choose exactly one of source or loader. See sources and loaders for input formats.