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.
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 insidegetStaticPaths or in the page frontmatter:
getStaticPathscalls slug-listing queries (e.g.ALL_PAGE_SLUGS_QUERY) to enumerate all routes.prefetchPages()batch-fetches all page data in parallel (6 at a time) and caches it in a module-levelMap.- 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
productiondataset:{ site: '' }— the($site == "" || site == $site)condition short-circuits on the empty string, so all documents match. - On the
rwcdataset:{ 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.