2

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!

BigglesZX
  • 958
  • 1
  • 12
  • 27

1 Answers1

1

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.

cfm
  • 156
  • 1
  • 2
  • 12
  • 1
    Thanks – some research since posting the question bears this out. A complete datastore export (via API endpoint or CLI) can contain what Sanity refers to as "system documents" but these appear to be limited to data such as plugin config. – BigglesZX Feb 15 '21 at 13:30