FormidableLabs / groqd

A schema-unaware, runtime and type-safe query builder for GROQ.
https://commerce.nearform.com/open-source/groqd
MIT License
221 stars 17 forks source link

Cannot access "altText" inside images #243

Open ttavni opened 7 months ago

ttavni commented 7 months ago

I am using the sanityImage utility method and cannot access the altText which is an additional field. I'm not sure if there's be a change with sanity since the implementation but for example:

      image: sanityImage('image', {
        withAsset: ['base', 'lqip', 'dimensions'],
        additionalFields: {
          altText: q.string().nullable(),
        },
      })

It always returns null for the altText because the altText is inside asset. The only way I've got around this is

      image: sanityImage('image', {
        additionalFields: {
          asset: q('asset').deref(),
        },
        withAsset: ['base', 'lqip', 'dimensions'],
      }),

Which sort of defeats the point and ruins the types

carbonrobot commented 7 months ago

@ttavni Is your altText directly on the asset type and not as an extension of the image type or part of the asset metadata field?

Is it possible to post the schema of your image type?

ttavni commented 7 months ago

@carbonrobot yes that's correctly. I am using the Sanity Media plugin (https://github.com/sanity-io/sanity-plugin-media) so it is automatically adding those fields and it's directly on the asset type - nothing extra in my schema.

I didn't realise about adding custom fields on images, that makes the additionalFields make more sense now 😅 but it is nice to store the alt text for images globally instead of individually through the media plugin