You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过DQL mutation添加的Dgraph数据无法通过GraphQL访问问题求助

问题解决方案

核心原因

Dgraph GraphQL 层查询时会自动过滤不符合类型定义规则的节点,你通过 DQL 插入的数据未满足 GraphQL 层的校验条件,因此无法被查询到。

具体修复要求

你在执行 DQL Mutation 时需要满足以下所有规则:

  • 必须为节点显式设置 dgraph.type 字段,值固定为 Product,用于让 GraphQL 层识别节点所属类型
  • 必须完整赋值所有 GraphQL Schema 中标记为非空(带!)的字段:Product.name、Product.slug、Product.created_at、Product.updated_at,缺少任意一个非空字段都会被 GraphQL 查询过滤
  • 所有字段的 predicate 名称必须和你定义的保持一致,和 GraphQL Schema 中 @dgraph(pred) 的配置匹配

正确DQL Mutation示例

JSON格式(dgo支持直接传入)

{
  "set": [
    {
      "dgraph.type": "Product",
      "Product.name": "product 2",
      "Product.slug": "prod-2",
      "Product.image": "https://example.com/prod2.jpg",
      "Product.created_at": "2021-10-05T06:37:57Z",
      "Product.updated_at": "2021-10-05T06:37:57Z"
    }
  ]
}

RDF格式

_:prod2 <dgraph.type> "Product" .
_:prod2 <Product.name> "product 2" .
_:prod2 <Product.slug> "prod-2" .
_:prod2 <Product.created_at> "2021-10-05T06:37:57Z" .
_:prod2 <Product.updated_at> "2021-10-05T06:37:57Z" .
_:prod2 <Product.image> "https://example.com/prod2.jpg" .

按上述规则插入数据后,再执行你提供的 GraphQL 查询即可返回新增的 Product 数据。

内容的提问来源于stack exchange,提问作者Panagiotis Koursaris

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 01:09:00