Я пытаюсь сгенерировать страницы с помощью gatsby-node из Sanity headless CMS.
У меня есть несколько шаблонов, которые работают нормально, мой третий шаблон не работает. Раньше он имел ту же структуру, что и другие шаблоны, я изменил структуру, чтобы использовать запрос stati c вместо запроса, подобного странице. См. Суть всех шаблонов.
Gatsby выходит из строя с сообщением об ошибке:
There was a problem parsing "/Users/computa/Documents/prosjekter/funka/template/web/src/templates/projectsSubPages.js"; any GraphQL
fragments or queries in this file were not processed.
This may indicate a syntax error in the code, or it may be a file type
that Gatsby does not know how to parse.
File: src/templates/projectsSubPages.js
My projectsSubPages. js template
import React from "react";
import { useStaticQuery, graphql } from "gatsby";
import Layout from "../components/layout";
const BlockContent = require("@sanity/block-content-to-react");
const projectsSubPages = ({ data }) => {
const data = useStaticQuery(graphql`
{
allSanityProjects {
edges {
node {
projectChildPages {
_rawBlockContent
title
}
}
}
}
}
`);
const pageData = data.allSanityProjects.edges;
return (
<Layout>
{/* {pageData.map((node) => (
<p>Hello world</p>
))}
<BlockContent blocks={pageData._rawBlockContent} /> */}
<p>Hello world!</p>
</Layout>
);
};
export default projectsSubPages;
My gatsby- node.js file, это нижняя страница createPage не удается
exports.createPages = ({ actions, graphql }) => {
const path = require(`path`);
const { createPage } = actions;
const projects = path.resolve("src/templates/projects.js");
const defaultPage = path.resolve("src/templates/defaultPage.js");
const projectsSubPages = path.resolve("src/templates/projectsSubPages.js");
return graphql(`
{
allSanityDefaultPage {
edges {
node {
slug
}
}
}
allSanityProjects {
edges {
node {
slug
projectChildPages {
slug
}
}
}
}
}
`).then((result) => {
if (result.errors) {
reporter.panic("failed to create page ", result.errors);
}
result.data.allSanityDefaultPage.edges.forEach(({ node }) => {
createPage({
path: node.slug,
component: defaultPage,
context: {
slug: node.slug,
},
});
});
result.data.allSanityProjects.edges.forEach(({ node }) => {
createPage({
path: node.slug,
component: projects,
context: {
slug: node.slug,
},
});
});
result.data.allSanityProjects.edges.forEach(({ node }) => {
if (node && node.projectChildPages && node.projectChildPages.slug) {
createPage({
path: node.slug + "/" + node.projectChildPages.slug,
component: projectsSubPages,
context: {
slug: node.slug + "/" + node.projectChildPages.slug,
},
});
}
});
});
};
См. Gist для получения дополнительной информации о коде и возврате запроса graphql https://gist.github.com/AndreasJacobsen/cd3fdfd9c4ea5e9f19fe17e4c38b74d2
Я не могу понять, что происходит не так, но, похоже, что-то не так в моем запросе GraphQL в моем шаблоне, хотя я получаю все необходимые данные из этого запроса с помощью GraphiQL Explorer