gpt4 book ai didi

javascript - Gatsby 节点错误 : "Must Provide Source" error being thrown

转载 作者:行者123 更新时间:2023-12-04 02:35:42 26 4
gpt4 key购买 nike

我在 Gatsby 中创建动态页面,从 Fauna 中提取数据。我在 gastby-node 中有一个查询抛出错误“必须提供源”,但该查询在 GraphiQL 中有效。我在下面包含了 gatsby-node.js。

exports.createPages = async function({actions, graphql}){
const {data} = await graphql`
query {
fauna {
allCompanies {
data {
slug
}
}
}
}
`

data.fauna.allCompanies.data.forEach(edge => {
const slug = edge.slug
actions.createPages({
path: slug,
component: require.resolve("./src/components/products.js"),
context:{
slug
},
})
})
}

最佳答案

今天我遇到了同样的错误,过了一段时间才弄清楚。一个愚蠢的错误。
graphql是一个需要以查询作为参数调用的函数 (graphql(`...`))。我把它误认为 graphql-tag我在 Apollo 中使用的gql`...`
这应该工作

exports.createPages = async function ({ actions, graphql }) {
/*
you have to pass the template literal query
in the function graphql(`...`)

*/
const { data } = await graphql(`
query {
fauna {
allCompanies {
data {
slug
}
}
}
}
`)

data.fauna.allCompanies.data.forEach(edge => {
const slug = edge.slug
actions.createPages({
path: slug,
component: require.resolve("./src/components/products.js"),
context: {
slug,
},
})
})
}


希望这可以帮助 !

关于javascript - Gatsby 节点错误 : "Must Provide Source" error being thrown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61980056/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com