【发布时间】:2020-06-27 10:58:42
【问题描述】:
我按照健全性文档创建了一个 internalLink 类型,并且根据关于将 internalLinks 与 graphql api 一起使用的问题说明,我将它创建为一个单独的类型,如下所示:
export default {
name: 'internalLink',
type: 'object',
title: 'Internal link',
fields: [
{
name: 'reference',
type: 'reference',
title: 'Reference',
to: [
{ type: 'helpTopic' },
// other types you may want to link to
]
}
]
}
我已经添加了 schema.js 如下:
import internalLink from './internalLink'
export default createSchema({
name: 'default',
types: schemaTypes.concat([
internalLink,
helpTopic,
blockContent,
figure,
slideshow,
])
})
并将其添加到注释中,如下所示:
annotations: [
{
type: 'internalLink'
}
]
当我在 Gatsby 中使用 graphiql 时,如果我不使用 resolveReferences,那么我会正确获取未解析的引用:
"markDefs": [
{
"_key": "00a07e239d3d",
"_type": "internalLink",
"reference": {
"_ref": "7c635eee-0d98-5335-a376-4101922ca4b7",
"_type": "reference"
}
}
]
但是,当我使用 _rawBody(resolveReferences:{maxDepth:1000}) 时,引用没有得到解析并返回为 null:
"markDefs": [
{
"_key": "00a07e239d3d",
"_type": "internalLink",
"reference": null
}
]
这是一个错误还是我做错了什么。我尝试过浏览文档,但无法弄清楚这一点,并且示例 gatsby sanity 组合项目没有 internalLinks 示例。
提前感谢您的帮助。
【问题讨论】:
-
您是否在更改架构后部署了 GraphQL 端点?每次更改架构时都必须运行
sanity graphql deploy。可能有一些不匹配导致它变成null。只是想在深入研究之前确保这一点。 -
是的,我确实运行了
sanity graphql deploy,并且我还在操场上检查了它确实具有具有正确 ID 的引用属性。似乎只是解决引用给了我错误。感谢您的回复,希望您能就可能的错误提供任何见解。 -
嘿,你找到方法了吗?
-
我在 github 页面上发布了一个关于 gatsby-source-sanity 的问题,他们已经回复了关于 beta 版本中的潜在修复 (github.com/sanity-io/gatsby-source-sanity/issues/60)。我一直忙于其他项目,所以还没有机会检查,但请尝试
gatsby-source-sanity@6.0.0-beta.0,如果对您很重要,请向他们提供反馈