Sorry, no results found for "".

Content Delivery API > Modular content fields

Modular content fields

If you have Modular Content fields, you can use GraphQL fragments to fetch information about all their embedded blocks.

Suppose a blog_post model has a modular content field called content, which in turn accepts the following block models:

  • Block blog_post_text_block: made of a text field (multi-paragraph text);

  • Block blog_post_quote_block: made of a quote field (multi-paragraph text) and author field (single-line string);

  • Block blog_post_gallery_block: made of a gallery field (image gallery);

This GraphQL query will do the work:

query {
allBlogPosts {
title
content {
... on BlogPostTextBlockRecord {
id
_modelApiKey
text
}
... on BlogPostQuoteBlockRecord {
id
_modelApiKey
quote
author
}
... on BlogPostGalleryBlockRecord {
id
_modelApiKey
gallery { url }
}
}
}
}

Since all records implement the GraphQL interface RecordInterface, you can dry up the same query like this:

query {
allBlogPosts {
title
content {
... on RecordInterface {
id
_modelApiKey
}
... on BlogPostTextBlockRecord {
text
}
... on BlogPostQuoteBlockRecord {
quote
author
}
... on BlogPostGalleryBlockRecord {
gallery { url }
}
}
}
}

The outcome of this query hinges on the type of Modular Content field. If we're dealing with the Multiple Blocks variant, it'll return an array of blocks. However, if we're working with the Single Block variant, it'll simply return one block, or null if it's absent.

Filtering records by contained blocks

If you need to filter records based on the content within their embedded blocks, please refer to the Deep filtering section of this guide, where this scenario is explained in detail.