Last active
April 24, 2020 13:42
-
-
Save theowenyoung/7821aa537c70949d8f90bf4fb0efd173 to your computer and use it in GitHub Desktop.
gatsby create node question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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