DGraph-js, how to run a schema query?

517 views Asked by At

I'm new to Dgraph and am bashing my head against a simple issue with dgraph-js. I've even pored through the github sourcecode but I've clearly missed what I'm looking for.

Within the dgraph-ratel interface I can run this query:

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

or even just

schema {}

to get schema information about the database. But within dgraph-js if I use the query transaction, it works fine for normal queries:

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

but running the following:

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

returns an empty object. I suspect that I shouldn't be using newTxn().query() but something else. Should it be a new dGraph.Operation()? Or maybe something else? Where can I see all the functions available to me? The readme on the dgraph-js (https://github.com/dgraph-io/dgraph-js) only provides so much information...

1

There are 1 answers

0
Michel Conrado Diz On BEST ANSWER