如何使用sanity.io和gatsby与gatsby source sanity中的内部链接?
我已经按照sanity文档创建了一个internalLink类型,并且根据关于将internalLink与graphql api一起使用的gotcha说明,我已经将其创建为一个单独的类型,如下所示:如何使用sanity.io和gatsby与gatsby source sanity中的内部链接?,gatsby,sanity,Gatsby,Sanity,我已经按照sanity文档创建了一个internalLink类型,并且根据关于将internalLink与graphql api一起使用的gotcha说明,我已经将其创建为一个单独的类型,如下所示: export default { name: 'internalLink', type: 'object', title: 'Internal link', fields: [ { name: 'reference', ty
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
]
}
]
}
import internalLink from './internalLink'
export default createSchema({
name: 'default',
types: schemaTypes.concat([
internalLink,
helpTopic,
blockContent,
figure,
slideshow,
])
})
annotations: [
{
type: 'internalLink'
}
]
我添加了它schema.js,如下所示:
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
]
}
]
}
import internalLink from './internalLink'
export default createSchema({
name: 'default',
types: schemaTypes.concat([
internalLink,
helpTopic,
blockContent,
figure,
slideshow,
])
})
annotations: [
{
type: 'internalLink'
}
]
并将其添加到注释中,如下所示:
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
]
}
]
}
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"
}
}
]
但是,当我使用\u rawBody(resolverences:{maxDepth:1000})
时,引用不会得到解析并返回为null:
"markDefs": [
{
"_key": "00a07e239d3d",
"_type": "internalLink",
"reference": null
}
]
这是一个bug还是我做错了什么。我已经试着浏览了这些文档,但没有弄清楚这一点,而且示例gatsby sanity combo项目没有internalLinks示例
提前感谢您的帮助。到目前为止,批注不能接受这样的模式类型。您必须将整个模式块放在其中。有点奇怪的限制。我想已经有人在Sanity.io的Github repo上提交了关于此问题的通知单/功能请求。更改架构后是否部署了GraphQL端点?每次更改架构时,您都必须运行
sanitygraphql deploy
。可能存在一些不匹配,从而导致null
。只是想确保在深入研究之前。是的,我确实运行了sanity graphql deploy
,并在操场上检查了它是否具有正确ID的引用属性。似乎是解析引用给了我错误。感谢您的回复,希望您能深入了解可能出现的错误。嘿,您找到办法了吗?我在github页面上为gatsby source sanity发布了一个问题,他们已经回复了一个测试版()中的潜在修复方案。我已经被其他项目转移,所以还没有机会检查,但请尝试gatsby源代码-sanity@6.0.0-beta.0
,如果这对YouTunks Sharon很重要,请向他们提供反馈。然而,我实际上是这样做的——将整个模式块作为匿名类型放在注释中。但也有同样的问题。然后,我在sanitydocs()中遵循了这个链接,并尝试了上面所示的模式类型。文档中的注释:“如果您计划使用Sanity的GraphQLAPI,您应该将internalLink作为模式类型,并使用类型:'internalLink'作为注释,而不是上面示例中的匿名对象。”