【发布时间】:2021-05-09 16:58:42
【问题描述】:
我正在尝试在 Contentful 的富文本字段中查询图像。我的查询应该是什么样的?这是我的查询:
query {allContentfulBlogPost (
sort: {
fields: publishedDate,
order: DESC
}){
edges {
node {
title
slug
publishedDate(formatString: "MMMM Do, YYYY")
body {
raw
references {
... on ContentfulAsset {
contentful_id
fixed(width: 1600) {
width
height
src
srcSet
}
}
}
}
}
}
} }
这是我编辑器中的代码。图像不会显示。
const Blog = (props) => { const options = {
renderNode: {
"embedded-asset-block": (node) => {
const alt = node.data.target.fields.title["en-US"]
const url = node.target.sys.id.references.fixed.src
return <img alt={alt} src={url} />
}
}
} 这是我查询的原始数据响应:
"raw": "{\"nodeType\":\"document\",\"data\":{},\"content\":[{\"nodeType\":\"paragraph\",\"content\":[{\"nodeType\":\"text\",\"value\":\"Here is a recipe for chewy chocolate chip cookies.\",\"marks\":[],\"data\":{}}],\"data\":{}},{\"nodeType\":\"embedded-asset-block\",\"content\":[],\"data\":{\"target\":{\"sys\":{\"id\":\"3eIIsGhe0e1my0IRJtstRp\",\"type\":\"Link\",\"linkType\":\"Asset\"}}}},{\"nodeType\":\"paragraph\",\"content\":[{\"nodeType\":\"text\",\"value\":\"\",\"marks\":[],\"data\":{}}],\"data\":{}}]}",
【问题讨论】:
标签: graphql gatsby contentful