KosmoKrator

data

Dgraph Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the Dgraph KosmoKrator integration.

9 functions 6 read 2 write API token auth

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.

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

NameTypeRequiredDescription
type_namestringyesThe 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

NameTypeRequiredDescription
typestringyesThe GraphQL type of the node (e.g., "User", "Post")
idstringyesThe 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

NameTypeRequiredDescription
mutationstringyesThe GraphQL mutation string to execute
variablesobjectnoOptional 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 = "[email protected]"
  }
})

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

NameTypeRequiredDescription
mutationstringyesThe GraphQL drop/delete mutation string to execute
variablesobjectnoOptional 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

NameTypeRequiredDescription
querystringyesThe GraphQL query string to execute
variablesobjectnoOptional 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 = "[email protected]"
  }
})

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.

Metadata-Derived Lua Example

local result = app.integrations.dgraph.dgraph_list_schema({})
print(result)

Functions

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.

Operation
Read read
Full name
dgraph.dgraph_list_schema
ParameterTypeRequiredDescription
No parameters.

dgraph_get_schema

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.

Operation
Read read
Full name
dgraph.dgraph_get_schema
ParameterTypeRequiredDescription
type_name string yes The GraphQL type name to retrieve the schema for.

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.

Operation
Read read
Full name
dgraph.dgraph_list_types
ParameterTypeRequiredDescription
No parameters.

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 (hash, exact, term, fulltext, trigram, etc.).

Operation
Read read
Full name
dgraph.dgraph_list_indexes
ParameterTypeRequiredDescription
No parameters.

dgraph_get_node

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.

Operation
Read read
Full name
dgraph.dgraph_get_node
ParameterTypeRequiredDescription
type string yes The GraphQL type of the node (e.g., "User", "Post").
id string yes The unique ID of the node to retrieve.

dgraph_mutate

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.

Operation
Write write
Full name
dgraph.dgraph_mutate
ParameterTypeRequiredDescription
mutation string yes The GraphQL mutation string to execute.
variables object no Optional variables object for the mutation.

dgraph_drop_mutation

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.

Operation
Write write
Full name
dgraph.dgraph_drop_mutation
ParameterTypeRequiredDescription
mutation string yes The GraphQL drop/delete mutation string to execute.
variables object no Optional variables object for the mutation.

dgraph_query

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.

Operation
action action
Full name
dgraph.dgraph_query
ParameterTypeRequiredDescription
query string yes The GraphQL query string to execute.
variables object no Optional variables object for the query.

dgraph_get_current_user

Get the current authenticated Dgraph user identity. Verifies the configured bearer token and returns the associated user information including ID, name, and email.

Operation
Read read
Full name
dgraph.dgraph_get_current_user
ParameterTypeRequiredDescription
No parameters.