syntra / gatsby-remark-reading-time

Gatsby remark plugin to add an estimated reading time field to all remark nodes
MIT License
25 stars 16 forks source link

MDX issue: Unknown field 'readingTime' on type 'MdxFields' #6

Open i-bsd opened 4 years ago

i-bsd commented 4 years ago

Switched over to MDX. All configuration for gatsby-remark-reading-time left the same.

Doesn't seem to be compatible:

GraphQL Error Encountered 1 error(s):
- Unknown field 'readingTime' on type 'MdxFields'. 

Using this query:

query BlogPostBySlug($slug: String!) {
         site {
           siteMetadata {
             title
             author
             siteUrl
           }
         }
         mdx(fields: {slug: {eq: $slug}}) {
           body
           id
           excerpt(pruneLength: 160)
           fields {
             slug
             readingTime {
               text
             }
           }
tgallacher commented 4 years ago

This isn't supported yet. But #5 will bring in support 😄

tgallacher commented 4 years ago

This can probably be closed now, as MDX support has been merged

i-bsd commented 4 years ago

Excellent. Thanks. Any changes need to be made to my query for it to work?

tgallacher commented 4 years ago

Excellent. Thanks. Any changes need to be made to my query for it to work?

Although this change has been merged, I don't believe a new version has been released. Docs on how to use (when it is released) have been added in #7

tgallacher commented 4 years ago

If you're super stuck and need to move on, you can create a copy of this plugin in your Gatsby setup as a local plugin. You can then remove it once the MDX feature has been released.

SMerdzhanov commented 4 years ago

Hey @tgallacher, thanks for sharing this intel :+1:

I was just wondering why it isn't working for me either. I see that the changes are already in 1.0.1 and that's the package version I'm using, but apparently it's still not there yet.

I'll follow your suggestion on using this as a local plugin. Hopefully, this gets published soon since it's quite a helpful package.

tgallacher commented 4 years ago

Hey @tgallacher, thanks for sharing this intel 👍

I was just wondering why it isn't working for me either. I see that the changes are already in 1.0.1 and that's the package version I'm using, but apparently it's still not there yet.

I'll follow your suggestion on using this as a local plugin. Hopefully, this gets published soon since it's quite a helpful package.

Yup, hopefully this is released soon (i'm also using the local plugin approach as a workaround). The changes are in master, but not in a tagged release yet. Version 1.0.1 is from 1 year ago from what I can tell, but hopefully this will be released soon.

thanks

ghost commented 4 years ago

y'all... gatsby-transformer-remark supports a timeToRead out-of-the-box 🤯just found this out

https://github.com/gatsbyjs/gatsby/blob/24bd7a8d2c7ce005c24b41a712679f8882d90c41/packages/gatsby-transformer-remark/src/extend-node-type.js#L380

nemethricsi commented 3 years ago

y'all... gatsby-transformer-remark supports a timeToRead out-of-the-box 🤯just found this out

https://github.com/gatsbyjs/gatsby/blob/24bd7a8d2c7ce005c24b41a712679f8882d90c41/packages/gatsby-transformer-remark/src/extend-node-type.js#L380

I'm not sure it's working good tho. I got 1 for pretty long posts.

adnjoo commented 1 year ago

I had a similar error like Unknown field 'readingTime' on type allMdx with a query like:

query {
      allMdx(sort: { frontmatter: { date: ASC } }, limit: 1000) {
        nodes {
          id
          frontmatter {
            slug
          }
          fields {
            readingTime {
              text
            }
          }
        }
      }
    }

and I changed node.rawBody to node.body in gatsby-node.js in the node_modules/gatsby-remark-reading-time folder and the query started working.

  } else if (node.internal.type === `Mdx`) {
    createNodeField({
      node,
      name: `readingTime`,
      value: readingTime(node.body)
    });
  }

maybe it has something to do with the Gatsby version? (I was using Gatsby 5.5.0)