首页 > 解决方案 > 如何使用 prismic graphql api 按链接文档/关系的 uid 过滤?

问题描述

我正在尝试按其类别、uid 列出一组文章,并且我假设我必须使用该where查询,但我无法将其用于链接文档。

问题似乎是where只接受字段上的字符串,但在链接文档的情况下,您需要深入挖掘 uid 字段。

我不确定我是否使用了错误的查询,但很难在文档中找到任何内容来帮助我。

我尝试深入研究类别对象:

{
  allDirectoryServices(
    where: { category: { _meta: { uid: "developers" } } }
  ) {
    edges {
      node {
        name
        city
        region
        country
        category {
          ...on DirectoryTaxonomy {
            _meta {
              uid
            }
            name
          }
        }
      }
    }
  }
}

但这会返回一个错误,它需要一个字符串:

"message": "Expected type String, found {_meta: {uid: \"developers\"}}.",
{
  allDirectoryServices(
    where: { category: "developers"}
  ) {
    edges {
      node {
        name
        city
        region
        country
        category {
          ...on DirectoryTaxonomy {
            _meta {
              uid
            }
            name
          }
        }
      }
    }
  }
}

显然,这不会返回任何结果。

标签: graphqlprismic.io

解决方案


我也在 Prismic Slack 群上问过这个问题,得到了他们的回答:

为了通过这样的内容关系/链接字段进行查询,您需要使用文档 ID。

where: { category: "WBsLfioAABNUo9Kk" }

不幸的是,无法通过 UID(或任何其他字段)进行查询。

我想他们很快就会更新他们的文档,因为这不在其中。

感谢棱镜的家伙!


推荐阅读