#5

Contentful, Gatsby, and Markdown

2019-08-14

TAGS: graphqlgatsbycontentful

When adding this TIL feature to my website I hit a snag on build in gatsby-node.

The issue came because I'm bringing in data from local markdown files as well as the Contentful API. I have a markdown content type from Contentful that gets picked up by allMarkdownRemark. That would then try and access frontmatter that wasn't there. A quick filter in my GraphQL query allowed me to only bring in local files.

{
  allMarkdownRemark(
    filter: { fileAbsolutePath: { ne: null } }
  ) {
    edges {
      node {
        fields {
          slug
        }
        frontmatter {
          type
        }
      }
    }
  }
  allContentfulTil {
    edges {
      node {
        title
        number
      }
    }
  }
}