Javascript GraphQL数据到对象

Javascript GraphQL数据到对象,javascript,reactjs,graphql,Javascript,Reactjs,Graphql,我使用GraphQL查询数据以获得一些图像。我尝试将输出作为一个对象来获取,这样就可以使用图像名称作为键将其传递给Image src。我成功地将其映射到数组,然后使用以下方法将其转换为数组: const data = useStaticQuery(graphql` query Draft { allFile(filter: { sourceInstanceName: { eq: "featuredProducts" } }) { edges {

我使用GraphQL查询数据以获得一些图像。我尝试将输出作为一个对象来获取,这样就可以使用图像名称作为键将其传递给Image src。我成功地将其映射到数组,然后使用以下方法将其转换为数组:

const data = useStaticQuery(graphql`
    query Draft {
      allFile(filter: { sourceInstanceName: { eq: "featuredProducts" } }) {
        edges {
          node {
            childImageSharp {
              fixed(width: 500, quality: 100) {
                ...GatsbyImageSharpFixed
                originalName
              }
            }
            name
          }
        }
      }
    }
  `)
我觉得有点太多了。在现代JS(ES2019+)中,我是否可以不通过这两个步骤获得最终对象?

您可以使用:


这仍然返回数组吗<代码>[“0”,“bilia”,“originalName:“bilia.png”}]],[“1”,“Superlono”,“originalName:“Superlono.png”}]]这里我想要的是一个对象
{“bilia:“bilia.png”}
@IanTran抱歉,排错了。
const images = data.allFile.edges.map(image => ({
    [image.node.name]: image.node.childImageSharp.fixed,
  }))

  const arrayToObject = array => {
    return Object.assign({}, ...array)
  }

  const FeaturedProducts = arrayToObject(images)
const featuredProducts = Object.fromEntries(data.allFile.edges.map(edge => {
  const image = edge.node;
  return [image.name, image.childImageSharp.fixed],
}));