Watch a live product demo πŸ‘€ See how Sanity powers richer commerce experiences

GraphQL - Is there a Way to Get the Image Metadata From an Image Component?

10 replies
Last updated: Oct 29, 2021
Using GraphQL is there a way to get the Image metadata from an image component used inside the
block
type?
Oct 28, 2021, 5:44 PM
The schema generator will expose a
<your-type-name>Raw
field for your Portable Text, but in order to resolve references you need to use one of our source plugins for Gatsby or Gridsome .
Oct 28, 2021, 5:53 PM
For example, Gatsby source allows you to do the following:
{
  allSanityProject {
    edges {
      node {
        _rawTasks(resolveReferences: {maxDepth: 5})
      }
    }
  }
}
Oct 28, 2021, 5:53 PM
I have the basic
Raw
field, I'm using
Apollo
with
nextjs
. Previously i've looked into the
_raw
field but couldn't figure out how to use it in this stack.
Oct 28, 2021, 5:54 PM
Got it. You unfortunately can't pass the
resolveReferences
argument unless you're using one of those source plugins.
Oct 28, 2021, 5:55 PM
So the answer my initial question in the context of my stack (sorry i should have said it in the ticket), it's a no? πŸ˜“
Oct 28, 2021, 5:56 PM
Yeah, it's a no 😞 . But since you're using a Next frontend, have you considered making a change over to using GROQ as your query language? It has a much more intuitive way of handling references within Portable Text.
Oct 28, 2021, 5:58 PM
yeah in hindsite it would be better to do this. Are you able to create chunks of a GROQ call and stitch them? i.e one for each CMS module (we have a modular CMS)
Oct 28, 2021, 6:46 PM
GROQ queries are strings. You can concatenate them or use template literals with string interpolation. for example: https://gist.github.com/mornir/4905c0d9adaa8612d797f8e054764087
Oct 28, 2021, 6:52 PM
Yeah, the great thing about GROQ is that you can stitch information together across any document in your dataset. There's a really good intro here . It's only simple examples, but it'll give you a look at how powerful it is.
Oct 28, 2021, 8:52 PM
Thanks folks!
Oct 29, 2021, 8:43 AM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing