【发布时间】:2020-08-18 13:56:00
【问题描述】:
我正在尝试为 Contentful 源添加 createSchemaCustomization,该源可能没有我感兴趣的字段,因此 Gatsby 无法推断类型。
我已经创建了自定义,这样我的模板查询就不会抱怨,但如果有一个条目,它也不会被拾取。我确定我可能没有正确设置自定义。这就是我所拥有的(@infer 标志似乎并没有起到多大作用):
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions;
const typeDefs = `
type ContentfulUniversalProduct implements Node @infer {
datesAndPricesSnippets: [DatesAndPricesSnippet]
}
type DatesAndPricesSnippet implements Node @infer {
id: String
title: String
icon: String
iconColor: String
body: WithChildMarkdownRemark
}
type WithChildMarkdownRemark implements Node @infer {
childMarkdownRemark: MarkdownRemark
}
`;
createTypes(typeDefs);
};
我的查询。
如果 Contentful 中有 datesAndPricesSnippets,并且我没有上述 schemaCustomization,则此查询有效。
如果我确实进行了自定义,则此查询的输出为 null - 无论内容是否为 Contentful。
export const query = graphql`
query($slug: String!, $id: String!) {
contentfulUniversalProduct {
datesAndPricesSnippets {
id
title
body {
childMarkdownRemark {
html
}
}
icon
iconColor
}
}
}
`
【问题讨论】: