[英]GraphQL query the same collection
I have a filtered query in GraphQL that return only some specific content , while I want to add this same query but to display all it content .我在 GraphQL 中有一个过滤查询,它只返回一些特定的内容,而我想添加这个相同的查询,但要显示它的所有内容。 I cannot use two similar queries in the same page , eventually I cannot pass this all data that I want , even if I add this query in a component it will cause an error of undefined .
我不能在同一个页面中使用两个相似的查询,最终我无法传递我想要的所有数据,即使我在组件中添加这个查询也会导致未定义的错误。 This is the query :
这是查询:
allPrismicCollection(
sort: {fields: data___collection___text, order: ASC}
limit: $limit
skip: $skip
) {
nodes {
data {
slides {
slide {
document {
... on PrismicSlide {
data {
blogs {
blog {
document {
... on PrismicBlog {
uid
data {
image {
gatsbyImageData(aspectRatio: 1.5)
}
}
}
}
}
}
}
}
}
}
}
}
}
}
and this is the query I want to add as well :这也是我要添加的查询:
allPrismicCollection {
nodes {
data {
collection {
text
}
slides {
slide {
document {
... on PrismicSlide {
id
data {
blogs {
blog {
document {
... on PrismicBlog {
id
data {
tags {
tag
}
}
}
}
}
}
}
}
}
}
}
}
}
}
Any idea how to mix these queries , or maybe to add it independently in components ?!知道如何混合这些查询,或者在组件中独立添加它吗?! Thanks.
谢谢。
I cannot use two similar queries in the same page
我不能在同一页面中使用两个相似的查询
You can as long as you alias them.只要你给它们起别名就可以了。 Like:
喜欢:
result1: allPrismicCollection(
sort: {fields: data___collection___text, order: ASC}
limit: $limit
skip: $skip
) {
nodes {
data {
slides {
slide {
document {
... on PrismicSlide {
data {
blogs {
blog {
document {
... on PrismicBlog {
uid
data {
image {
gatsbyImageData(aspectRatio: 1.5)
}
}
}
}
}
}
}
}
}
}
}
}
}
}
result2: allPrismicCollection {
nodes {
data {
collection {
text
}
slides {
slide {
document {
... on PrismicSlide {
id
data {
blogs {
blog {
document {
... on PrismicBlog {
id
data {
tags {
tag
}
}
}
}
}
}
}
}
}
}
}
}
}
}
The result of each specific query, instead of being inside props.data.allPrismicCollection
will be inside of props.data.result1
and props.data.result2
respectively.每个特定查询的结果,而不是在
props.data.allPrismicCollection
内,将分别在props.data.result1
和props.data.result2
内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.