我正在尝试使用新的@fileByRelativePath解析器扩展的接口,以保持与v3的兼容性。
我正在为我的内容使用棱镜,以及gatsby-source-prismic v2。我在Prismic中有两种内容类型,并创建了接口,以便能够更容易地查询和映射主页索引。
以下是正在运行的(但使用已弃用的推断解析器)模式:
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
const typeDefs = `
interface indexPosts @nodeInterface {
id: ID!
uid: String!
data: Data!
type: String!
}
type Data {
title: Title!
date: Date!
featured: String!
featured_image: Featured_image!
body: Body!
}
type Title {
text: String!
}
type Featured_image {
localFile: File!
}
type Body {
html: String!
}
type PrismicGallery implements Node & indexPosts {
uid: String!
data: Data!
type: String!
}
type PrismicEssay implements Node & indexPosts {
uid: String!
data: Data!
type: String!
}
`
createTypes(typeDefs)
}问题出现在将@fileByRelativePath添加到Featured_image类型定义之后。这样做会在构建过程中给我一个错误:
"path“参数必须是字符串类型。接收的类型未定义”
考虑到我的图像是第三方托管的,我不确定如何提供必要的路径参数。我试着按照the end of this page上的简单指南来做,我怀疑这样做的方法可能是使用解析器或类型生成器,并使用‘源’来访问localFile及其父featured_image提供的url字段,但我搞不懂!
我使用gatsby-image和childImageSharp方便字段来呈现图像,如果这有什么不同的话!
发布于 2020-07-08 22:38:00
当我尝试使用@fileByRelativePath时,我遇到了完全相同的问题。我设法通过在包含File的type上使用@infer来解决我的问题。
试试这个:
type Featured_image @infer {
localFile: File!
}https://stackoverflow.com/questions/59836856
复制相似问题