【问题标题】:Gatsby createTypes don't create localFile using FileGatsby createTypes 不使用 File 创建 localFile
【发布时间】:2022-01-09 00:29:06
【问题描述】:

当 graphql 中有一个为空的字段时,我在运行 Gatsby 时遇到了问题(在 cms 中,有时该字段为空,有时不是)。我设法通过 createTypes 添加 gatsby-node.js 来解决这个问题。不幸的是,就像使用字符串类型的文本工作正常一样,所以对于使用文件类型子字段 localFile 的照片没有创建。即使没有照片,我也需要 localFile 出现,与添加照片的方式相同。有谁知道如何解决这个问题。非常感谢您的帮助。

gatsby-node.js

exports.sourceNodes = ({ actions }) => {
 const { createTypes } = actions
 const typeDefs = ` type StrapiPageEstimateRealizations implements Node { 
     Title: String
     Description: String
     Img: File
} 

` 
createTypes(typeDefs) 
}

graphql when the photo field is empty

graphql when a picture is added in cms

【问题讨论】:

    标签: graphql gatsby strapi


    【解决方案1】:

    File 不是本机类型,因此根据上下文,您需要添加自定义类型。

    尝试定义您的自定义类型,例如:

    type LocalFile {
      localFile: File @link(from: "localFile___NODE")
    }
    

    然后:

     const typeDefs = ` type StrapiPageEstimateRealizations implements Node { 
         Title: String
         Description: String
         Img: LocalFile 
    } 
    

    有用的资源:

    【讨论】:

    • 谢谢,这对我很有用!
    猜你喜欢
    • 1970-01-01
    • 2020-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-29
    • 2021-04-01
    • 1970-01-01
    • 2020-07-25
    相关资源
    最近更新 更多