How to configure multiple workspaces in Sanity v3 with GraphQL APIs?
When you're working with multiple workspaces in Sanity v3 and trying to deploy GraphQL APIs, you need to configure the graphql array in your sanity.cli.ts (or sanity.cli.js) file. This tells the CLI which workspaces should have GraphQL APIs deployed.
Here's how to fix the error:
In your sanity.cli.ts file, add a graphql array that maps to your workspaces:
import { defineCliConfig } from 'sanity/cli'
export default defineCliConfig({
api: {
projectId: 'your-project-id',
dataset: 'production'
},
graphql: [
{
id: "production",
workspace: "production", // matches workspace name in sanity.config.ts
},
{
id: "staging",
workspace: "staging", // matches workspace name in sanity.config.ts
}
]
})Key points:
- The
workspaceproperty in each GraphQL config object must match the workspace names you've defined in yoursanity.config.tsfile - The
idproperty lets you identify each GraphQL API when deploying
Deploying your GraphQL APIs:
Once configured, you can deploy GraphQL APIs in these ways:
# Deploy all GraphQL APIs
sanity graphql deploy
# Deploy only a specific API by its ID
sanity graphql deploy --api productionMake sure your workspace configurations are consistent between sanity.config.ts (where you define the workspaces) and sanity.cli.ts (where you configure the GraphQL APIs). The workspace names must match exactly for the CLI to properly associate each GraphQL API with its corresponding workspace.
You can find more details in the GraphQL documentation and the CLI GraphQL reference.
Show original thread2 replies
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.