[英]“Cannot read property 'page' of undefined” - Gatsby and Prismic creating pagination for template in gatsby-node
[英]ChildImageSharp is null after creating custom schema in gatsby-node
我正在用 gatsby 和 Strapi 建立一個網站,但我遇到了一個無法解決的問題。
這是我的問題:
我制作了一個自定義 graphQL 架構,以避免在我的客戶在 CMS 中留下空白字段時構建失敗。 但是因為我為我的主頁橫幅做了這個,childImageSharp 是 null。
我假設我的自定義 graphql 模式錯誤,但我不明白在哪里。
這是我的文件:
主頁.js
const IndexPage = ({ data }) => {
return (
<Layout>
{data.allStrapiBanner.edges[0].node.banner.childImageSharp.fixed &&
<Img
fixed={data.allStrapiBanner.edges[0].node.banner.childImageSharp.fixed}
imgStyle={{ position: "static" }}
/>
}
</Layout>
)
}
export default IndexPage
export const pageQuery = graphql`
allStrapiBanner {
edges {
node {
banner {
childImageSharp {
fixed(width: 800){
src
}
}
}
}
}
}
}
`
這是我的 gatsby-node.js 自定義架構:
exports.sourceNodes = ({ actions }) => {
const { createTypes } = actions
const typeDefs = `
type allStrapiBanner implements Node {
banner: childImageSharp
}
type childImageSharp{
childImageSharp: fixed
}
type fixed{
fixed(width: Int): src
}
type src{
src: String
}
`
createTypes(typeDefs)
}
現在,當我沒有將圖像上傳到橫幅字段時,蓋茨比構建沒有錯誤,但是當我上傳圖像時 childImageSharp 是 null
我已經閱讀了文檔( https://www.gatsbyjs.com/docs/reference/graphql-data-layer/schema-customization/ ),但我無法讓它工作。 如果有人可以給我一個提示,告訴我如何正確地為 childImageSharp 創建我的自定義模式。
非常感謝你提前
解決了
經過數小時的蠻力試圖了解出了什么問題,我終於解決了我的問題。 我不敢相信它是如此簡單:
我只是將 gastby-node.js 中的架構更改為
exports.sourceNodes = ({ actions }) => {
const { createTypes } = actions
const typeDefs = `
type allStrapiBanner implements Node {
banner: File
}
`
createTypes(typeDefs)
}
它工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.