gatsby-uc / gatsby-source-strapi

Gatsby source plugin for building websites using Strapi as a data source
MIT License
354 stars 182 forks source link

Cannot query richText when empty #326

Closed Mrowa96 closed 2 years ago

Mrowa96 commented 2 years ago

Info:

When I try to query richText field (not required) from a component (requied) which has "" as a value, my build fails, because schema doesn't recognise this field as a richText. Instead it recognise it as a String.

image

On top of that if richText value equals null my whole strapi query response is equal to null. RichText may have null value when user creates new entity and doesn't fill richText with anything immediately.

Broken response looks like this:

{
  "data": {
    "strapiView": null
  },
  "extensions": {
    "enableRefresh": "true"
  }
}

Example:

I have this structure in Strapi:

image

My query looks like this:

query MyQuery {
  strapiView {
    name
    seoSectionText {
      enable
      content {
        data {
          childMarkdownRemark {
            html
          }
        }
      }
    }
  }
}

I have also defined custom types to handle situation when whole strapiView will be empty:

type StrapiViewSeoSectionTextContentData implements Node @infer {
  childMarkdownRemark: MarkdownRemark
}

type StrapiViewSeoSectionTextContent {
  data: StrapiViewSeoSectionTextContentData
}

type StrapiViewSeoSectionText implements Node @infer {
  enable: Boolean
  content: StrapiViewSeoSectionTextContent
}

type StrapiView implements Node @infer {
  id: ID!
  name: String!
  seoSectionText: StrapiViewSeoSectionText
}

I created PR with fix for this issues, but I'm not sure if it won't break anything

325