Skip to content

Instantly share code, notes, and snippets.

@theowenyoung
Last active April 24, 2020 13:42
Show Gist options
  • Save theowenyoung/7821aa537c70949d8f90bf4fb0efd173 to your computer and use it in GitHub Desktop.
Save theowenyoung/7821aa537c70949d8f90bf4fb0efd173 to your computer and use it in GitHub Desktop.
gatsby create node question
exports.sourceNodes = function () {
// I know I can't query the graphql data in `sourceNodes` lifecycle, just a example.
// My question is which lifecycle can I query the data, and create new node before createPages
// like this:
const allMarkdownRemarkResult = await graphql(`
{
allMarkdownRemark {
edges {
node {
id
excerpt( format: HTML, pruneLength: 500)
}
}
}
}
`);
allMarkdownRemarkResult.allMarkdownRemark.edges.forEach(({ node }) => {
createNode({
id: createNodeId(`timelinet-${node.id}`),
excerpt: node.excerpt,
children: [],
parent: node.id,
internal: {
type: "Timeline",
contentDigest: createContentDigest(`timelinet-${node.id}`)
},
})
})
}
exports.createPages = async ({ graphql }) => {
const allTimeline = await graphql(`{
allTimeline {
edges {
node {
id
excerpt
}
}
}
}`)
console.log('allTimeline', allTimeline);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment