gatsby-source-sanity: Portable text / blocks not useful when used inside an array or object

When querying for a block that resides within another object i.e. not at root level there doesn’t seem to be a way to get any useful information out of it.

Example query:

query MyQuery {
  sanityPage {
    modules {
      ... on SanityRichText {
        _key
        _type
        blocks {
          style
        }
      }
    }
  }
}

Most of the fields under “blocks” are null. The only way I’ve been able to get the content I need out of this particular example is by using _rawModules at the root level. This isn’t ideal since I’m already querying for each type of module using inline fragments and including the raw data is just doubling up on that and adding extra data I don’t want.

The official GraphQL API seems to allow outputting raw json at a nested level, I’ve confirmed this via the playground with the following query:

query {
  allPages {
    modules {
    	... on RichText {
        blocksRaw
      }
    }
  }
}

Is it possible to implement this same behaviour in the Gatsby plugin?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 20
  • Comments: 21 (3 by maintainers)

Most upvoted comments

any update here?

Hi! I just released a new beta version with a fix for this - it has a few breaking changes, however. Try it out: npm install gatsby-source-sanity@6.0.0-beta.0

I also can’t think of a workaround other than creating documents for any usage of blockContent. Definitely suboptimal considering the experience this brings for editors and the unintuitiveness of having to rediscover this for new devs coming in.

So seconding this should be a priority.

Thanks for reporting! We’ll take a closer look at this very soon.

Hi all! Sorry that we haven’t gotten around to sorting this out yet, it’s on our roadmap of things to get to, but we can’t give an ETA at the moment.

Workaround for this is make your object a document for now. Not ideal

I’m trying out Sanity for the first time and also hit this bug. This seems to be a pretty common scenario and fixing it should probably be prioritised, no?

I’ve run into the same issue, and in my case I have a nested object that has an array of blocks for content, and the _raw{FieldName} key is not available like it is at the top level.