【发布时间】:2020-11-14 19:55:30
【问题描述】:
编辑
我想我不清楚我的问题。
问题是 sourceInstanceName 正在返回问题中显示的空数组,即使该文件夹包含内容和 .md 文件。
大家好,我在使用 graphql 查询文件夹时遇到问题。
你看我有这个文件结构:
/content/posts/Journeys/{FILENAME}.{EXTENSION}
/content/posts/Blog/{FILENAME}.{EXTENSION}
我想查询文件夹名称(又名 Journeys 或 BLOG)而不是内容。
我可以使用这个查询:
query test2 {
journeys: allFile(filter: {sourceInstanceName: {eq: "posts"}}) {
edges {
node {
dir
name
relativePath
relativeDirectory
}
}
}
}
返回这个,它返回不必要的文件,因为我只想要文件夹名称或目录:
{
"data": {
"journeys": {
"edges": [
{
"node": {
"dir": "D:/Side-projects/salomonpina.dev/content",
"name": ".git",
"relativePath": ".git",
"relativeDirectory": ""
}
},
{
"node": {
"dir": "D:/Side-projects/salomonpina.dev/content/icons/png",
"name": "github-icon_512",
"relativePath": "icons/png/github-icon_512.png",
"relativeDirectory": "icons/png"
}
},
more info down...
它也适用于资产
但是当我将(filter: {sourceInstanceName: {eq: "posts"}}) 更改为(filter: {sourceInstanceName: {eq: "journeys"}})
它返回一个空数组:
{
"data": {
"journeys": {
"edges": []
}
}
}
即使它使用正确的名称,来自gatsby-source-filesystem 的名称。
这是我在gatsby-config.js 和gatsby-source-filesystem 中所做的。
{
resolve: "gatsby-source-filesystem",
options: {
name: "posts",
path: `${__dirname}/content/`,
},
},
{
resolve: "gatsby-source-filesystem",
options: {
name: "assets",
path: `${__dirname}/static/`,
},
},
{
resolve: "gatsby-source-filesystem",
options: {
name: "journeys",
path: `${__dirname}/content/posts/Journeys/`,
},
},
我试过this solution,但似乎没有帮助。
任何帮助将不胜感激。
【问题讨论】:
-
你是指每个
post的文件夹吗? -
是的,每个帖子的文件夹名称
标签: graphql filesystems gatsby