Contentful与Netlify构建时GraphQL字段子字段缺失报错求助
解决Netlify构建时的GraphQL错误问题
错误信息
构建过程中出现以下GraphQL错误:
GraphQLError: Field "jsonLdAnswer2" of type "contentfulTechnologyJsonLdAnswer2 TextNode" must have a selection of subfields. Did you mean "jsonLdAnswer2 { ... }"?
问题背景
该错误出现在添加一段Product类型的结构化数据之后,新增的结构化数据代码如下:
{ '@type': 'Product', name: 'Okta Lifecycle Management', operatingSystem: "cloud software as a services", applicationCategory: "SecurityApplication", applicationSuite: "Okta Lifecycle management is a required product for Okta with Universal directory", softwareHelp: "deployment consulting and set up support", url: 'https://ironcovesolutions.com/technology/okta/', description: 'Okta Lifecycle Managment for speedy on and off deployment of users to cloud applicaitons', keywords: "okta, lcm, cloud, sign on, life, cycle, managment, users,onboard, quick", brand: { '@type': 'Brand', name: 'Okta', }, offers: { '@type': 'Offer', url: 'https://ironcovesolutions.com/pricing/okta-product-price-sso-mfa-ud-amfa-sso/', priceCurrency: 'USD', price: '6.00', priceValidUntil: '2023-12-31', availability: 'https://schema.org/InStock', itemCondition: 'https://schema.org/NewCondition', }, },
解决方法
- 找到项目中请求
jsonLdAnswer2字段的GraphQL查询语句 - 原查询大概率直接写了
jsonLdAnswer2,没有指定子字段。GraphQL要求非标量类型的字段必须明确选择子字段,不能直接请求整个字段 - 根据Contentful里该字段的实际定义,修改查询为选择具体子字段。比如如果是文本节点类型,通常要写成:
jsonLdAnswer2 { text # 按需添加其他子字段,比如nodeType等 } - 保存修改后重新触发Netlify构建
内容的提问来源于stack exchange,提问作者ironcove
相关产品推荐
相关产品推荐

