【问题标题】:GraphQL "$id" of required type "Int!" was not provided所需类型“Int!”的 GraphQL“$id”没有提供
【发布时间】:2020-08-24 05:03:33
【问题描述】:

我的代码有一些问题,我正在使用 Gatsby 和 Gatsby Awesome Pagination,

所以我不知道发生了什么,因为 gatsby develop 正在工作,但是当我使用时

gatsby build 上面写着

您的 GraphQL 查询中有一个错误: 所需类型“Int!”的变量“$id”没有提供。

这是我在 gatsby-node.js 中的代码

  const BlogPosts = result.data.allWordpressPost.edges
  paginate({
    createPage, 
    items: BlogPosts, 
    itemsPerPage: 10,
    itemsPerFirstPage: 10,
    pathPrefix: '/blog',
    component: path.resolve('./src/pages/blog.js'), 
  })
  BlogPosts.forEach(post => {
    createPage({
      path: `/${post.node.slug}`,
      component: BlogSinglePage,
      context: {
        id: post.node.wordpress_id,
      },
    })

  })

这是我在 Blog.js 中的代码



export const query = graphql`
  query ($skip: Int!, $limit: Int!) {
    allWordpressPost(
      skip: $skip 
      limit: $limit 
    ) 
    {
      edges {
        node {
          wordpress_id
          title
          excerpt
          slug
          date(formatString: "YYYY-MM-DD")
          categories {
            name
            slug
          }
          featured_media {
            source_url
          }
        }
      }
    }
  }
`

你能告诉我我做错了什么

谢谢!!!

【问题讨论】:

    标签: graphql gatsby


    【解决方案1】:

    “src/pages”中不是你的“Blog.js”吗?

    由于 Gatsby 核心自动将“src/pages”中的 react 组件转换为带有 url 的页面,我建议您将“Blog.js”移动到“src/templates”

    【讨论】:

      猜你喜欢
      • 2021-06-03
      • 2019-05-29
      • 2019-05-01
      • 2020-10-18
      • 2021-07-18
      • 2021-03-13
      • 2017-06-06
      • 1970-01-01
      • 2020-11-04
      相关资源
      最近更新 更多