Closed danoszz closed 4 years ago
Having this same issue! Such a really frustrating bug. I suggest people shouldn't clear their cache until this is resolved.
So the expectation is that the field fluid
must return null
when media is not an image:
{
media: {
fluid: null
}
}
But instead, it returns an object where all fields are null
:
{
media: {
fluid: {
aspectRatio: null,
// all other fields are null as well
}
}
}
It happens in fluid
resolver (and in fixed
too):
This was working in the past because all fields of ContentfulFluid
and ContentfulFixed
were nullable. This was changed in #20314
The good fix would be to check if the node is null in the resolver above and return null
vs object. Does anybody want to do a PR for this? Ideally, we should also have a test case for this.
@vladar This should be resolved via #20794 .
@danoszz, @daydream05 This fix has been published. Please let me know if it resolves your issues.
@ryanhefner yessir! Thanks for the quick fix 🏄♂️
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.
https://github.com/gatsbyjs/gatsby/issues/1517 https://github.com/gatsbyjs/gatsby/issues/2881 https://github.com/gatsbyjs/gatsby/issues/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