Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different GraphQL query in development and production #12460

Closed
janosh opened this issue Mar 10, 2019 · 1 comment
Closed

Different GraphQL query in development and production #12460

janosh opened this issue Mar 10, 2019 · 1 comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@janosh
Copy link
Contributor

janosh commented Mar 10, 2019

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?

@pieh pieh added the type: question or discussion Issue discussing or asking a question about Gatsby label Mar 11, 2019
@pieh
Copy link
Contributor

pieh commented Mar 11, 2019

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 #10844 (comment)

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

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Apr 1, 2019
@janosh janosh closed this as completed Apr 1, 2019
@gatsbyjs gatsbyjs deleted a comment from gatsbot bot Apr 1, 2019
@janosh janosh removed the stale? Issue that may be closed soon due to the original author not responding any more. label Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

2 participants