Error deploying GraphQL API in Sanity v3 with --dataset and --tag flags
sanity graphql deploy --dataset test --tag default$ sanity graphql deploy --dataset test --tag default
WARN: More than one API defined, and --dataset/--tag is specified
WARN: This will use the specified flag for ALL APIs!
? Continue with flag override for all APIs? Yes
Error: Multiple GraphQL APIs with the same dataset and tag found (test/default)
at Object.deployGraphQLApiAction [as default] (~/veri/narrative-content/node_modules/sanity/lib/_chunks/deployApiAction-6e38bde5.js:1555:13)export default defineCliConfig({
api: {
projectId: "xxxxxx",
},
graphql: [
{
workspace: "production",
},
{
workspace: "test",
},
],
});export default defineConfig([
{
name: "test", // Identifier used to reference configuration
title: "test", // Name displayed in Sanity studio dropdown
projectId: "xxxxxx",
default: true, // Which config to open by default in Sanity studio
dataset: "test",
basePath: "/test", // URL path
plugins: [deskTool(), media(), muxInput({ mp4_support: "standard" })],
schema: {
types: schemaTypes,
},
},
{
name: "production", // Identifier used to reference configuration
title: "production", // Name displayed in Sanity studio dropdown
projectId: "xxxxxx",
dataset: "production",
basePath: "/production", // URL path
plugins: [deskTool(), media(), muxInput({ mp4_support: "standard" })],
schema: {
types: schemaTypes,
},
},
]);When I run
$ sanity graphql deploy --helpit only lists
--dry-run
--forceand
--apias options. Is
--datasetand
--tagno longer supported from cli?
Running
sanity graphql deployfirst prompts me to deploy
productionand then
testand this way deploying works just fine. I’d just like to specify as arguments which env I want to deploy.
Based on your configuration, you're running into this issue because in Sanity v3, the way you specify which GraphQL API to deploy has changed. The --dataset and --tag flags still exist but they're causing conflicts when you have multiple workspace-based GraphQL API configurations.
The solution is to use the --api flag instead, which is the v3 way of targeting specific GraphQL deployments when you have multiple workspaces configured.
In your sanity.cli.ts, you've defined two GraphQL APIs based on workspaces:
graphql: [
{
workspace: "production",
},
{
workspace: "test",
},
]However, these configurations need explicit IDs to be targetable. Update your sanity.cli.ts to include id properties:
export default defineCliConfig({
api: {
projectId: "xxxxxx",
},
graphql: [
{
id: "production-api",
workspace: "production",
},
{
id: "test-api",
workspace: "test",
},
],
});Now you can deploy specific APIs using:
sanity graphql deploy --api test-apior
sanity graphql deploy --api production-apiThe reason --dataset and --tag are causing errors is that when you have workspace-based configurations, each workspace already maps to its corresponding dataset from your sanity.config.ts. Using --dataset and --tag tries to override this for ALL APIs, which creates duplicate configurations for the same dataset/tag combination - hence the error "Multiple GraphQL APIs with the same dataset and tag found (test/default)".
As you discovered, running sanity graphql deploy without flags works because it prompts you interactively for each workspace. But using the --api flag with explicit IDs gives you the programmatic control you're looking for while respecting the workspace-based configuration pattern in v3.
The CLI GraphQL documentation confirms that --api <api-id> is the recommended approach for deploying specific APIs in multi-workspace setups.
Show original thread2 replies
Was this answer helpful?
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.