Sanity GraphQL API
Sanity provides a GraphQL API for querying content.
Endpoint
https://[project-id].api.sanity.io/v2024-01-01/graphql/[dataset]/default
Deployment
Deploy the GraphQL API:
cd studio
npx sanity graphql deploy
Usage
The project uses Apollo Client to query Sanity:
import { apolloClient } from '@/lib/apollo-client'
import { GET_HERO_QUERY } from '@/lib/apollo-queries'
const { data } = await apolloClient.query({
query: GET_HERO_QUERY,
variables: { locale: 'en' }
})
Example Query
query GetHero($locale: String!) {
allHero(where: { locale: { eq: $locale } }) {
title
subtitle
cta {
label
url
}
}
}