I'm trying to build a Type in my gatsby-node.js
file that supports an optional value. Which I think is done with [String!]!
.
How can I load the new Type that I've created inside gatsby-node.js
on home.js
?
gatsby-node.js:
const path = require('path');
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions;
const typeDefs = `
type markdownRemark implements Node {
frontmatter: Features
}
type Features {
title: [String!]!
description: [String!]!
}
`;
createTypes(typeDefs);
};
pages/home/home.js:
export const query = graphql`
query HomeQuery($path: String!) {
markdownRemark(frontmatter: { path: { eq: $path } }) {
html
frontmatter {
features {
title
description
}
}
}
}
`;
home.md:
---
path: "/"
features:
- title: Barns
description: Praesent commodo cursus magna vel scelerisque nisl consectetur et. Nullam id dolor id nibh ultricies vehicula ut id elit.
- title: Private Events
description: Praesent commodo cursus magna vel scelerisque nisl consectetur et. Nullam id dolor id nibh ultricies vehicula ut id elit.
- title: Food and Drinks
description: Praesent commodo cursus magna vel scelerisque nisl consectetur et. Nullam id dolor id nibh ultricies vehicula ut id elit.
- title: Spa
description: Praesent commodo cursus magna vel scelerisque nisl consectetur et. Nullam id dolor id nibh ultricies vehicula ut id elit.
---
This needs to work so that if the features
array inside home.md
's front matter is empty, then GraphQL doesn't throw an error.
Please don't tell me to always include at least one value in the array, because this isn't practical, my solution needs to support no values in my array.
I've spent two hours going through documentation/issues in circles trying to find a working solution, please can someone save me!