GraphQl查询相同的集合

发布于 2025-02-09 04:59:28 字数 1774 浏览 2 评论 0原文

我在GraphQL中有一个过滤的查询,该查询仅返回一些特定的内容,而我想添加相同的查询,但要显示所有IT内容。我不能在同一页面中使用两个类似的查询,最终我也无法传递我想要的所有数据,即使我在组件中添加了此查询,也会导致未定义的错误。 这是查询:

  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)
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }

这也是我要添加的查询:

  allPrismicCollection {
    nodes {
      data {
          collection {
          text
        }
        slides {
          slide {
            document {
              ... on PrismicSlide {
                id
                data {
                  blogs {
                    blog {
                      document {
                        ... on PrismicBlog {
                          id
                          data {
                            tags {
                              tag
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      
      }
    }
  }

任何想法如何混合这些查询,或者可能在组件中独立添加?! 谢谢。

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 . 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烈酒灼喉 2025-02-16 04:59:28

我不能在同一页面中使用两个类似的查询

只要您别名它们。如:

  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
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      
      }
    }
  }

每个特定查询的结果,而不是在props.data.allprismcollection中,将在props.data.result1props.data.result2分别。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文