1

I'm figuring out how to render standard long text, but having issues.

Please take a look at my query, that is working when ran in the graphQL playground.

{
  allContentfulArticle {
    nodes {
      title
      slug
      para {
        para
      }
    }
  }
}

Here is my article.js file

import React from "react"
import { graphql } from "gatsby"
 

const Article = props => (
  <div>
    <header>
      <h1>{props.data.site.siteMetadata.title}</h1>
    </header>

    <main>
      <h1>{props.data.contentfulArticle.title}</h1>
    </main>

    <footer>
    <p>{props.data.site.siteMetadata.author}</p>
    </footer>
  </div>
)

export default Article

export const query = graphql`
  query Article($id: String) {
    site {
      siteMetadata {
        title
        description
        author
      }
    }
    contentfulArticle(id: { eq: $id }) {
      title
      subtitle
      slug
      para {
        para
      }
    }
  }
`

The strange thing is that I can render the title easily which is a simialir content type - just short.

I can see my title, slug and other metadata fields being displayed on localhost, but not the para paragraph.

enter image description here

1 Answer 1

1

You are not rendering your long text field despite your GraphQL query looks perfect. Just use:

import React from "react"
import { graphql } from "gatsby"
 

const Article = props => (
  <div>
    <header>
      <h1>{props.data.site.siteMetadata.title}</h1>
    </header>

    <main>
      <h1>{props.data.contentfulArticle.title}</h1>
    </main>
    <p>Your long text is: {props.data.contentfulArticle.para.para}</p>
    <footer>
    <p>{props.data.site.siteMetadata.author}</p>
    </footer>
  </div>
)

export default Article

export const query = graphql`
  query Article($id: String) {
    site {
      siteMetadata {
        title
        description
        author
      }
    }
    contentfulArticle(id: { eq: $id }) {
      title
      subtitle
      slug
      para {
        para
      }
    }
  }
`
2
  • Perfect, thanks - not quite sure how I missed that! I have chosen to render long text, because I had major issues with render rich text using the new raw subfield. Would you mind taking a look at this issue? - stackoverflow.com/questions/65751495/… Jan 16, 2021 at 19:04
  • Sure, I will. If the issue has been solved please accept the answer to close the issue :) Jan 16, 2021 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.