Retrieving schema?

Moved from GitHub dgraph-js/20

Posted by jeffkhull:

Modifying the schema with op.setSchema … client.alter(op) works great.

However, how can I retrieve the dgraph schema? I tried passing a query of the form:

schema {
...
}

But it doesn’t return results, I assume because a schema query isn’t supported by the Txn.query method?

pawanrawal commented :

You can retrieve the schema using the /query endpoint. The result would be in the Schema field.

jeffkhull commented :

Thanks @pawanrawal. To clarify, can I do this with the js client or only the HTTP endpoint?

pawanrawal commented :

Looks like we just return the JSON result from the client.

@gpahal could we check if Schema field has a non-empty response if it does then convert it to JSON and return otherwise return the JSON response? This should be safe to do because we don’t allow schema{} with other queries so we can’t have both.

gpahal commented :

You can do this with the client. Just use the Response#getSchemaList() method.

jeffkhull commented :

@gpahal got it, thanks!