Merging Sanity GraphQL schema with Hasura remote schemas
Yes, this is absolutely possible! Sanity does provide a GraphQL endpoint that you can use with Hasura's remote schemas feature.
Getting Your Sanity GraphQL Endpoint
First, you need to deploy a GraphQL API for your Sanity project. From your Sanity Studio project folder, run:
sanity graphql deployThis will generate and deploy a GraphQL endpoint based on your Sanity schema. Your endpoint URL will follow this format:
https://<yourProjectId>.api.sanity.io/v2023-08-01/graphql/<dataset>/<tag>
- Replace
<yourProjectId>with your actual Sanity project ID - Replace
<dataset>with your dataset name (usuallyproduction) - The
<tag>defaults todefaultunless you specify otherwise
For production use with high traffic, you can use the CDN-cached version:
https://<yourProjectId>.apicdn.sanity.io/v2023-08-01/graphql/<dataset>/<tag>
Integrating with Hasura
Once you have your GraphQL endpoint, you can add it as a remote schema in Hasura:
- Go to your Hasura Console
- Navigate to the "Remote Schemas" tab
- Click "Add" and provide:
- A name for your remote schema (e.g., "sanity")
- Your Sanity GraphQL endpoint URL
- Any necessary headers (authentication tokens if your dataset requires them)
Important Considerations
Schema Updates: Remember that when you change your Sanity schema, you need to redeploy the GraphQL API by running sanity graphql deploy again. The endpoint doesn't automatically update.
Read-Only: Sanity's GraphQL API is currently read-only for queries. Mutations aren't supported through GraphQL, so you'll need to use Sanity's Mutation API for write operations.
Schema Compatibility: Sanity requires stricter schema definitions for GraphQL than it does for GROQ. You may need to move any "anonymous" object types to named, top-level types in your schema.
This setup should work similarly to how Contentful integrates with Hasura, allowing you to query your Sanity content alongside your Hasura data in unified GraphQL queries.
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.