Skip to content

Portable text / blocks not useful when used inside an array or object #37

@leighkendell

Description

@leighkendell

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions