Is there a way to modify the GraphQL queries in a page component depending on whether the site is running in development or production mode?
You can't directly manipulate query text, but you can pass different context depending if you are in dev or in prod mode.
If this is referring to issue described in https://github.com/gatsbyjs/gatsby/issues/10844#issuecomment-471349943
programatically create blog listing, so you can pass context
to query
createPage({
path: "/blog",
template: <some_template>,
context: {
draftBlacklist: process.env.NODE_ENV === `production` ? [true] : []
}
})
and then in query:
query BlogListing($draftBlacklist: [String!]!) {
allMarkdownRemark(filter: {frontmatter: {draft: {nin: $draftBlacklist}}}) {
edges {
node {
frontmatter {
title
draft
}
}
}
}
Which should show all nodes in dev, and filter out all nodes with draft
set to true
in production. There might be some caching issue (if you run build after develop, we will not rerun query atm). But if you use netlify
(or other kinds of CI/CD) for production builds this should work
Most helpful comment
You can't directly manipulate query text, but you can pass different context depending if you are in dev or in prod mode.
If this is referring to issue described in https://github.com/gatsbyjs/gatsby/issues/10844#issuecomment-471349943
programatically create blog listing, so you can pass
context
to queryand then in query:
Which should show all nodes in dev, and filter out all nodes with
draft
set totrue
in production. There might be some caching issue (if you run build after develop, we will not rerun query atm). But if you usenetlify
(or other kinds of CI/CD) for production builds this should work