✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

GraphQL Query and Gatsby - Populating Author Bio Raw Text

4 replies
Last updated: Apr 22, 2022
Hello, I am struggling to get the author bio raw text to populate return from my blog post template query. Query looks like this:
  query BlogPostTemplateQuery($id: String!) {
    post: sanityPost(id: { eq: $id }) {
      id
      publishedAt
      categories {
        _id
        title
      }
      mainImage {
        ...SanityImage
        alt
      }
      title
      slug {
        current
      }
      _rawExcerpt(resolveReferences: { maxDepth: 5 })
      _rawBody(resolveReferences: { maxDepth: 5 })
      authors {
        _key
        author {
          image {
            crop {
              _key
              _type
              top
              bottom
              left
              right
            }
            hotspot {
              _key
              _type
              x
              y
              height
              width
            }
            asset {
              _id
            }
          }
          name
          bio 
        }
      }
    }
  }
`;
And the error I’m getting is:

There was an error in your GraphQL query:

Field "bio" of type "[SanityBlock]" must have a selection of subfields. Did you mean "bio { ... }"?
But I cannot find any of the fields that are defined for ‘bio’ in any documentation. In the GraphQL playground, these are bioRaw and return an array of objects but none of the rawContent, rawBody, or raw Excerpt fields are working. Any help would be greatly appreciated!
Apr 22, 2022, 12:30 AM
Apr 22, 2022, 12:49 AM
Thanks! I'll give it a go!
Apr 22, 2022, 12:50 AM
OK, so I was able to access the bio on the field
bioRaw
here . You won't be able to use any of the
_raw
fields in the playground since those are generated by Gatsby when you use gatsby-source-sanity. Do you have a
_rawBio
in your Gatsby data layer somewhere?
Apr 22, 2022, 1:06 AM
So I got this working, thank you! I assume by data layer you just mean the query described in the component so Gatsby knows what data to bring in? I had it there but was never actually displaying that particular prop anywhere, thought the bio data would show up in the dev tools component inspector anyways so thought it wasn't being returned at all. Once I added an element to display it, it worked fine lol 🤷‍♂️ thanks again!
Apr 22, 2022, 6:55 PM

Sanity– build remarkable experiences at scale

Sanity is a 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.

Was this answer helpful?