sanitygroq

Is it possible to query document schema metadata in Sanity/GROQ?


I have a simple singleton document schema defined in my Sanity/NextJS project, to model my "Colophon" page (richText is a custom block field type):

export default {
    title: 'Colophon',
    name: 'colophon',
    type: 'document',
    __experimental_actions: ['update', 'publish'],
    fields: [
        {
            title: 'Body',
            name: 'body',
            type: 'richText',
            validation: Rule => Rule.required(),
        },
    ],
};

I retrieve this document with a simple query in my NextJS application:

export async function getStaticProps() {
    const colophon = await client.fetch(`
        *[_type == "colophon"][0]
    `);
    // ...
};

Is it possible to write a GROQ query to retrieve the meta title defined in the schema, i.e. Colophon? Although this is a singleton document, I would like to avoid repeating this string in my project if possible. At the moment, I can only see the fields on the document in my results, i.e. body.

Thanks for reading!


Solution

  • No, I don't believe there is.

    As far as I understand what you're after; The schema is defined in the studio-instance and not the datastore. Those two are not hard coupled. I have several studio-instances with small variations on the schemas using one single project/datastore. The API you query to get data does not care which studio and schema was used and cant answer for the actual schema details.