gatsby-source-rss-feed icon indicating copy to clipboard operation
gatsby-source-rss-feed copied to clipboard

Query fails when rss feed has no items.

Open jhoude5 opened this issue 4 years ago • 3 comments

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.

jhoude5 avatar May 17 '21 21:05 jhoude5

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.

lettie16 avatar Mar 23 '23 14:03 lettie16

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

mottox2 avatar Mar 23 '23 16:03 mottox2

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!

jdahdah avatar Jan 19 '24 12:01 jdahdah