【问题标题】:Attempting to query with graphql where id is尝试使用 id 所在的 graphql 进行查询
【发布时间】:2021-09-05 14:00:42
【问题描述】:

我需要在 id 为 {id} 的 Strapi/gatsby 中使用 graphql 获取查询。 根据文档found here,您可以这样查询:

{
  allStrapiArticle {
    edges {
      node {
        id
        title
        content
      }
    }
  }
}

这行得通,我可以查询,但是我只想获得一篇 id 为 {id} 的文章;

我试过了:

    {
  allStrapiArticle(id: "4") {
    edges {
      node {
        id
        title
        content
      }
    }
  }
}

还有:

{
  allStrapiArticle {
    edges {
      node(id: "4") {
        id
        title
        content
      }
    }
  }
}

以上两个都给我一个错误。知道如何实现这一目标吗?

【问题讨论】:

  • 如果您只使用{node(id: "4") {... on Article { id title content } }} 而不使用所有其他内容,它是否有效?

标签: graphql gatsby strapi


【解决方案1】:

用途:

    {
  allStrapiArticle(filter: {id: {eq: "4" }}) {
    edges {
      node {
        id
        title
        content
      }
    }
  }
}

elemMatch 过滤器也可能对您的用例有用。

查看localhost:8000/___graphql 游乐场以测试您的查询和过滤器。

更多参考资料:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-27
    • 2019-10-22
    • 1970-01-01
    • 2020-11-16
    • 2019-09-22
    • 2021-06-30
    • 2018-08-03
    • 1970-01-01
    相关资源
    最近更新 更多