Merging Sanity GraphQL schema with Hasura remote schemas

2 replies
Last updated: Dec 17, 2020
Hello,I have a question about using sanity with Hasura (
https://hasura.io/ )I want to have users and other data in Hasura and content like e.g blog posts in sanity so I can manage. Hasura has a thing called remote schemas that will merge your remote schema with the GraphQL engine’s auto-generated schema. But I wasn’t able to figure it out because I didn’t find a single graphql endpoint in docs to merge it with Hasura. Is this even possible or have anyone experience with something like this? This is possible with contentful so I guess it should be with sanity as well (
https://www.contentful.com/blog/2020/09/17/combining-contentful-graphql-postgres-hasura/ )
AI Update

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 deploy

This 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 (usually production)
  • The <tag> defaults to default unless 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:

  1. Go to your Hasura Console
  2. Navigate to the "Remote Schemas" tab
  3. 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 thread
2 replies
You need to use the CLI to generate a GraphQL endpoint for your project: https://www.sanity.io/docs/graphql
When you do it will ouput the endpoint URL that you can add to the Hasura instance.
👍
Thank you, this was it 🙂

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?