While each Modus SDK offers similar capabilities, the APIs and usage may vary between languages.Modus Dgraph APIs documentation is available on the following pages:
- AssemblyScript Dgraph APIs
- Go Dgraph APIs(this page)
Import
To begin, import thedgraph package from the SDK:
Dgraph APIs
The APIs in thedgraph package are below, organized by category.
We’re constantly introducing new APIs through ongoing development with early
users. Please open an issue if
you have ideas on what would make Modus even more powerful for your next app!
Functions
AlterSchema
Alter the schema of a Dgraph database.Name of the connection, as defined in the
manifest.
The schema to apply to the Dgraph database.
DropAll
Drop all data from a Dgraph database.Name of the connection, as defined in the
manifest.
DropAttr
Drop an attribute from a Dgraph schema.Name of the connection, as defined in the
manifest.
The attribute to drop from the Dgraph schema.
EscapeRDF
Ensures proper escaping of RDF string literals.The RDF string literal to escape.
ExecuteMutations
Execute one or more mutations, without a filtering query.If you need to filter the mutations based on a query, use the
ExecuteQuery function instead, and pass the mutations after
the query.Name of the connection, as defined in the
manifest.
ExecuteQuery
Execute a DQL query to retrieve data from a Dgraph database. Also used to execute a filtering query and apply one or more mutations to the result of the query.If you need apply mutations without a filtering query, use the
ExecuteMutations function instead.Name of the connection, as defined in the
manifest.
Optional parameters specifying pointers to one or more
Mutation
objects to execute on the nodes matched by the query.NewMutation
Creates a newMutation object.
NewQuery
Creates a newQuery object from a DQL query string.
The DQL query to execute.
Types
Mutation
A Dgraph mutation object, used to execute mutations.A JSON string representing the data to set in the mutation.
A JSON string representing the data to delete in the mutation.
A string representing the data to set in the mutation in RDF N-Quads format.
A string representing the data to delete in the mutation in RDF N-Quads
format.
A string representing the condition query for the mutation, as a DQL
@if
directive.A string representing the condition query for the mutation, as a DQL
@if
directive.WithSetJson(json)
Sets the
SetJson field of the mutation to the given json string. Returns
the Mutation object to allow for method chaining.WithDelJson(json)
Sets the
DelJson field of the mutation to the given json string. Returns
the Mutation object to allow for method chaining.WithSetNquads(nquads)
Sets the
SetNquads field of the mutation to the given nquads string.
Returns the Mutation object to allow for method chaining.WithDelNquads(nquads)
Sets the
DelNquads field of the mutation to the given nquads string.
Returns the Mutation object to allow for method chaining.WithCondition(cond)
Sets the
condition field of the mutation to the given cond string, which
should be a DQL @if directive. Returns the Mutation object to allow for
method chaining.Query
A Dgraph query object, used to execute queries.The DQL query to execute.
A map of query variables, with values encoded as strings.
WithVariable(name, value)
Sets a query variable with the given
name and value. name is of type
string, and value can be a string, number, or boolean.Returns the *Query object to allow for method chaining.The
WithVariable method is the preferred way to set query variables in a
Query object, and allows for fluent method chaining to add multiple variables.
For example:Request
A Dgraph request object, used to execute queries and mutations.This object was used by the
Execute function, which has been replaced by the
ExecuteQuery and ExecuteMutations
functions. You should no longer need to create a Request object directly.