👋 Next.js Conf 2024: Come build, party, run, and connect with us! See all events

Error deploying GraphQL API in Sanity v3 project

2 replies
Last updated: Dec 16, 2022
Hi, I’m trying to update v2 project to v3. So far going nicely, except when I run
sanity graphql deploy --dataset test --tag default
I get an error.

$ 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)
My sanity.cli.ts:

export default defineCliConfig({
  api: {
    projectId: "xxxxxx",
  },
  graphql: [
    {
      workspace: "production",
    },
    {
      workspace: "test",
    },
  ],
});
Sanity.config.ts

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 --help
it only lists
--dry-run
--force
and
--api
as options. Is
--dataset
and
--tag
no longer supported from cli?
Running
sanity graphql deploy
first prompts me to deploy
production
and then
test
and this way deploying works just fine. I’d just like to specify as arguments which env I want to deploy.
Dec 16, 2022, 8:27 AM
And Immediately I get it 🤦‍♂️
I need to define id for each graphQL api like this:

export default defineCliConfig({
  api: {
    projectId: "xxxxxx",
  },
  graphql: [
    {
      id: "production",
      workspace: "production",
    },
    {
      id: "test",
      workspace: "test",
    },
  ],
});
And then

yarn sanity graphql deploy --api test
Dec 16, 2022, 8:30 AM
$ yarn sanity graphql deploy --api test --tag moo
WARN: More than one API defined, and --tag is specified
WARN: This will use the specified flag for ALL APIs!
? Continue with flag override for all APIs? Yes
Deploying only specified APIs: test
⚠ Generating GraphQL API: test/moo
? Do you want to enable a GraphQL playground? Yes
✔ Generating GraphQL API: test/moo

Project: xxxxx
Dataset: test
Tag:   moo
URL:   <https://xt399tbr.api.sanity.io/v1/graphql/test/moo>
✔ Deployed!

:sparkles: Done in 38.58s.

I feel the message
This will use the specified flag for ALL APIs!
is maybe a bit misleading since it actually still only deployed one API which is the test api with tag default 🤔
Also the --tag property seems to be working still, but it’s not listed in options with
sanity deploy --help
Dec 16, 2022, 8:34 AM

Sanity– build remarkable experiences at scale

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

Was this answer helpful?