Have a gatsby blog to which I've added a cover image that is either an image (I want that to appear as a Gatsby Image) or mp4 (I want that to appear as html5 video).
The problem is, when I query this field (in my markdown posts, cover: x.mp4
or cover: x.jpg
), if it's an mp4 and it doesn't have a property of childImageSharp
(error: TypeError: Cannot read property 'fluid' of null
).
My query looks like this:
frontmatter {
date(formatString: "YYYY")
title
cover {
childImageSharp {
fluid(maxWidth: 900) {
...GatsbyImageSharpFluid_noBase64
...GatsbyImageSharpFluidLimitPresentationSize
}
}
}
}
so my goal is to have some kind of JSX like:
{post.frontmatter.cover.childImageSharp && (
<Img fluid={post.frontmatter.cover.childImageSharp.fluid} />
)}
{post.frontmatter.cover.childImageSharp ? '' : (
<video src={post.frontmatter.cover} />
)}
any ideas?