I’ve created a new content type, id “jobPost”. I want to display content based on this in the Gatsby site but can’t get the graphQL to work for me. It’s not clear if what I’m trying is the way it’s supposed to be done. My content type structure is very close to the blog post type so I just replicated part of the qraphQL query and amended for my content type:
allContentfulJobPost(sort: { fields: [publishDate], order: DESC }) {
edges {
node {
title
slug
publishDate(formatString: "MMMM Do, YYYY")
tags
description {
childMarkdownRemark {
html
}
}
}
}
}
However, when I do this I get an error and the site doesn’t load:
TypeError: Cannot read property ‘0’ of undefined
RootIndex.render
src/pages/index.js:9
6 | import ArticlePreview from '../components/article-preview'
7 |
8 | class RootIndex extends React.Component {
> 9 | render() {
10 | const siteTitle = get(this, 'props.data.site.siteMetadata.title')
11 | const posts = get(this, 'props.data.allContentfulBlogPost.edges')
12 | const [author] = get(this, 'props.data.allContentfulPerson.edges')
Should my approach work or am I missing something? Unfortunately the onboarding content talks about using the JS SDK and not graphQL so it’s not clear whether I’m doing the right thing.