UNPKG

sanity

Version:

Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches

18 lines (14 loc) 539 B
import {type SanityClient} from '@sanity/client' import {DEFAULT_STUDIO_CLIENT_OPTIONS, getPublishedId, type SourceClientOptions} from 'sanity' export async function resolveTypeForDocument( getClient: (options: SourceClientOptions) => SanityClient, id: string, ): Promise<string | undefined> { const query = '*[sanity::versionOf($publishedId)][0]._type' const type = await getClient(DEFAULT_STUDIO_CLIENT_OPTIONS).fetch( query, {publishedId: getPublishedId(id)}, {tag: 'structure.resolve-type'}, ) return type }