如何在reactJS中映射嵌套的graphQL查询

时间:2020-10-31 22:52:02

标签: reactjs graphql wp-graphql

我想从此响应中显示FeaturedImage-> mediaItemUrl,我能够映射authorId和标题,但如何获取图像的媒体URL

const ALL_BLOGS = gql`
 {
  posts(last: 10) {
    nodes {
      authorId
      guid
      title
      commentCount
      commentStatus
      author {
        node {
          name
        }
      }
      date
      pinged
      uri
      featuredImage {
        node {
          mediaItemUrl
        }
      }
    }
  }
}

这是ReactJS代码The code snippet

1 个答案:

答案 0 :(得分:0)

在您的代码段中,好像您忘记将node放在mediaItemUrl之前

{data.blog.featuredImage.map(featuredImage => (
             <li key={featuredImage.node>
                  <h2>{featuredImage.node.mediaItemUrl}</h2>
             </li>
))}