Gatsby 中的多个查询错误“发现多个“根”查询”

Júl*_*mes 6 root reactjs graphql gatsby

要通过本教程创建帖子模板(我在第 4 部分): https: //www.joaopedro.cc/blog-com-gatsby-e-react-parte-4

但是在执行“PostPage”查询时发生错误:

Multiple "root" queries found: "PostPage" and "PostPage".
Only the first ("PostPage") will be registered.

Instead of:

1 | query PostPage {
2 |   markdownRemark {
3 |     #...
4 |   }
5 | }
6 | 
7 | query PostPage {
8 |   markdownRemark {
9 |     #...
10 |   }
11 | }

Do:

1 | query postPageAndPostPage {
2 |   markdownRemark {
3 |     #...
4 |   }
5 |   markdownRemark {
6 |     #...
7 |   }
8 | }
Run Code Online (Sandbox Code Playgroud)

我查看了类似问题的其他答案,据我了解,这是一个区分大小写的问题,但据我所知,一切看起来都是正确的。

我不会出格的。:( 提前致谢!

cor*_*ard 4

这里的错误消息实际上很有帮助,但并没有完全解决问题。

问题是您只能有一个查询,并且可以有多个查询。解决方案是在单个查询中查询所需的所有数据,而不是将其拆分为多个,如错误所示。

唉,你试图通过同一个字段获取我想象的两个不同的数据集,这默认会给你另一个错误。但这里有一个简单的解决方案:使用别名来消除结果中重复的字段名称。

query PostPage {
  firstPost: markdownRemark {
    #...
  }
  secondPost: markdownRemark {
    #...
  }
}
Run Code Online (Sandbox Code Playgroud)