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

Can't use graphql in onCreateNode #3121

Closed
MrToph opened this issue Dec 3, 2017 · 2 comments
Closed

Can't use graphql in onCreateNode #3121

MrToph opened this issue Dec 3, 2017 · 2 comments

Comments

@MrToph
Copy link

MrToph commented Dec 3, 2017

Hi,
I'm trying to make a graphql query in onCreateNode in gatsby-node.js, but graphql is undefined.
It seems like it's not passed to this function.

exports.onCreateNode = ({
  graphql,
  node,
  boundActionCreators,
  getNode,
}) => {
  console.log(graphql)
}

It works on exports.createPages, so I expected it to also work here. (The documentation also doesn't give much info on what arguments are available for the gatsby-node functions.)

Is there a reason why I cannot use graphql in this function?

@pieh
Copy link
Contributor

pieh commented Dec 3, 2017

It's because at this stage of build process graphql schema is not yet created. Use getNodes to get all created nodes and filter/process it in js

@MrToph
Copy link
Author

MrToph commented Dec 3, 2017

Alright will do it this way then, thanks.

@MrToph MrToph closed this as completed Dec 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants