【问题标题】:How can I filter by uid of a linked document / relationship using the prismic graphql api?如何使用 prismic graphql api 按链接文档/关系的 uid 过滤?
【发布时间】:2019-08-17 23:31:56
【问题描述】:

我正在尝试按类别和 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
          }
        }
      }
    }
  }
}

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

【问题讨论】:

    标签: graphql prismic.io


    【解决方案1】:

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

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

    where: { category: "WBsLfioAABNUo9Kk" }

    很遗憾,无法通过 UID(或任何其他字段)进行查询。

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

    感谢 Prismic 的人!

    【讨论】:

      猜你喜欢
      • 2019-04-08
      • 1970-01-01
      • 2019-02-10
      • 2020-03-08
      • 1970-01-01
      • 2020-10-15
      • 2020-08-02
      • 2023-03-19
      • 2023-03-09
      相关资源
      最近更新 更多