Techniques for creating and populating Sanity schemas with example content using Faker.js and CLI.
Great questions about streamlining your prototyping workflow! Let me address both:
1. Creating Schemas via GUI
Unfortunately, there isn't a first-party or widely-adopted GUI schema builder for Sanity. The schemas are code-first by design, defined in TypeScript/JavaScript files. This approach gives you type safety, version control, and programmatic flexibility that visual builders typically can't match.
That said, you can make schema creation faster with:
- VS Code Snippets - The official Sanity extension includes snippets for quickly scaffolding schemas
- Templates - Many come with pre-built schemas you can adapt
- Recipes - Reusable schema patterns for common use cases
The code-first approach actually becomes an advantage once you're comfortable with it - you can copy, modify, and generate schemas programmatically, which is harder with GUI builders.
2. Generating Mock/Seed Data
This is where @sanity-typed/faker really shines! It's exactly what you're looking for - it generates realistic mock data based on your schemas using Faker.js under the hood.
Here's how it works:
import { sanityConfigToFaker } from "@sanity-typed/faker";
import { base, en } from "@faker-js/faker";
import config from "./sanity.config";
const sanityFaker = sanityConfigToFaker(config, {
faker: { locale: [en, base] }
});
// Generate a mock product document
const mockProduct = sanityFaker.product();This will generate fully-typed mock documents with realistic data for all your fields - strings, arrays, objects, references, etc. Perfect for prototyping and testing!
Custom Mocks
You can also customize the generated data using customMock on your schema types to match your specific needs.
Other Approaches
If you need to actually seed your dataset (not just generate mocks in memory), you can:
- Write a script using the Sanity client to create documents with
@sanity-typed/fakerdata - Use Sanity Functions to programmatically create content
- Check out community tools like @sanity-typed/client-mock for testing workflows
The @sanity-typed/faker package is part of the @sanity-typed ecosystem by Shayan Hashimoto, which also includes typed clients and GROQ helpers - definitely worth exploring if you're working with TypeScript!
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.