Is there a way to query/gain access to other markdown files/nodes when resolving a Graphql query?
See original GitHub issueIs there a way to query/gain access to other markdown files/nodes when resolving a Graphql query?
I have pages as markdown files with a front matter field for a list of widget names. These widgets are markdown files of their own with a bunch of front-matter fields that I will use as props in a react component.
I have all of the widgets in a separate folder and am not directly using them to create pages. What I would like to do is create a query that functions like this:
{
allMarkdownRemark(filter: { fileAbsolutePath: {regex : "/src\/pages/"} }) {
edges {
node {
excerpt(pruneLength: 400)
html
id
frontmatter {
templateKey
path
date
title
// This frontmatter widgetlist has the names of the markdown files that I need to resolve the widgetList on the node.
widgetList {
widget
}
}
widgetList {
widget {
widgetStyle
isCenter
isFullWidth
}
}
}
}
}
}
I am currently stuck because I have the names of the widgets that are supposed to be on each page in the front matter, but to resolve the widgetList type, I need to to find the markdown nodes in question in the page-components folder.
I used the code from gatsby-transformer-remark to get started creating my custom plugin in plugins/markdown-extender. Gatsby-transformer-remark has a file extend-node-type.js which I have been modifying. But a lot of this code is completely foreign to me other than the Graphql bits. @KyleAMathews would you be able to shed some light on this so I can start digging in a better direction? That would be much appreciated!
Here’s a link to the repo: https://github.com/luczaki114/Lajkonik-Gatsby-NetlifyCMS-Site
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (11 by maintainers)
Top GitHub Comments
Oh, we currently only map to ids. But we can make it work with some additional custom code in
gatsby-node.js
:and in your
gatsby-config.js
use this mapping config:and example query:
There’s always room for improvement for sure. I’m currently working on schema related things and will add this to my list (why that list is only growing and not getting smaller 😠 ).
Way to to be able to specify on what field to we should link nodes would indeed be great as current mapping is best suited for json/yaml data (where we define id ourselves) or for programmatic solution (like one I pasted above). It would be great to do something like: