gatsby-source-contentful: if media is video or image, non-nullable field breaks build #20696
Labels
help wanted
Issue with a clear description that the community can help with.
status: confirmed
Issue with steps to reproduce the bug that’s been verified by at least one reviewer.
type: bug
An issue or pull request relating to a bug in Gatsby
Description
For the past months, I have been using Contentful and Gatsby successfully. Somehow, a couple of days ago, my build keeps breaking with the following error.
Context
I've set up a portfolio website, where each project has its own page. On this project page, I display videos and images about the project. To have a smooth workflow in Contentful, I've defined one content type
showcaseMedia
for all assets. Here you can uploadmedia
with some metadata and options. This uploaded asset can be both a video and an image.I call the following GraphQL query on the project page to access the data. The below query is simplified, the full query can be found here.
Later I differentiate if the media item is an image or video with the boolean
isVideo
. For an image, I will use theImg
component fromgatsby-image
, for displaying a video I use avideo
oriframe
element.Steps to reproduce
showcaseMedia
(or pick another name)showcaseMedia
an upload an imageshowcaseMedia
an upload a video here.showcaseMedia
items on one parent page, such a project post pageCannot return null for non-nullable field ContentfulFluid.aspectRatio.
and your code chunk where the error originates.Expected result
null
.nullable
fields should be done on the Frontend.Actual result
showcaseMedia
element. Therefore, the fluid field will returnnull
.gatsby-source-contentful
does not allownull
for certain fields on the fragmentContentfulFluid
.Problem origins
When removing
new GraphQLNonNull()
atfluidNodeType
located gatsby/packages/gatsby-source-contentful/src/extend-node-type.js, everything works as excepted.The following threads talk about the related/same problem.
#1517
#2881
#3344
Possible solutions
I can imagine some fields need to be NonNullable. So by just removing them, it will cause more problems in the future. That's why I thought about some solutions, but I am not able to get my head around what the correct solution will be.
null
value for the field typefluidNode
by setting an option ingatsby-config.js
ContentfulFluid
fragment ingatsby-node.js
I don't mind to make a PR to fix this matter, but I'd like to have some advice on
Environment
The text was updated successfully, but these errors were encountered: