【发布时间】:2020-12-22 18:50:09
【问题描述】:
我正在使用 Next Js 构建我的网站 在我的 Index.js 文件中我写的地方
export async function getStaticProps() {
const res = await fetch('https://localhost:3000/api/v1/datas' ,{headers: {"Authorization": "secret","Content-Type" => "application/json"}})
let data = await res.json()
}
但我想调用 Graphql 而不是这个
{
"query": "query getDataById($dataId: ID) {
getDataById(dataId: $dataId) {
id
url
category {
name
id
__typename
}
}
}",
"variables": {
"dataId": "123"
}
}
谁能建议我如何在我的 getStaticProps() 方法中调用 nextjs 中的 Graphql 而不是调用 API。
【问题讨论】: