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 fails when rss feed has no items. #19

Open jhoude5 opened 3 years ago

jhoude5 commented 3 years ago

Im trying to post job feeds. But I want to make we capture when there are no jobs to show a message, but the build fails because the name of the feed doesnt have items in the rss feed to add to the database.

lettie16 commented 1 year ago

Was there any fix for this?

It also relates to the other issue here:

There was an error in your GraphQL query: Cannot query field "allFeedGatsbyBlog" on type "Query".

The problem is with a vacancy/jobs feed there are likely times when the rss data returns nothing or no items. This then causes the graphql query to break as none of the nodes it is expecting have been returned. So a solution for this would be handy otherwise the plugin is unusable in when the feed returns no items.

mottox2 commented 1 year ago

@lettie16 Thanks for the reminder. I missed this Issue and the problem still exists. I will investigate around the end of this month.

jdahdah commented 9 months ago

I just found a solution for this. You can provide a custom schema in gatsby-node.js that sets up the GraphQL nodes regardless of whether the feed has items or not. This tutorial explains why it happens and how to write the schema.

In my case it's also a job board, served by the TeamTailor service. This is my schema customization:

// gatsby-node.js

exports.createSchemaCustomization = ({ actions }) => {
  const { createTypes } = actions

  createTypes(`
    type FeedTeamTailorRss implements Node {
      guid: String
      department: String
      title: String
      locations: [Location]
      link: String
    }
    type Location {
      tt_location: TTLocation
    }
    type TTLocation {
      tt_city: String
      tt_country: String
    }
  `)
}

I based it on the original GraphQL query, which in my case is:

allFeedTeamTailorRss {
  nodes {
    guid
    department
    title
    locations {
      tt_location {
        tt_city
        tt_country
      }
    }
    link
  }
}

Hope this helps!