Watch a live product demo 👀 See how Sanity powers richer commerce experiences

I’m hoping to use Sanity as an earlier part of our design and prototyping workflow. Are there any techniques or plugins folks would recommend to – 1. Create Sanity schemas...

7 replies
Last updated: Dec 15, 2020
I’m hoping to use Sanity as an earlier part of our design and prototyping workflow.
Are there any techniques or plugins folks would recommend to –

1. Create Sanity schemas via a GUI?
2. Populate a Sanity instance with example content based on the schema (similar to using Faker.js directives)?
Wish #1 would definitely be helpful in some circumstances, although not critical.

Wish #2 would be vital to exemplify a model, to better design against it.

How are others faking or mocking realistic dummy data in Sanity?
Dec 12, 2020, 6:47 PM
user Y
is pre-populating a Sanity database with mock content something you’ve run into before (e.g. to support a content-first design/dev process)?
Dec 13, 2020, 5:47 PM
Hey there! 🙂
As far as I know there does not exist a GUI tool for creating schemas. That would be lovely though! So if you find one let me know
😄
In regards to 2: Faker.js looks very unassuming on what you do with it. So I picture you can easily make a node script that creates objects for your schema with Faker.js data and either saves it to an
ndjson
file that you later can import into Sanity via the CLI or directly by using the JS client so you don't have to temporaily store the data on local disk.
Dec 14, 2020, 7:34 AM
☝️ Right on!
I'd also add that when I worked with Sanity back in the agency days, we also strived to get real project content in as early as possible (we actually pretty much banned
lorem ipsum
 because real content always brings surprises).

user S
has made a schema generator that takes you one step closer to that GUI experience. https://sanity-schema.simeongriggs.dev/ You could also check out the Sanity Snippets for VS Code if you want to make'em quicker.
Dec 14, 2020, 7:41 AM
☝️ Right on!
I'd also add that when I worked with Sanity back in the agency days, we also strived to get real project content in as early as possible (we actually pretty much banned
lorem ipsum
 because real content always brings surprises).

user S
has made a schema generator that takes you one step closer to that GUI experience. https://sanity-schema.simeongriggs.dev/ You could also check out the Sanity Snippets for VS Code if you want to make'em quicker.
Dec 14, 2020, 7:41 AM
user A
user Y
Thanks!
Using Faker to emulate realistic content would be great.


I picture you can easily make a node script that creates objects for your schema with Faker.js data and either saves it to an 
ndjson
 file that you later can import into Sanity via the CLI  or directly by using the JS client
Are there any analogous code samples you code point me for sorting out how to build a pipeline like this 👆?
Dec 14, 2020, 4:32 PM
Say you want to generate 10 000 random users. I imagine the Faker.js script can look something like this:

// file: generate_data.js
const faker = require("faker");

const noUsersToGenerate = 10000; // 10 000

for (let i = 0; i < noUsersToGenerate; i++) {
  const newUser = {
    _id: faker.random.uuid(),
    _type: "user",
    name: faker.name.findName(),
    email: faker.internet.email(),
  };

  console.log(JSON.stringify(newUser));
}
Which will output
ndjson
directly that you can re-route to a file:

$ node generate_data.js > my_fake_data.ndjson
Which you can then import to Sanity with the CLI:


$ sanity dataset import my_fake_data.ndjson name-of-my-dataset
I'm sure you can do this a lot of fancy ways where the generate script'll parse your Sanity schema so you don't have to write it manually. But it doesn't have to be more complex than this to get you started I think
🙂
Hope it helps! Please share in
i-made-this if you make something cool 😄
Dec 15, 2020, 7:40 AM
Thanks so much Benedicte. 🙌
I’ll play with this to see what results I can possibly build out.
Dec 15, 2020, 12:16 PM

Sanity.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Categorized in

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing