4

I have successfully sourced data with gatsby-source-contentful, but can't figure out how to extend contentful queries with markdownRemark as it's shown in the official gatsby-contentful-starter.

I added gatsby-transformer-remark in gatsby-config.js, ran gatsby clean && gatsby develop, but still can't see childMarkdownRemark in Graphiql. enter image description here

gatsby-config.js:

module.exports = {
  siteMetadata: {
    title: 'Test Contentful and MarkdownRemark',
  },
  plugins: [
    {
      resolve: `gatsby-source-contentful`,
      options: {
        // spaceId: 'XXXXXXXXXXXX',
        // accessToken: 'XXXXXXXXXXXX',
      },
    },
    `gatsby-transformer-remark`
  ],
}

package.json:

{
  "name": "test-gatsby-contentful",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "gatsby": "^2.18.2",
    "gatsby-source-contentful": "^2.1.62",
    "gatsby-transformer-remark": "^2.6.37"
  }
}

Reproduction repo

iamskok
  • 600
  • 5
  • 19
  • 2
    I tried your repository, everything working as expected: I can query *childMarkdownRemark*. Is your Contentful data Markdown format? – Zooly Nov 25 '19 at 20:14
  • Yes, contentful returns markdown. Were you able to see `childMarkdownRemark` on `body` in Graphiql as well? – iamskok Nov 25 '19 at 20:38
  • 1
    Yep, I only checked there – Zooly Nov 25 '19 at 20:50
  • Can you please share the query which worked for you? – iamskok Nov 25 '19 at 20:51
  • I don't have same structure than you on Contentful (I guess), but my query is : `query MyQuery { allContentfulArticleDeBlog { edges { node { body { childMarkdownRemark { html excerpt } } } } } } ` – Zooly Nov 25 '19 at 20:54
  • I just double-checked that I'm using Rich Text snippet in contentful. But once I query `childMarkdownRemark` on `body` I get `Cannot query field "childMarkdownRemark" on type `contentfulFeaturedServicesBodyRichTextNode` – iamskok Nov 25 '19 at 20:59
  • 2
    Ok on my side I'm using Long Text with Markdown as Appearance (default one) – Zooly Nov 25 '19 at 21:02

1 Answers1

0

gatsby-transformer-remark only works with Long Text fields that contain Markdown formatted text. If your field type is Rich Text the plugin will not work since the field doesn't contain Markdown, but you can use Contentful's rich-text-html-renderer.

Kaivosukeltaja
  • 15,541
  • 4
  • 40
  • 70