-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow invalid source data by making gatsbyImageData nullable (#218
) When sourcing data every sourced item might _not_ be be valid. Instead of stopping the build an error will be logged. Make sure to check if `gatsbyImageData` is not null before using in the `GatsbyImage` component. Closes #214
- Loading branch information
Showing
6 changed files
with
129 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import { graphql, useStaticQuery } from 'gatsby'; | ||
import { GatsbyImage, getImage } from 'gatsby-plugin-image'; | ||
|
||
const ProblemExample = () => { | ||
const data = useStaticQuery(graphql` | ||
query { | ||
allSomeBadImageData { | ||
nodes { | ||
name | ||
gatsbyImageData(height: 200) | ||
} | ||
} | ||
} | ||
`); | ||
|
||
return data.allSomeBadImageData.nodes.map((node, index) => { | ||
const gatsbyImage = getImage(node); | ||
|
||
if (gatsbyImage) { | ||
return <GatsbyImage key={index} image={gatsbyImage} alt={node.name} />; | ||
} else { | ||
return <div>No image for node with name: {node.name}</div>; | ||
} | ||
}); | ||
}; | ||
|
||
export default ProblemExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters