Search code examples
reactjsmarkdowngraphqlcontentfulgatsby

GatsbyJS - How to query longtext Contentful fields in GraphQL


I ran into a problem querying a field of type "long text" from contentful.

I know the Contentful long text field is actually markdown. So I installed the gatsby-transformer-remark plugin, which I presumed I need.

Here's my GraphQL query:

  query getStoreById($relativeUrl: String!) {
    contentfulStore(relativeUrl: { eq: $relativeUrl }) {
      relativeUrl
      shopPageTitle
      mainPageTextContent {
        mainPageTextContent
      }
    }
  }

The console still shows:

Objects are not valid as a React child (found: object with keys {childMarkdownRemark}). 

Something to do with that error message.

Thanks!


Solution

  • The query will look something like:

    query getStoreById($relativeUrl: String!) { contentfulStore(relativeUrl: { eq: $relativeUrl }) { relativeUrl shopPageTitle mainPageTextContent { childMarkdownRemark { html } } } }

    If you haven't learned how to use GraphiQL yet, try opening it at localhost:8000/___graphql! It's your best friend for learning how to query your Contentful schema.