我已经按照理智文档创建了一个内部链接类型,并且根据关于将内部链接与 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 组合项目没有内部链接示例。
感谢您提前提供的帮助。
最佳答案
到目前为止,注释不能接受这样的模式类型。您必须将整个架构 block 放在那里。有点奇怪的限制。我认为有人已经在 Sanity.io 的 Github 存储库上提出了有关此问题的票证/功能请求。
关于gatsby - 如何通过 gatsby-source-sanity 使用 sanity.io 和 gatsby 中的内部链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60704140/