Gatsby: GraphQL 错误未知参数`slug`

创建于 2017-09-10  ·  3评论  ·  资料来源: gatsbyjs/gatsby

嘿大家。 尝试使用高级启动器将内容连接到博客。 我已经从混合中提取了文件系统插件,并试图将示例帖子拉过来。 但是,我目前在启动开发服务器时遇到错误GraphQL Error Unknown argument slug

exports.createPages = ({ graphql, boundActionCreators }) => {
  const { createPage } = boundActionCreators
  return new Promise((resolve, reject) => {
    graphql(
      `
      {
        allContentfulBlogPost(limit: 1000) {
          edges {
            node {
              id
              slug
            }
          }
        }
      }
    `
    )
      .then(result => {
        if (result.errors) {
          reject(result.errors)
        }
        const postPage = path.resolve("src/templates/post.jsx");
        _.each(result.data.allContentfulBlogPost.edges, edge => {
          console.log(edge.node);

          createPage({
            path: `/post/${edge.node.slug}`,
            component: postPage,
            context: {
              id: edge.node.id,
              slug: edge.node.slug
            },
          })
        })
      })
      .then(resolve)
  })
}

我将上下文设置为包含“slug”,如果我理解正确的话,它就是它可用于实际的后组件 graphQL 查询的地方……但它抛出了错误。
这是发生这种情况的一些控制台输出

Fetch Contentful data: 404.350ms
success source and transform nodes — 0.552 s
success building schema — 0.548 s
success createLayouts — 0.055 s
⠁ /xxxxxxx/src/templates/post.jsx
{ id: 'c7juaTIcg6cW2wAGKCQuios', slug: 'test-post' }
success createPages — 0.061 s
success createPagesStatefully — 0.023 s
GraphQL Error Unknown argument `slug`

  file: /Users/joshuaweaver/Documents/JoyfulNoise/joyfulnoiseliving/src/templates/post.jsx

   1 |
   2 |   query BlogPostBySlug($slug: String!) {
>  3 |     allContentfulBlogPost(slug: { eq: $slug }) {
     |                           ^
   4 |       title
   5 |       slug
...

我对 GraphQL 很陌生,所以我可能会在这里遗漏一些明显的东西。 你在这里看到的有什么不寻常的地方吗? 感谢您的关注!

最有用的评论

哦,是的,那个查询不会起作用。 在将查询添加到您的组件之前,请务必在 Graph i QL 中试用您的查询。

“all”用于查询某个类型的所有节点。 没有全部用于查询单个项目。

所有3条评论

节点可能没有 slug 吗?

2017 年 9 月 10 日,星期日,上午 7:17,Josh Weaver通知@ github.com 写道:

嘿大家。 尝试使用高级将内容连接到博客
起动机。 我已经从混合中取出文件系统插件并正在尝试
只需将示例帖子拉过来即可。 但是,我目前正在得到一个
启动开发服务器时出现错误 GraphQL 错误未知参数 slug。

export.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators
返回新的承诺((解决,拒绝)=> {
图ql(
{ allContentfulBlogPost(limit: 1000) { edges { node { id slug } } } }
)
.then(结果 => {
如果(结果。错误){
拒绝(结果。错误)
}
const postPage = path.resolve("src/templates/post.jsx");
_.each(result.data.allContentfulBlogPost.edges, edge => {
控制台日志(边缘节点);

      createPage({
        path: `/post/${edge.node.slug}`,
        component: postPage,
        context: {
          id: edge.node.id,
          slug: edge.node.slug
        },
      })
    })
  })
  .then(resolve)

})
}

我将上下文设置为包含“slug”,如果我理解正确的话,它是
它可用于实际的后期组件 graphQL 查询...
但它抛出了错误。
这是发生这种情况的一些控制台输出

获取内容数据:404.350ms
成功源和转换节点 — 0.552 s
成功构建模式 — 0.548 s
成功 createLayouts — 0.055 秒
⠁ /xxxxxxx/src/templates/post.jsx
{ id: 'c7juaTIcg6cW2wAGKCQuios', slug: 'test-post' }
成功 createPages — 0.061 秒
成功 createPagesStatefully — 0.023 秒
GraphQL 错误未知参数slug

文件:/Users/joshuaweaver/Documents/JoyfulNoise/joyfulnoiseliving/src/templates/post.jsx

1 |
2 | 查询 BlogPostBySlug($slug: String!) {

3 | allContentfulBlogPost(slug: { eq: $slug }) {
| ^
4 | 标题
5 | 蛞蝓
...

我对 GraphQL 很陌生,所以我可能会在这里遗漏一些明显的东西。


您收到此消息是因为您订阅了此线程。
直接回复本邮件,在GitHub上查看
https://github.com/gatsbyjs/gatsby/issues/2069 ,或静音线程
https://github.com/notifications/unsubscribe-auth/AAEVh7fahni3VfI4tz_PphtJPctw2jV5ks5sg2LWgaJpZM4PSM2E
.

好吧,我在 Contentful 中只有一个节点/帖子。

嗯..我最终将查询从allContentfulBlogPost更改contentfulBlogPost并且现在可以使用了......但是,我对 GraphQL 如此陌生,我不确定我是否理解区别。

哦,是的,那个查询不会起作用。 在将查询添加到您的组件之前,请务必在 Graph i QL 中试用您的查询。

“all”用于查询某个类型的所有节点。 没有全部用于查询单个项目。

此页面是否有帮助?
0 / 5 - 0 等级