gatsby-source-microcms icon indicating copy to clipboard operation
gatsby-source-microcms copied to clipboard

未入力のフィールドがある場合にビルドエラーが起きる

Open shibe97 opened this issue 4 years ago • 2 comments

概要

microCMSのフィールドとして定義しているが、入稿画面で未入力のデータがあるとビルドエラーが起きる場合がある

リスト形式の場合

特定のフィールドがリスト内で全て存在していない場合にエラーが発生する

オブジェクト形式の場合

特定のフィールドが存在していない場合にエラーが発生する

shibe97 avatar Jul 07 '20 05:07 shibe97

他のヘッドレスCMSプラグインでも同様の問題が起きている。 https://github.com/gatsbyjs/gatsby/issues/2392

shibe97 avatar Jul 07 '20 05:07 shibe97

gatsby-node.jsにて下記のようにスキーマのデフォルト定義を行うことで回避ができる。

例:gatsbyobjectAPIにて、title, imageを任意設定にしたい場合

exports.createSchemaCustomization = ({ actions }) => {
  const { createTypes } = actions
  const typeDefs = `
    type MicrocmsGatsbyobject implements Node {
      title: String
      image: Image
    }
    type Image {
      url: String
    }
  `
  createTypes(typeDefs)
}

shibe97 avatar Jul 07 '20 06:07 shibe97