我想创建一个类别页面.我正在使用Gatsby.js、GraphQL和Strapi



我想创建一个类别页面。我正在使用Gatsby.js、GraphQL和Strapi。过滤器可能不工作。但我不知道该怎么解决。

{strapiCategory.slug}.js

import * as React from "react";
import { graphql } from "gatsby";
import { Helmet } from "react-helmet";
import Layout from "../../components/Layout";
import PostList from "../../components/PostList";
import *as styles from "./{MicrocmsCategory.slug}.module.css";
const CategoryPage = (props) => {
const categories = props.data.strapiCategory;
const posts = props.data.allStrapiPost.nodes;
return (
<Layout>
<Helmet>
<title>{categories.name}</title>
<meta name="description" content={categories.name} />
</Helmet>
<p className={styles.categoryName}> {categories.name}</p>
<PostList posts={posts} />
</Layout>
);
};
export const query = graphql`
query ($slug: String!){
strapiCategory (slug: { eq: $slug }){
name
slug

}
allStrapiPost(filter:{categories:{slug:{ eq: $slug }}}){
nodes {
slug
title
content
thumbnail
published_at(formatString: "YYYY.MM.DD hh:mm")
categories {
slug
name
}
}
}
}
`;
export default CategoryPage;

错误代码

错误#98123 WEBPACK

生成开发JavaScript捆绑包失败

/用户/t/WebDevelopment/xxxxxxx/src/pages/categories/{xxxx.slug}.js29:39错误字段";鼻涕虫";不是由类型定义的"StrapPostCategoriesFilterListInput";graphql/模板字符串

✖1个问题(1个错误,0个警告(

失败重新构建开发捆绑包-中的0.177s错误/用户/t/WebDevelopment/xxxxx/src/pages/categories/{xxxxxx.slug}.js29:39错误字段";鼻涕虫";不是由类型定义的"StrapPostCategoriesFilterListInput";

链接工作正常。

它将显示出来。

const categories = props.data.strapiCategory;
<title>{categories.name}</title>.

这将不会显示。

const posts = props.data.allStrapiPost.nodes;
<PostList posts={posts} />

字段"鼻涕虫";不是由类型定义的"StrapPostCategoriesFilterListInput";graphql/模板字符串

这是不言自明的。在您的情况下,slug位于categories(FileSystem API中的集合/嵌套路由(下。

你的{xxxxx.slug}.js应该变成:

{xxxxx.categories.slug}.js

你能试着在graphql中使用where而不是filter吗

allStrapiPost(where:{categories:{slug:{ eq: $slug }}}){

最新更新