GraphQL Query and Gatsby - Populating Author Bio Raw Text
4 replies
Last updated: Apr 22, 2022
T
Hello, I am struggling to get the author bio raw text to populate return from my blog post template query. Query looks like this:
And the error I’m getting is:
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!
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 } } } } `;
There was an error in your GraphQL query: Field "bio" of type "[SanityBlock]" must have a selection of subfields. Did you mean "bio { ... }"?
Apr 22, 2022, 12:30 AM
T
Sure, thank you! I believe it's this: https://kyxjcfj0.api.sanity.io/v1/graphql/production/default
Apr 22, 2022, 12:49 AM
OK, so I was able to access the bio on the field
bioRawhere . You won't be able to use any of the
_rawfields in the playground since those are generated by Gatsby when you use gatsby-source-sanity. Do you have a
_rawBioin your Gatsby data layer somewhere?
Apr 22, 2022, 1:06 AM
T
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.