我使用GatsbyJS,这是我的第一次冒险与反应和graphql。我想混一个单页的内容同时包含“博客,帖子”类型的内容,以及“回购后”类型的内容,但我不知道如何将它添加到查询过滤它。
另外;我知道什么是frontmatter(RE:降价),但我不知道是什么templateKey,而“EQ”在此背景下。我不知道有足够的了解什么,我看就知道它叫什么,开始寻找解释。
export const pageQuery = graphql`
query IndexQuery {
allMarkdownRemark(
sort: { order: DESC, fields: [frontmatter___date] },
filter: { frontmatter: { templateKey: { eq: "blog-post" } }}
) {
edges {
node {
excerpt(pruneLength: 400)
id
fields {
slug
}
frontmatter {
title
templateKey
date(formatString: "MMMM DD, YYYY")
}
}
}
}
}
`
这里eq
意味着equals和templateKey
在你降价frontmatter只是另一个关键。你定的过滤器基本上是说:“如果templateKey
在frontmatter
值等于博客员额”。
你可以改变从过滤器
filter: { frontmatter: { templateKey: { eq: "blog-post" } }}
至
filter: { frontmatter: { templateKey: { in: ["blog-post", "repo-post"] } }}
你应该看看docs on graphql。它也有一个叫做GraphiQL伟大的工具,以查询玩耍。