System Information
- Strapi Version: 4.1.9
- Operating System: Windows 10
- Database: SQLite
- Node Version: 16.14.0
- NPM Version: 8.6.0
I’ve been trying to get a Gatsby website to work with Strapi as backend. I’m having issues with making it possible to have optinal data. In Strapi I’ve set a field for an image which could be left empty. When there is an image everything is fine and I can access the image url from Gatsby using a GraphQL query.
However if the image is empty Gatsby shows an error. I tried creating a type in gatsby-node.js
, but can’t seem to do it properly. Either the query gets the data from Strapi, but if there is no data it gives me an error. Or when I try the code below the query always returns null
even if there is an image added in Strapi, but it also doesn’t give an error when there is no image.
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions;
const typeDefs = `
type STRAPI_HOME_PAGE implements Node {
aboutSectionImage: STRAPI__MEDIA
}
`;
createTypes(typeDefs);
};
What is the correct way of adding a type definition, so the query returns the image url when there is one, but if there isn’t an image returns null
?