【问题标题】:Is there a way to createSchemaCustomization but only if the type is incorrect有没有办法创建SchemaCustomization,但前提是类型不正确
【发布时间】:2022-01-18 14:57:10
【问题描述】:
exports.createSchemaCustomization = ({ actions }) => {
  const { createTypes } = actions;
  const typeDefs = `
  type AirtableData implements Node {
    ${constants.claimsField}: [Airtable]
    ${constants.interruptsField}: [Airtable]
    ${constants.demographicsField}: [Airtable]
    ${constants.carouselsField}: [Airtable]
  }
`;

在上面的例子中,我是否可以只定义不正确类型的字段(例如字符串),而不是明确定义我的字段。我只想将默认值添加到我的架构(由插件创建)。当我的后端没有数据时,插件会生成不正确的类型,这会破坏我的所有查询并导致构建失败。如果我使用上述明确的策略......那么我的查询也将停止工作。我正在使用https://www.gatsbyjs.com/plugins/gatsby-source-airtable/,并且需要将其作为最后一步,以确保我的架构允许“不存在”的值。我该怎么办?

【问题讨论】:

    标签: gatsby gatsby-plugin


    【解决方案1】:

    AFAIK 不可能给同一个字段不同的类型,即有时是 String,有时是 Int.. 我认为你想要做的是使用联合类型:

    type MyUnionType = String | Int
    
    type Data implements Node {
      fieldName: [MyUnionType]
    }
    

    【讨论】:

      猜你喜欢
      • 2022-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多