question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

General Remark (Markdown) filter in GraphQL

See original GitHub issue

Summary

As briefly noted here, it’d be useful to have Remark parse arbitrary data fields. This’d be even better if handled at the GraphQL data layer, because then the browser never has to process Markdown at all.

Basic example

<page-query>
query Post($id: String) {
  post(id: $id) {
    body(markdown: true)
  }
}
</page-query>

We’d then expect $page.post.body to be pre-rendered, ready to pass to v-html.

Motivation

I don’t just want Remark to parse .md files; in my case, Netlify CMS stores chunks of Markdown in my content’s .yml files wherever there’s a rich text field.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

16reactions
hjvedvikcommented, Jul 1, 2019

Yes, it would be really nice to be able to parse any markdown content in the GraphQL layer 😃 We are working on a new schema API which could allow a plugin to for example add a @markdown directive which could be used on any String field to transform it to HTML. The API will be ready within a couple of weeks.

11reactions
patrikengborgcommented, Feb 17, 2020

I came up with this solution.

first npm install markdown-it --save

In gridsome.server.js, require it: var MarkdownIt = require('markdown-it')

then add:

api.loadSource(({ addSchemaResolvers }) => {
  addSchemaResolvers({
    ContentfulBlogPost: {
      body: {
        type: 'String',
        args: {
          markdown: 'Boolean'
        },
        resolve(node, args) {
          if (args.markdown) {
            const md = new MarkdownIt()
            return md.render(node.body)
          }

          return node.body
        }
      }
    }
  }
}

Then you can use body(markdown: true) in your GraphQL for that field.

That’s it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I filter graph ql query based on markdown frontmatter?
I think the filter should be on the allMarkdownRemark : { allMarkdownRemark ( filter: { frontmatter: { type: { eq: "folio" } }...
Read more >
GraphQL API style guide - GitLab Docs
Aliasing and deprecating mutations. Marking schema items as Alpha. How to filter Kibana for queries that used deprecated fields. Create a deprecation issue....
Read more >
Keeping certain parts of your GraphQL schema hidden from ...
However, Directives are part of the general GraphQL Specification, ... A directive that will filter things from the Introspection Query ...
Read more >
Working Draft - GraphQL
GraphQL source documents may contain single-line comments, starting with the ... GraphQL descriptions are defined using the Markdown syntax (as specified by ...
Read more >
Create a Markdown Blog Using Next.js - Joy of Code
There are remark plugins that process Markdown and rehype plugins that ... so it would be nice being able to filter them by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found