data
Dgraph Lua API for KosmoKrator Agents
Agent-facing Lua documentation and function reference for the Dgraph KosmoKrator integration.Lua Namespace
Agents call this integration through app.integrations.dgraph.*.
Use lua_read_doc("integrations.dgraph") inside KosmoKrator to discover the same reference at runtime.
Call Lua from the Headless CLI
Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic
Dgraph workflow without starting an interactive agent session.
kosmo integrations:lua --eval 'dump(app.integrations.dgraph.list_schema({}))' --json kosmo integrations:lua --eval 'print(docs.read("dgraph"))' --json
kosmo integrations:lua --eval 'print(docs.read("dgraph.list_schema"))' --json Workflow file
Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.
local dgraph = app.integrations.dgraph
local result = dgraph.list_schema({})
dump(result) kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json integrations:lua exposes app.integrations.dgraph, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.dgraph.default.* or app.integrations.dgraph.work.* when you configured named credential accounts.
MCP-only Lua
If the script only needs configured MCP servers and does not need Dgraph, use the narrower mcp:lua command.
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json Agent-Facing Lua Docs
This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.
Dgraph — Lua API Reference
All tools are accessed via app.integrations.dgraph.{tool_key}({params}).
dgraph_list_schema
List the full GraphQL schema from Dgraph. Returns all types, their fields, and field types. Useful for understanding the overall data model.
Parameters
This tool takes no parameters.
Example
local result = app.integrations.dgraph.dgraph_list_schema()
for _, t in ipairs(result.schema.types) do
print(t.name)
end
dgraph_get_schema
Get the GraphQL schema for a specific type in Dgraph. Returns the type definition including all fields and their types.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
type_name | string | yes | The GraphQL type name to retrieve the schema for |
Example
local result = app.integrations.dgraph.dgraph_get_schema({
type_name = "User"
})
for _, field in ipairs(result.schema.types[1].fields) do
print(field.name .. ": " .. (field.type.name or "unknown"))
end
dgraph_list_types
List all types defined in the Dgraph GraphQL schema. Returns type names for all user-defined and system types available in the database.
Parameters
This tool takes no parameters.
Example
local result = app.integrations.dgraph.dgraph_list_types()
for _, t in ipairs(result.schema.types) do
print(t.name)
end
dgraph_list_indexes
List all indexes defined in the Dgraph schema. Returns types with their fields and directives, allowing you to identify indexed fields and their index types.
Parameters
This tool takes no parameters.
Example
local result = app.integrations.dgraph.dgraph_list_indexes()
for _, t in ipairs(result.schema.types) do
for _, field in ipairs(t.fields or {}) do
for _, dir in ipairs(field.directives or {}) do
if dir.name == "dgraph" then
print(t.name .. "." .. field.name .. " (indexed)")
end
end
end
end
dgraph_get_node
Get a specific node from Dgraph by providing its type and ID. Returns the node data including all populated fields.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
type | string | yes | The GraphQL type of the node (e.g., "User", "Post") |
id | string | yes | The unique ID of the node to retrieve |
Example
local node = app.integrations.dgraph.dgraph_get_node({
type = "User",
id = "0x123"
})
print(node.getUser.id)
print(node.getUser.name)
dgraph_mutate
Execute a GraphQL mutation to add or update data in Dgraph. Provide the full GraphQL mutation string and optional variables.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
mutation | string | yes | The GraphQL mutation string to execute |
variables | object | no | Optional variables object for the mutation |
Example
local result = app.integrations.dgraph.dgraph_mutate({
mutation = [[
mutation AddUser($name: String!, $email: String!) {
addUser(input: [{ name: $name, email: $email }]) {
user {
id
name
}
}
}
]],
variables = {
name = "Alice",
email = "alice@example.com"
}
})
print("Created user: " .. result.addUser.user[1].id)
dgraph_drop_mutation
Execute a GraphQL drop/delete mutation to remove data from Dgraph. Use with caution as this permanently removes data.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
mutation | string | yes | The GraphQL drop/delete mutation string to execute |
variables | object | no | Optional variables object for the mutation |
Example
local result = app.integrations.dgraph.dgraph_drop_mutation({
mutation = [[
mutation DeleteUser($id: ID!) {
deleteUser(filter: { id: [$id] }) {
user {
id
}
}
}
]],
variables = {
id = "0x123"
}
})
print("Deleted user")
dgraph_query
Execute a custom GraphQL query against Dgraph. Provide the full GraphQL query string and optional variables. Supports filtering, pagination, sorting, and nested traversals.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
query | string | yes | The GraphQL query string to execute |
variables | object | no | Optional variables object for the query |
Example
local result = app.integrations.dgraph.dgraph_query({
query = [[
query($name: String) {
queryUser(filter: { name: { eq: $name } }) {
id
name
email
}
}
]],
variables = {
name = "Alice"
}
})
for _, user in ipairs(result.queryUser) do
print(user.name .. " <" .. user.email .. ">")
end
dgraph_get_current_user
Get the current authenticated Dgraph user identity. Verifies the configured bearer token and returns the associated user information.
Parameters
This tool takes no parameters.
Example
local user = app.integrations.dgraph.dgraph_get_current_user()
print("User: " .. (user.currentUser.name or "unknown"))
print("Email: " .. (user.currentUser.email or "unknown"))
Multi-Account Usage
If you have multiple Dgraph accounts configured, use account-specific namespaces:
-- Default account (always works)
app.integrations.dgraph.function_name({...})
-- Explicit default (portable across setups)
app.integrations.dgraph.default.function_name({...})
-- Named accounts
app.integrations.dgraph.production.function_name({...})
app.integrations.dgraph.staging.function_name({...})
All functions are identical across accounts — only the credentials differ.
Raw agent markdown
# Dgraph — Lua API Reference
All tools are accessed via `app.integrations.dgraph.{tool_key}({params})`.
---
## dgraph_list_schema
List the full GraphQL schema from Dgraph. Returns all types, their fields, and field types. Useful for understanding the overall data model.
### Parameters
This tool takes no parameters.
### Example
```lua
local result = app.integrations.dgraph.dgraph_list_schema()
for _, t in ipairs(result.schema.types) do
print(t.name)
end
```
---
## dgraph_get_schema
Get the GraphQL schema for a specific type in Dgraph. Returns the type definition including all fields and their types.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `type_name` | string | yes | The GraphQL type name to retrieve the schema for |
### Example
```lua
local result = app.integrations.dgraph.dgraph_get_schema({
type_name = "User"
})
for _, field in ipairs(result.schema.types[1].fields) do
print(field.name .. ": " .. (field.type.name or "unknown"))
end
```
---
## dgraph_list_types
List all types defined in the Dgraph GraphQL schema. Returns type names for all user-defined and system types available in the database.
### Parameters
This tool takes no parameters.
### Example
```lua
local result = app.integrations.dgraph.dgraph_list_types()
for _, t in ipairs(result.schema.types) do
print(t.name)
end
```
---
## dgraph_list_indexes
List all indexes defined in the Dgraph schema. Returns types with their fields and directives, allowing you to identify indexed fields and their index types.
### Parameters
This tool takes no parameters.
### Example
```lua
local result = app.integrations.dgraph.dgraph_list_indexes()
for _, t in ipairs(result.schema.types) do
for _, field in ipairs(t.fields or {}) do
for _, dir in ipairs(field.directives or {}) do
if dir.name == "dgraph" then
print(t.name .. "." .. field.name .. " (indexed)")
end
end
end
end
```
---
## dgraph_get_node
Get a specific node from Dgraph by providing its type and ID. Returns the node data including all populated fields.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `type` | string | yes | The GraphQL type of the node (e.g., `"User"`, `"Post"`) |
| `id` | string | yes | The unique ID of the node to retrieve |
### Example
```lua
local node = app.integrations.dgraph.dgraph_get_node({
type = "User",
id = "0x123"
})
print(node.getUser.id)
print(node.getUser.name)
```
---
## dgraph_mutate
Execute a GraphQL mutation to add or update data in Dgraph. Provide the full GraphQL mutation string and optional variables.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `mutation` | string | yes | The GraphQL mutation string to execute |
| `variables` | object | no | Optional variables object for the mutation |
### Example
```lua
local result = app.integrations.dgraph.dgraph_mutate({
mutation = [[
mutation AddUser($name: String!, $email: String!) {
addUser(input: [{ name: $name, email: $email }]) {
user {
id
name
}
}
}
]],
variables = {
name = "Alice",
email = "alice@example.com"
}
})
print("Created user: " .. result.addUser.user[1].id)
```
---
## dgraph_drop_mutation
Execute a GraphQL drop/delete mutation to remove data from Dgraph. Use with caution as this permanently removes data.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `mutation` | string | yes | The GraphQL drop/delete mutation string to execute |
| `variables` | object | no | Optional variables object for the mutation |
### Example
```lua
local result = app.integrations.dgraph.dgraph_drop_mutation({
mutation = [[
mutation DeleteUser($id: ID!) {
deleteUser(filter: { id: [$id] }) {
user {
id
}
}
}
]],
variables = {
id = "0x123"
}
})
print("Deleted user")
```
---
## dgraph_query
Execute a custom GraphQL query against Dgraph. Provide the full GraphQL query string and optional variables. Supports filtering, pagination, sorting, and nested traversals.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `query` | string | yes | The GraphQL query string to execute |
| `variables` | object | no | Optional variables object for the query |
### Example
```lua
local result = app.integrations.dgraph.dgraph_query({
query = [[
query($name: String) {
queryUser(filter: { name: { eq: $name } }) {
id
name
email
}
}
]],
variables = {
name = "Alice"
}
})
for _, user in ipairs(result.queryUser) do
print(user.name .. " <" .. user.email .. ">")
end
```
---
## dgraph_get_current_user
Get the current authenticated Dgraph user identity. Verifies the configured bearer token and returns the associated user information.
### Parameters
This tool takes no parameters.
### Example
```lua
local user = app.integrations.dgraph.dgraph_get_current_user()
print("User: " .. (user.currentUser.name or "unknown"))
print("Email: " .. (user.currentUser.email or "unknown"))
```
---
## Multi-Account Usage
If you have multiple Dgraph accounts configured, use account-specific namespaces:
```lua
-- Default account (always works)
app.integrations.dgraph.function_name({...})
-- Explicit default (portable across setups)
app.integrations.dgraph.default.function_name({...})
-- Named accounts
app.integrations.dgraph.production.function_name({...})
app.integrations.dgraph.staging.function_name({...})
```
All functions are identical across accounts — only the credentials differ. local result = app.integrations.dgraph.list_schema({})
print(result) Functions
list_schema Read
List the full GraphQL schema from Dgraph. Returns all types, their fields, and field types. Useful for understanding the overall data model.
- Lua path
app.integrations.dgraph.list_schema- Full name
dgraph.dgraph_list_schema
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
get_schema Read
Get the GraphQL schema for a specific type in Dgraph. Returns the type definition including all fields and their types. Provide the type name to inspect.
- Lua path
app.integrations.dgraph.get_schema- Full name
dgraph.dgraph_get_schema
| Parameter | Type | Required | Description |
|---|---|---|---|
type_name | string | yes | The GraphQL type name to retrieve the schema for. |
list_types Read
List all types defined in the Dgraph GraphQL schema. Returns type names for all user-defined and system types available in the database.
- Lua path
app.integrations.dgraph.list_types- Full name
dgraph.dgraph_list_types
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
list_indexes Read
List all indexes defined in the Dgraph schema. Returns types with their fields and directives, allowing you to identify indexed fields and their index types (hash, exact, term, fulltext, trigram, etc.).
- Lua path
app.integrations.dgraph.list_indexes- Full name
dgraph.dgraph_list_indexes
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
get_node Read
Get a specific node from Dgraph by providing its type and ID. Returns the node data including all populated fields. Use the type name as defined in your GraphQL schema.
- Lua path
app.integrations.dgraph.get_node- Full name
dgraph.dgraph_get_node
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | yes | The GraphQL type of the node (e.g., "User", "Post"). |
id | string | yes | The unique ID of the node to retrieve. |
mutate Write
Execute a GraphQL mutation to add or update data in Dgraph. Provide the full GraphQL mutation string and optional variables. Supports all mutation operations including add, update, and upsert.
- Lua path
app.integrations.dgraph.mutate- Full name
dgraph.dgraph_mutate
| Parameter | Type | Required | Description |
|---|---|---|---|
mutation | string | yes | The GraphQL mutation string to execute. |
variables | object | no | Optional variables object for the mutation. |
drop_mutation Write
Execute a GraphQL drop/delete mutation to remove data from Dgraph. Provide the full GraphQL mutation string for deleting nodes and optional variables. Use with caution as this permanently removes data.
- Lua path
app.integrations.dgraph.drop_mutation- Full name
dgraph.dgraph_drop_mutation
| Parameter | Type | Required | Description |
|---|---|---|---|
mutation | string | yes | The GraphQL drop/delete mutation string to execute. |
variables | object | no | Optional variables object for the mutation. |
query action
Execute a custom GraphQL query against Dgraph. Provide the full GraphQL query string and optional variables. Supports all query operations including filtering, pagination, sorting, and nested traversals.
- Lua path
app.integrations.dgraph.query- Full name
dgraph.dgraph_query
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | yes | The GraphQL query string to execute. |
variables | object | no | Optional variables object for the query. |
get_current_user Read
Get the current authenticated Dgraph user identity. Verifies the configured bearer token and returns the associated user information including ID, name, and email.
- Lua path
app.integrations.dgraph.get_current_user- Full name
dgraph.dgraph_get_current_user
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||