How to automate Sanity GraphQL deploy in CircleCI without interactive prompts?
Great question! Let me help you with both parts of your CircleCI integration.
Making GraphQL Deploy Non-Interactive
For the GraphQL playground prompt, you can use the --playground or --no-playground flags to avoid the interactive question. In your CircleCI config, use:
sanity graphql deploy --dataset=staging --playground
sanity graphql deploy --dataset=prod --playgroundOr if you don't want the playground enabled:
sanity graphql deploy --dataset=staging --no-playground
sanity graphql deploy --dataset=prod --no-playgroundAccording to the CLI documentation, the command supports these flags:
--playground- Deploy with the GraphQL playground interface--no-playground- Deploy without the playground--dataset <name>- Specify which dataset to deploy for--force- Deploy without confirming breaking changes (useful for CI)
Authentication in CircleCI
For authentication in your CI environment, you'll need to set up a Sanity auth token as an environment variable. Create a token in your Sanity project settings and add it as SANITY_AUTH_TOKEN in your CircleCI environment variables. The CLI will automatically pick this up and won't prompt for login.
Comparing Datasets and Slack Notifications
For comparing datasets between staging and prod and sending Slack notifications, I'd strongly recommend using Sanity Functions rather than traditional webhooks. Functions are serverless compute that run directly on Sanity's infrastructure - no external hosting needed!
Here's why Functions are better for this:
- Native integration: They run on Sanity's infrastructure, no need to deploy separate services
- Event-driven: Automatically triggered on document changes (create, update, publish, delete)
- Easy setup: Deploy via CLI from a Blueprint configuration
- Built-in monitoring: Includes logging for debugging
You could set up a Function that:
- Triggers when documents are published in staging
- Compares the document with the prod dataset
- Sends a notification to Slack with the differences
Here's a basic example structure:
// In your sanity.blueprint.ts
export default defineBlueprint({
functions: [
defineFunction({
name: 'notify-on-publish',
trigger: 'document.publish',
handler: async (event, context) => {
// Compare datasets and send to Slack
const slackWebhook = process.env.SLACK_WEBHOOK_URL;
// Your comparison logic here
await fetch(slackWebhook, {
method: 'POST',
body: JSON.stringify({
text: `Changes detected: ${event.documentId}`
})
});
}
})
]
});If you need to stick with webhooks for some reason (like if you already have external infrastructure), you can configure those in your Sanity project settings, but Functions are the modern, recommended approach for most automation tasks like this.
For your CircleCI workflow, you'd deploy both the GraphQL API and Functions as part of your pipeline:
- run: sanity graphql deploy --dataset=staging --playground --force - run: sanity graphql deploy --dataset=prod --playground --force - run: sanity blueprint deploy # Deploy your Functions
Hope this helps! Let me know if you need clarification on any part.
Show original thread1 reply
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.