-
Description
Gatsby provides gatsby-config.js module.exports = {
plugins: [
{
resolve: `gatsby-source-filesystem`,
options: {
name: `blog-posts`,
path: path.resolve(__dirname, `./src/contents/blog-posts`),
},
},
{
resolve: `gatsby-transformer-remark`,
options: {
excerpt_separator: `<!--more-->`,
},
},
],
} Right now, I am filtering {
allBlogPost: allMarkdownRemark(
filter: {fileAbsolutePath: {glob: "**/blog-posts/**"}}
sort: {fields: frontmatter___date, order: DESC}
) {
blogPosts: nodes {
fileAbsolutePath
fields {
slug
}
parent {
... on File {
sourceInstanceName
}
}
frontmatter {
title
author
date(formatString: "MMMM DD, YYYY")
tags
}
}
}
} Unfortunately, I cannot filter on parent other than id so I am unable to filter {
allBlogPost: allMarkdownRemark(
filter: {
parent: {sourceInstanceName: "blog-posts"}
}
sort: {fields: frontmatter___date, order: DESC}
) {
blogPosts: nodes {
fileAbsolutePath
fields {
slug
}
parent {
... on File {
sourceInstanceName
}
}
frontmatter {
title
author
date(formatString: "MMMM DD, YYYY")
tags
}
}
}
} It would be great if {
allBlogPost: allMarkdownRemark(
filter: {fileSourceInstanceName: {eq: "blog-posts"}}
sort: {fields: frontmatter___date, order: DESC}
) {
blogPosts: nodes {
fileAbsolutePath
fileSourceInstanceName
fileRelativeDirectory
fileName
}
}
} or provide a file node with those fields: {
allBlogPost: allMarkdownRemark(
filter: {file: sourceInstanceName: {eq: "blog-posts"}}
sort: {fields: frontmatter___date, order: DESC}
) {
blogPosts: nodes {
file {
absolutePath
sourceInstanceName
relativeDirectory
name
}
}
}
} I think having the ability to filter Steps to reproduceI've made a minimal repo at https://github.com/kimbaudi/gatsby-group-query. Expected resultHave ability to filter Actual resultOnly have ability to filter {
allBlogPost: allMarkdownRemark(
filter: { fileAbsolutePath: { glob: "**/blog-posts/**" } }
) {
blogPosts: nodes {
fileAbsolutePath
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
linking to discussion #30393 |
Beta Was this translation helpful? Give feedback.
-
You can use https://www.gatsbyjs.com/docs/reference/config-files/actions/#createNodeField to add additional fields |
Beta Was this translation helpful? Give feedback.
-
@LekoArts - thank you for your suggestion... it works perfectly! For anyone else interested, here is my gatsby-node.js exports.onCreateNode = ({ node, actions: { createNodeField }, getNode }) => {
if (node.internal.type === `MarkdownRemark`) {
const { absolutePath, name, sourceInstanceName } = getNode(node.parent)
const relativeFilePath = createFilePath({
node,
getNode,
})
createNodeField({
name: `absolutePath`,
node,
value: absolutePath,
})
createNodeField({
name: `name`,
node,
value: name,
})
createNodeField({
name: `sourceInstanceName`,
node,
value: sourceInstanceName,
})
createNodeField({
name: `slug`,
node,
value: `/${sourceInstanceName}${relativeFilePath}`,
})
}
} And now I can filter those fields: |
Beta Was this translation helpful? Give feedback.
You can use https://www.gatsbyjs.com/docs/reference/config-files/actions/#createNodeField to add additional fields