【问题标题】:Gatsby StaticQuery Not Returning A ValueGatsby StaticQuery 不返回值
【发布时间】:2020-12-06 17:52:00
【问题描述】:

在我的 index.js 上,我想展示一些组件,每个组件都有自己的查询等。我正在使用 Gatsby 的静态查询文档页面中的代码。但是,根本没有任何东西被退回。在构建开发包或在控制台中,我没有收到任何错误。谁能看看我做错了什么?

import React from "react"
import { StaticQuery, graphql } from "gatsby"

export default function Segment() {
return (
    <StaticQuery
        query={graphql`
            query {
                allSanityProduct(limit:1) {
                    edges {
                        node {
                            productName
                        }
                    }
                }
            }
        `}
        render={data => (
            <header>
                <h1>{data.allSanityProduct.edges.productName}</h1>
            </header>
        )}
    />
)
}

非常感谢任何帮助。

【问题讨论】:

  • 恕我直言,按预期工作,未定义任何内容...错误的数据路径/选择器

标签: graphql gatsby


【解决方案1】:

正确的数据路径应该是:

data.allSanityProduct.edges[0].node.productName

【讨论】:

    猜你喜欢
    • 2021-04-05
    • 2020-11-12
    • 2023-03-25
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 2020-03-13
    • 2019-11-04
    • 2020-10-14
    相关资源
    最近更新 更多