Is it possible to connect @sanity/client to local studio when developing?

5 replies
Last updated: Sep 9, 2020
Hello! Quick question: Is it possible to connect
@sanity/client
to local studio when developing? I want to try out some schema changes before deploying it.
AI Update

The short answer is: no, you cannot connect @sanity/client directly to your local Studio instance. The Sanity client always connects to the hosted Content Lake (your project's cloud-hosted datasets), not to the Studio application itself.

However, you have several good options for testing schema changes safely before deploying to production:

Use a separate dataset for development

The recommended approach is to create a staging or development dataset within your project. You can work with this dataset locally while testing schema changes:

import {createClient} from '@sanity/client'

const client = createClient({
  projectId: 'your-project-id',
  dataset: 'development', // or 'staging' instead of 'production'
  apiVersion: '2024-01-01',
  useCdn: false
})

You can create additional datasets through the Sanity Manage interface or CLI. As mentioned in the projects documentation, projects support multiple datasets for different development stages - production, development, and staging datasets allow you to test features and migrations while maintaining content integrity.

Copy data between datasets

If you want to test with realistic data, you can copy content from your production dataset to your development dataset using the sanity dataset copy command:

sanity dataset copy production development

This creates a snapshot of your production content in the development dataset, letting you experiment safely.

Why the Studio isn't a "server"

It's important to understand that Sanity Studio is just a React application - it's a frontend interface that also connects to the Content Lake via the client. The Studio doesn't host your content locally; it's always reading from and writing to your cloud-hosted datasets. This architecture means your content is always in the Content Lake, whether you're accessing it through Studio, your website, or any other client.

This multi-dataset approach is actually quite powerful - you can run your local Studio pointed at a development dataset, test your schema changes there, and once you're confident, deploy the schema and switch your production Studio and clients to use it.

Is this what I want to learn and use or is there some best practise way to test schema changes while developing? https://www.sanity.io/blog/getting-started-with-sanity-as-a-headless-cms#migrating-your-content-is-easy-c204f379a409
Exporting and importing your dataset can make a lot of sense for testing in this way. You’ll want to make a “development” dataset on your project and when you’re working locally, you can use a different dataset (https://www.sanity.io/docs/sanity-json#environments-933842c25dea )
When you’ve got that, you can import your production data into the development dataset to have a close approximation to your live data before testing your schema
Exporting and importing your dataset can make a lot of sense for testing in this way. You’ll want to make a “development” dataset on your project and when you’re working locally, you can use a different dataset (https://www.sanity.io/docs/sanity-json#environments-933842c25dea )
When you’ve got that, you can import your production data into the development dataset to have a close approximation to your live data before testing your schema
That makes sense! Awesome, I'm gonna try it and also set up nightly backups to S3 and I'll sleep better 😄 Thanks! 🙏
Data Redundancy = better sleep 😄

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.

Was this answer helpful?