mottox2 / gatsby-source-rss-feed

Gatsby source plugin for rss feed.
https://www.npmjs.com/package/gatsby-source-rss-feed
24 stars 6 forks source link

Query error when adding custom XML field #5

Closed mikeriley131 closed 5 years ago

mikeriley131 commented 5 years ago

Getting error GraphQL Error Unknown field youTubeUrl on type FeedLibSynRss after adding a custom field to the RSS XML.

query:

export const pageQuery = graphql`
  query {
    allFeedLibSynRss {
      edges {
        node {
          title
          youTubeUrl
          enclosure {
            url
          }
          itunes {
            season
            episode
            summary
            keywords
            duration
          }
        }
      }
    }
  }

snippet of RSS feed:

<item>
    ...
    <itunes:season>1</itunes:season>
    <itunes:episode>1</itunes:episode>
    <itunes:episodeType>full</itunes:episodeType>
    <!-- START ITEM EXTRA TAGS -->
    <youTubeUrl>https://www.youtube.com/watch?v=YE7VzlLtp-4</youTubeUrl>
    <!-- CLOSE ITEM EXTRA TAGS -->
</item>

Are the comments causing the issue? Unfortunately I don't have any control over them.

mottox2 commented 5 years ago

@mikeriley131 Did you add youTubeUrl to options.parserOption.customFields.item in gatsby-config.js?

// In your gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: `gatsby-source-rss-feed`,
      options: {
        url: `https://www.gatsbyjs.org/blog/rss.xml`,
        name: `GatsbyBlog`,
        // Optional
        // Read parser document: https://github.com/bobby-brennan/rss-parser#readme
        parserOption: {
          customFields: {
            item: ['itunes:duration']
          }
        }
      }
    }
  ]
}
mikeriley131 commented 5 years ago

I didn't. My understanding was that the customFields object would just be for properties containing a colon (:). Will try today and see if that makes a difference.

mikeriley131 commented 5 years ago

Well that does indeed work. Thank you! Could you help me understand what needs to go in that customFields object and what does not?

mottox2 commented 5 years ago

@mikeriley131 gatsby-source-rss-feed use rss-parser as RSS parser. rss-parser has default fields, so we have to define custom fields.

We can check default fields in this file. https://github.com/bobby-brennan/rss-parser/blob/master/lib/fields.js