When running gatsby build command it fails with the following error:
"gatsby-plugin-feed" threw an error while running the onPostBuild lifecycle:
Cannot query field "allMarkdownRemark" on type "Query".
I am not using markdown in this project, but sourcing my content from Prismic using gatsby-source-prismic.
This page does not seem to offer much help on how to source content that is not from markdown feed. https://www.gatsbyjs.org/docs/adding-an-rss-feed/
And neither does the github page for the module. https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-feed
gatsby-config.js:
module.exports = {
siteMetadata: {
title: 'Something',
siteUrl: 'https://something.com/',
description:
'Lorem Ipsum Dolor Sit Amet',
author: '@something'
},
plugins: [
... some plugins,
{
resolve: 'gatsby-plugin-feed',
options: {
query: `{
site {
siteMetadata {
title
description
siteUrl
site_url: siteUrl
}
}
}
`
},
feeds: [
{
serialize: ({ query: { site, allPrismicPost } }) => {
return allPrismicPost.edges.map(edge => {
return Object.assign({}, edge.node.data, {
description: edge.node.pre_title,
date: edge.node.first_publication_date,
url: site.siteMetadata.siteUrl + edge.node.uid,
guid: site.siteMetadata.siteUrl + edge.node.uid
});
});
},
query: `
{
allPrismicPost {
edges {
node {
id
uid
first_publication_date
data {
title {
text
}
pre_title
link_text
}
}
}
}
}
`,
output: '/feed.xml',
title: 'RSS feed'
}
]
},
}
}
https://www.gatsbyjs.org/docs/adding-an-rss-feed/#customizing-the-rss-feed-plugin
This is the part you should look into. You need to create a custom serialize function. You probably want to keep the siteMetadata query (except you define those things in Prismic, too). Maybe also have a look at starters that use the feed plugin: https://www.gatsbyjs.org/starters/?d=gatsby-plugin-feed&v=2 (you could also filter by Headless:CMS)
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-feed`,
options: {
query: `
{
site {
siteMetadata {
title
description
siteUrl
site_url: siteUrl
}
}
}
`,
feeds: [
{
serialize: ({ query: { site, allPrismicYourContent } }) => {
return allPrismicYourContent.edges.map(edge => {
your content
})
},
query: `
{
allPrismicYourContent {}
}
`,
output: "/rss.xml",
title: "Your Site's RSS Feed",
},
],
},
},
],
}
I am not sure what you are suggesting, I am writing my own serialize function. When reading the error message it doesn't look like it is the serialization that's the problem.
The problem is:
"gatsby-plugin-feed" threw an error while running the onPostBuild lifecycle:
Cannot query field "allMarkdownRemark" on type "Query".
Can you link your repository or provide a minimal reproduction?
Here is a repo with minimal reproduction. https://github.com/mathiasha/gatsby-feed-bug
npm installnpm run build@mathiasha i've picked up on your issue and it seems that i have a solution for your case.
Here are the steps i took to solve your issue.
yarn build && yarn serve and it seems that the issue persists, it is defaulting to the inbuilt query. Basically the one implemented here and here. {
resolve: "gatsby-plugin-feed",
options: {
setup(ref) {
const metaInfo = ref.query.site.siteMetadata
metaInfo.generator = "GatsbyJS test"
return metaInfo
},
query: `
{
site {
siteMetadata {
title
description
siteUrl
site_url: siteUrl
}
}
}
`,
feeds: [
{
serialize(value) {
const rssMetadata = value.query.site.siteMetadata
return value.query.allPrismicPost.edges.map(edge => ({
description: edge.node.data.post_title.text,
date: edge.node.first_publication_date,
url: rssMetadata.siteUrl + edge.node.uid,
guid: rssMetadata.siteUrl + edge.node.uid,
}))
},
query: `
{
allPrismicPost {
edges {
node {
id
uid
first_publication_date
data {
post_title {
text
}
}
}
}
}
}
`,
output: "/fees.xml",
title: "Dansk RSS feed",
},
],
},
},
gatsby build && gatsby serve and i'm presented with:success open and validate gatsby-configs - 0.079 s
success load plugins - 0.839 s
success onPreInit - 0.063 s
success delete html and css files from previous builds - 0.068 s
success initialize cache - 0.064 s
success copy gatsby files - 0.228 s
success onPreBootstrap - 0.064 s
verbose gatsby-source-prismic - starting to create types
success gatsby-source-prismic - create types - 0.067 s
verbose gatsby-source-prismic - starting to fetch documents
verbose gatsby-source-prismic - fetching documents page 1
verbose gatsby-source-prismic - fetched 1 documents
success gatsby-source-prismic - fetch documents - 0.872 s
verbose gatsby-source-prismic - starting to create nodes
verbose gatsby-source-prismic - creating node {"id":"8e814031-38d9-5484-94f4-23133eea5ea0","type":"PrismicPost","prismicId":"XXIcyBEAACYAIcyB"}
success gatsby-source-prismic - create nodes - 1.587 s
verbose gatsby-source-prismic - starting to write out type paths
verbose gatsby-source-prismic - writing out type paths to:
C:\Users\paxa2\Documents\gatsby_fork\testmobileheader\test_mathiasha\gatsby-feed-bug\public\undefined402bcb81c87e7b33f331c1a5d2f71073.json
success gatsby-source-prismic - write out type paths - 0.063 s
success source and transform nodes - 2.794 s
success Add explicit types - 0.060 s
warn Deprecation warning - adding inferred resolver for field PrismicPost.first_publication_date. In Gatsby v3, only fields with an explicit directive/extension will
get a resolver.
warn Deprecation warning - adding inferred resolver for field PrismicPost.last_publication_date. In Gatsby v3, only fields with an explicit directive/extension will get
a resolver.
success Add inferred types - 0.207 s
success Processing types - 0.122 s
success building schema - 0.517 s
success createPages - 0.082 s
success createPagesStatefully - 0.125 s
success onPreExtractQueries - 0.059 s
success update schema - 0.095 s
success extract queries from components - 0.308 s
success write out requires - 0.062 s
success write out redirect data - 0.060 s
success onPostBootstrap - 0.059 s
â €
info bootstrap finished - 14.237 s
â €
success run static queries - 0.056 s
success Building production JavaScript and CSS bundles - 7.642 s
success Rewriting compilation hashes - 0.067 s
success run page queries - 0.091 s — 2/2 202.13 queries/second
success Building static HTML for pages - 0.732 s — 2/2 6.61 pages/second
info Done building in 23.04 sec
http://localhost:9000/fees.xml i'm presented with the following:
Feel free to provide feedback so that we can close this issue or continue to work on it until we find a suitable solution for your issue.
@jonniebigodes your solution does seem to do the trick.
Thanks @jonniebigodes ! Closing this as resolved then :)
@LekoArts Well the issue still persists. So either the issue should be fixed, or the documentation has to be updated to reflect the necessary parts to go through so other people wont have to go through these issue.
I cloned your repo again after realizing that your real issue was the misplacement of the feeds option. You closed the options early (here) and hence the feeds option never was considered.
So this is a user error and nothing we can fix in the documentation or code :)
Most helpful comment
@mathiasha i've picked up on your issue and it seems that i have a solution for your case.
Here are the steps i took to solve your issue.
yarn build && yarn serveand it seems that the issue persists, it is defaulting to the inbuilt query. Basically the one implemented here and here.gatsby build && gatsby serveand i'm presented with:http://localhost:9000/fees.xmli'm presented with the following:Feel free to provide feedback so that we can close this issue or continue to work on it until we find a suitable solution for your issue.