Queries Library
Queries LibraryDisplay the URLs from all image blocks in a post

Display the URLs from all image blocks in a post

This query fetches the data for all blocks in the post (including inner blocks) while filtering them by core/image type, and extracts the URL property from each.

query GetImageBlockImageURLs($postId: ID!) {
  post(by: { id: $postId }, status: any) {
    coreImageURLs: blockFlattenedDataItems(
      filterBy: { include: "core/image" }
    )
      @underEachArrayItem(
        passValueOnwardsAs: "blockDataItem"
      )
        @applyField(
          name: "_objectProperty"
          arguments: {
            object: $blockDataItem,
            by: {
              path: "attributes.url"
            }
          }
          setResultInResponse: true
        )
      @arrayUnique
  }
}