1
votes

I have a GraphQL schema on a headless CMS. I'm using gatsby-source-graphql on a Gatsby site to get data from it.

There is a content field MyType_BlogPost.body of type String. This contains markdown code.

Is it possible to transform (with gatsby-transformer-remark) that into MarkdownRemark (or similar) so that it will automatically get subfields like html that contain the data one would expect (html code transformed from the markdown source)? I suspect subfields would be the way to do this, but I'm not 100 % of that.

I also suspect this could help but I'm not sure: https://www.gatsbyjs.org/docs/schema-customization/

Thank you.

1
If your MyType_BlogPost.body contains HTML, you can convert that to Markdown using something like turndown after it has been queried. Or are you actually wanting to change the GraphQL query such that it returns Markdown instead of the html which is currently stored in the .body field? - JayGee
Hmm sorry, I think my question was vague. The body field contains markdown code which I would like to transform into html. Question fixed. - ile

1 Answers

0
votes

If the field contains markdown code which you would like to transform into html, you should be able to do that using remark.

Remark is the library that gatsby-transformer-remark uses under the hood.

https://remark.js.org/

Specifically, look at the API section in their docs.