首页 > 解决方案 > DGraph-js,如何运行模式查询?

问题描述

我是 Dgraph 的新手,我对 dgraph-js 的一个简单问题感到头疼。我什至仔细研究了 github 源代码,但我显然错过了我正在寻找的东西。

在 dgraph-ratel 界面中,我可以运行以下查询:

schema(pred: [name]) {
  type
  index
}

甚至只是

schema {}

获取有关数据库的架构信息。但是在 dgraph-js 中,如果我使用查询事务,它对于普通查询可以正常工作:

const res = await this.connection.newTxn().query(`query {
    getData(func: regexp(name, /.*mic+.*/i)) {
        name
    }
}`);
const data = res.getJson();

但运行以下内容:

const res = await this.connection.newTxn().query(`schema {}`);
const data = res.getJson();

返回一个空对象。我怀疑我不应该使用 newTxn().query() 而是其他东西。它应该是一个新的 dGraph.Operation() 吗?或者也许是别的什么?我在哪里可以看到我可以使用的所有功能?dgraph-js ( https://github.com/dgraph-io/dgraph-js ) 上的自述文件只提供了这么多信息......

标签: node.jsdgraph

解决方案



推荐阅读