The Modus Dgraph API allows you to run queries and mutations against a Dgraph database.

Import

To begin, import the dgraph namespace from the SDK:

Dgraph APIs

The APIs in the dgraph namespace are below, organized by category.

We’re constantly introducing new APIs through ongoing development with early users. Open an issue if you have ideas on what would make Modus even more powerful for your next app!

Functions

execute

Execute a Dgraph query or mutation using a Dgraph Request object.

function execute(hostName: string, request: Request): Response;
hostName
string
required

Name of the host, as defined in the manifest.

request
Request
required

A Dgraph Request object, describing the query or mutation to execute.

alterSchema

Alter the schema of a Dgraph database.

function alterSchema(hostName: string, schema: string): string;
hostName
string
required

Name of the host, as defined in the manifest.

schema
string
required

The schema to apply to the Dgraph database.

dropAttr

Drop an attribute from a Dgraph schema.

function dropAttr(hostName: string, attr: string): string;
hostName
string
required

Name of the host, as defined in the manifest.

attr
string
required

The attribute to drop from the Dgraph schema.

dropAll

Drop all data from a Dgraph database.

function dropAll(hostName: string): string;
hostName
string
required

Name of the host, as defined in the manifest.

Objects

Request

A Dgraph request object, used to execute queries and mutations.

class Request {
  constructor(Query: Query | null = null, Mutations: Mutation[] | null = null);
  query: Query = new Query();
  mutations: Mutation[] = [];
}
new dgraph.Request(query, mutations)

Creates a new Request object with the given query and mutations.

The query and mutations fields are optional and default to null.

query
Query

A Dgraph query object.

mutations
Mutation[]

An array of Dgraph mutation objects.

Query

A Dgraph query object, used to execute queries.

class Query {
  constructor(query: string = "", variables: Variables = new Variables());
  query: string = "";
  variables: Map<string, string> = new Map<string, string>();
}
new dgraph.Query(query, variables)

Creates a new Query object with the given query and variables. query is a Dgraph Query Language (DQL) query string, and variables is a Variables object.

query
string

The DQL query to execute.

variables
Map<string, string>

A map of query variables.

Variables

A Variables object used to set query variables in a Dgraph query.

class Variables {
  public set<T>(name: string, value: T): void;
  public toMap(): Map<string, string>;
}
Variables.set(name, value)

Sets a query variable with the given name and value. name is of type string, and value can be of any type.

Variables.toMap()

Returns a map of all query variables set in the Variables object.

Mutation

A Dgraph mutation object, used to execute mutations.

class Mutation {
  constructor(
    public setJson: string = "",
    public delJson: string = "",
    public setNquads: string = "",
    public delNquads: string = "",
    public condition: string = "",
  )
}
new dgraph.Mutation(setJson, delJson, setNquads, delNquads, condition)

Creates a new Mutation object with the given setJson, delJson, setNquads, delNquads, and condition fields.

setJson
string

A JSON string representing the data to set in the mutation.

delJson
string

A JSON string representing the data to delete in the mutation.

setNquads
string

A string representing the data to set in the mutation in NQuads format.

delNquads
string

A string representing the data to delete in the mutation in NQuads format.

condition
string

A string representing the condition query for the mutation.