Skip to main content
GROQ (Graph-Relational Object Queries) is Sanity’s query language. All content fetching in the Astro app goes through GROQ queries defined in astro-app/src/lib/sanity.ts.

defineQuery pattern

Every query is wrapped with defineQuery from the groq package. This enables Sanity TypeGen to extract the query’s return type automatically and write it to sanity.types.ts.
The TypeGen-generated return type ALL_SPONSORS_QUERY_RESULT is imported in the same file and used wherever the query result is typed:

How queries are used at build time

The Astro app uses a static build by default. Queries run at build time inside getStaticPaths or in the page frontmatter:
  1. getStaticPaths calls slug-listing queries (e.g. ALL_PAGE_SLUGS_QUERY) to enumerate all routes.
  2. prefetchPages() batch-fetches all page data in parallel (6 at a time) and caches it in a module-level Map.
  3. Per-page renders call helper functions (getPage, getAllSponsors, etc.) which return from the cache instantly.

getSiteParams() for multi-site filtering

Every query that targets site-aware document types includes a $site parameter. getSiteParams() returns the correct value for the current build:
  • On the production dataset: { site: '' } — the ($site == "" || site == $site) condition short-circuits on the empty string, so all documents match.
  • On the rwc dataset: { site: 'rwc-us' } or { site: 'rwc-intl' } — only documents belonging to the current site are returned.
SITE_ID and DATASET are resolved at build time from PUBLIC_SITE_ID and PUBLIC_SANITY_DATASET environment variables, which Vite statically replaces.

loadQuery() wrapper

All queries go through loadQuery() rather than calling sanityClient.fetch() directly. When Visual Editing is active, it switches to the drafts perspective, enables stega encoding, and accumulates sync tags for the Live Content API:

Named queries exported from sanity.ts

Helper functions

Cached helpers (getAllSponsors, etc.) bypass the cache and re-fetch when Visual Editing is enabled, so the preview always shows the latest draft data.