Node.js 出现问题,查询被留在编译代码中

Node.js 出现问题,查询被留在编译代码中,node.js,reactjs,graphql,gatsby,gatsby-plugin-mdx,Node.js,Reactjs,Graphql,Gatsby,Gatsby Plugin Mdx,通过关注YouTube开始学习盖茨比。我遵循了教程中所示的每个步骤。所以我在创建帖子列表页面的阶段 文章列表页面将有3篇文章,另一篇将通过分页提供。它将按降序排序 我得到一个错误,如下所示: function graphql() { > 93 | throw new Error( | ^ 94 | `It appears like Gatsby is misconfigured. Gatsby related \`graphql\` calls `

通过关注YouTube开始学习盖茨比。我遵循了教程中所示的每个步骤。所以我在创建帖子列表页面的阶段

文章列表页面将有3篇文章,另一篇将通过分页提供。它将按降序排序

我得到一个错误,如下所示:

function graphql() {
> 93 |   throw new Error(
     |        ^
  94 |     `It appears like Gatsby is misconfigured. Gatsby related \`graphql\` calls ` +
  95 |       `are supposed to only be evaluated at compile time, and then compiled away. ` +
  96 |       `Unfortunately, something went wrong and the query was left in the compiled code.\n\n` +
gatsby-node.js文件:

exports.createPages = async function({actions, graphql}){
    const {data} = await graphql(`
        query {
            allMdx(sort: {fields: frontmatter___date, order: DESC}) {
                edges {
                    node {
                    frontmatter {
                        slug
                    }
                    id
                    }
                }
            }
        }
    `)

    //Create paginated pages for posts
    const postPerPage = 3

    const numPages = Math.ceil(data.allMdx.edges.length / postPerPage)

    Array.from({ length: numPages }).forEach((_, i) => {
        actions.createPage({
            path: i === 0 ? `/` : `/${ i+1 }`,
            component: require.resolve("./src/templates/allPosts.js"),
            context: {
                limit: postPerPage,
                skip: i * postPerPage,
                numPages, 
                currentPage: i + 1,
            },
        })
    })

    // //Create Single blog posts
    // data.allMdx.edges.forEach(edge => {
    //     const slug = edge.node.frontmatter.slug,
    //     const id = edge.node.id
    //     actions.createPages({
    //         path: slug,
    //         component: require.resolve(`./src/templates/singlePost.js`),
    //         context: {id},
    //     })
    // })

}
allPosts.js文件:

import React from "react"
import {graphql} from "gatsby"
import {Container, Content, ContentCard, FeatureImage, Pagination} from "../components"
import {H1, P} from "../elements"

const allPosts = ({pageContext, data}) => {
    const {currentPage, numPages} = pageContext
    const isFirst = currentPage === 1
    const isLast = currentPage === numPages
    const prevPage = currentPage - 1 === 1 ? "/" : `/${currentPage -1}`
    const nextPage = `/${currentPage + 1}`

    const posts = data.allMdx.edges

    return (
        <Container>
            <FeatureImage />
            <Content>
                <H1 textAlign="center" margin="0 0 1rem 0">
                    Elit rhoncus tellus proin parturient.
                </H1>
                <P color="dark2" textAlign="center">
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Adipiscing volutpat risus quis lorem pulvinar et pulvinar sit dictum. Eget orci, orci in congue cursus nulla tincidunt facilisi.
                </P>
                {posts.map(post => (
                    <ContentCard 
                        key={post.node.frontmatter.slug}
                        date={post.node.frontmatter.date}
                        title={post.node.frontmatter.title}
                        excerpt={post.node.frontmatter.excerpt}
                        slug={post.node.frontmatter.slug}
                    />
                ))}
            </Content>
            <Pagination 
                isFirst={isFirst}
                isLast={isLast}
                prevPage={prevPage}
                nextPage={nextPage}                
            />
        </Container>
    )
}

export default allPosts

export const pageQuery = graphql(`
    query AllPostsQuery($skip: Int!, $limit:Int!){
        allMdx(sort: {fields: frontmatter___date, order: DESC}, skip: $skip, limit: $limit) {
            edges {
                node {
                frontmatter {
                    slug
                    title
                    date(formatString: "MMMM DD, YYYY")
                    excerpt
                }
                }
            }
        }
    }
`)
从“React”导入React
从“盖茨比”导入{graphql}
从“./components”导入{容器、内容、内容卡、功能图像、分页}
从“./元素”导入{H1,P}
const allPosts=({pageContext,data})=>{
常量{currentPage,numPages}=pageContext
常量isFirst=currentPage==1
常量isLast=currentPage==numPages
const prevPage=currentPage-1==1?“/”:`/${currentPage-1}`
const nextPage=`/${currentPage+1}`
const posts=data.allMdx.edges
返回(
产时腹股沟突出。

同侧的奥雷姆·多洛·塞特,是一位杰出的献祭者。同侧的奥雷姆·普尔维纳和普尔维纳的奥雷姆·塞特·奥雷姆·塞特·奥雷姆·塞特·奥雷姆·塞特·塞特。奥雷姆·奥雷姆·塞特,奥雷姆·塞特·奥雷姆,在康格河中的奥雷姆·卡苏斯·努尔·塞特·塞特。

{posts.map(post=>( ))} ) } 导出默认的allpost export const pageQuery=graphql(` 查询AllPostsQuery($skip:Int!,$limit:Int!){ allMdx(排序:{字段:frontmatter\uuuuuu日期,顺序:DESC},skip:$skip,limit:$limit){ 边缘{ 节点{ 前沿物质{ 鼻涕虫 标题 日期(格式字符串:“MMMM DD,YYYY”) 节选 } } } } } `)
在allPosts.js中,查询应该是这样的graphql
{your\u query}
而不是graphql(
{your\u query}


是盖茨比节点查询问题的原因还是模板中的问题?@FerranBuireu,因此我添加了模板文件。希望这有助于找到问题所在。我真的不知道是什么导致了这个问题。如果不进行调试,很难帮助和猜测是哪个查询导致了这个问题。请尝试删除/注释模板查询,以检查项目是否仍在生成。@FerranBuireu请检查模板查询。在教程中,页面/index.js被删除。将替换为allPosts.js。如果需要,您可以在pages文件夹中找到index.js文件,格式为.txt。@FerranBuireu我曾尝试添加和删除注释,但没有成功。
export const pageQuery = graphql`
    query AllPostsQuery($skip: Int!, $limit:Int!){
        allMdx(sort: {fields: frontmatter___date, order: DESC}, skip: $skip, limit: $limit) {
            edges {
                node {
                frontmatter {
                    slug
                    title
                    date(formatString: "MMMM DD, YYYY")
                    excerpt
                }
                }
            }
        }
    }
`