Dgraph-js how to make schema queries

Hello everybody! I’m completely new to dgraph so I apologise for the newbie question.

Right now I’m trying to set up a dgraph database which communicates with the clients through nodejs. As such I’ve installed dgraph-js (GitHub - dgraph-io/dgraph-js: Official Dgraph JavaScript client)

I’ve managed to get it to query the database and edit it, but I’d also like to get schema information.

Within the ratel interface I can run:

schema(pred: [name]) {

Or just

schema {}

And I get the expected output. From my nodejs server I can run:

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

And get the fetched result, but if I try:

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

I get an empty result. 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 only provides so much information…

you can use


Oooh that looks interesting! Is there a place I can learn all of the functions available to me?

Unfortunately no, just exploring the code, readme and tests files.

Thank you very much Michel! When poring through the github code again I realise I wasn’t properly importing the d.ts files into my project, but now I have everything working smoothly along with code completion, which helps a great deal.

I don’t know what you guys think about stack overflow, but I asked this question on there (to no avail). Maybe you’d like to put your answer there for some reputation and to increase dgraph’s presence on that site?

The question is here:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.