How to configure multiple workspaces in Sanity v3 with GraphQL APIs?

2 replies
Last updated: Mar 1, 2023
Hi everyone, please how do i resolve this
Error: Multiple workspaces/sources configured. You must define an array of GraphQL APIs in sanity/sanity.cli.ts and specify which workspace/source to use.
.
i'm trying to use multiple workspace in the version 3
AI Update

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 workspace property in each GraphQL config object must match the workspace names you've defined in your sanity.config.ts file
  • The id property 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 production

Make 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 thread
2 replies
You’ll need to define those workspaces inside of an array in you CLI config . Ex:
export default defineCliConfig({
  api: {
    projectId: "xxxxxx",
  },
  graphql: [
    {
      id: "production",
      workspace: "production",
    },
    {
      id: "dev",
      workspace: "dev",
    },
  ],
});
thanks 😊

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?