> ## Documentation Index
> Fetch the complete documentation index at: https://helix-digitalocean.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Property Additions

> Add computed properties and derived values to query results by combining schema fields and traversal results to enrich query responses

```rust theme={null}
::{
    <new_property>: <schema_field>,
    <computed_property>: <traversal_expression>
}
```

<Note>
  Property additions allow you to compute derived values and add metadata to your query results without modifying the underlying schema.
</Note>

<Warning>
  When using the SDKs or curling the endpoint, the query name must match what is defined in the `queries.hx` file exactly.
</Warning>

### Example 1: Adding computed properties with traversals

<CodeGroup>
  ```rust Query focus={1-6} [expandable] theme={null}
  QUERY GetUserDetails () =>
      users <- N<User>::RANGE(0, 5)
      RETURN users::{
          userID: ID,
          followerCount: _::In<Follows>::COUNT
      }

  QUERY CreateUser (name: String, age: U8) =>
      user <- AddN<User>({
          name: name,
          age: age
      })
      RETURN user

  QUERY CreateFollow (follower_id: ID, following_id: ID) =>
      follower <- N<User>(follower_id)
      following <- N<User>(following_id)
      AddE<Follows>::From(follower)::To(following)
      RETURN "Success"
  ```

  ```rust Schema theme={null}
  N::User {
      name: String,
      age: U8
  }

  E::Follows {
      From: User,
      To: User
  }
  ```
</CodeGroup>

Here's how to run the query using the SDKs or curl

<CodeGroup>
  ```python Python [expandable] theme={null}
  from helix.client import Client

  client = Client(local=True, port=6969)

  users = [
      {"name": "Alice", "age": 25},
      {"name": "Bob", "age": 30},
      {"name": "Charlie", "age": 28},
      {"name": "Diana", "age": 22},
  ]

  user_ids = []
  for user in users:
      result = client.query("CreateUser", user)
      user_ids.append(result[0]["user"]["id"])

  for i in range(1, len(user_ids)):
      client.query("CreateFollow", {
          "follower_id": user_ids[i],
          "following_id": user_ids[0]
      })

  result = client.query("GetUserDetails", {})
  print("User details with follower count:", result)
  ```

  ```rust Rust [expandable] theme={null}
  use helix_rs::{HelixDB, HelixDBClient};
  use serde_json::json;

  #[tokio::main]
  async fn main() -> Result<(), Box<dyn std::error::Error>> {
      let client = HelixDB::new(Some("http://localhost"), Some(6969), None);

      let users = vec![
          ("Alice", 25),
          ("Bob", 30),
          ("Charlie", 28),
          ("Diana", 22),
      ];

      let mut user_ids = Vec::new();
      for (name, age) in &users {
          let result: serde_json::Value = client.query("CreateUser", &json!({
              "name": name,
              "age": age,
          })).await?;
          user_ids.push(result["user"]["id"].as_str().unwrap().to_string());
      }

      for i in 1..user_ids.len() {
          let _follow: serde_json::Value = client.query("CreateFollow", &json!({
              "follower_id": user_ids[i],
              "following_id": user_ids[0]
          })).await?;
      }

      let result: serde_json::Value = client.query("GetUserDetails", &json!({})).await?;
      println!("User details with follower count: {result:#?}");

      Ok(())
  }
  ```

  ```go Go [expandable] theme={null}
  package main

  import (
      "fmt"
      "log"

      "github.com/HelixDB/helix-go"
  )

  func main() {
      client := helix.NewClient("http://localhost:6969")

      users := []map[string]any{
          {"name": "Alice", "age": uint8(25)},
          {"name": "Bob", "age": uint8(30)},
          {"name": "Charlie", "age": uint8(28)},
          {"name": "Diana", "age": uint8(22)},
      }

      var userIDs []string
      for _, user := range users {
          var created map[string]any
          if err := client.Query("CreateUser", helix.WithData(user)).Scan(&created); err != nil {
              log.Fatalf("CreateUser failed: %s", err)
          }
          userIDs = append(userIDs, created["user"].(map[string]any)["id"].(string))
      }

      for i := 1; i < len(userIDs); i++ {
          followPayload := map[string]any{
              "follower_id":  userIDs[i],
              "following_id": userIDs[0],
          }
          var follow map[string]any
          if err := client.Query("CreateFollow", helix.WithData(followPayload)).Scan(&follow); err != nil {
              log.Fatalf("CreateFollow failed: %s", err)
          }
      }

      var result map[string]any
      if err := client.Query("GetUserDetails", helix.WithData(map[string]any{})).Scan(&result); err != nil {
          log.Fatalf("GetUserDetails failed: %s", err)
      }

      fmt.Printf("User details with follower count: %#v\n", result)
  }
  ```

  ```typescript TypeScript [expandable] theme={null}
  import HelixDB from "helix-ts";

  async function main() {
      const client = new HelixDB("http://localhost:6969");

      const users = [
          { name: "Alice", age: 25 },
          { name: "Bob", age: 30 },
          { name: "Charlie", age: 28 },
          { name: "Diana", age: 22 },
      ];

      const userIds: string[] = [];
      for (const user of users) {
          const result = await client.query("CreateUser", user);
          userIds.push(result.user.id);
      }

      for (let i = 1; i < userIds.length; i++) {
          await client.query("CreateFollow", {
              follower_id: userIds[i],
              following_id: userIds[0]
          });
      }

      const result = await client.query("GetUserDetails", {});
      console.log("User details with follower count:", result);
  }

  main().catch((err) => {
      console.error("GetUserDetails query failed:", err);
  });
  ```

  ```bash Curl [expandable] theme={null}
  curl -X POST \
    http://localhost:6969/CreateUser \
    -H 'Content-Type: application/json' \
    -d '{"name":"Alice","age":25}'

  curl -X POST \
    http://localhost:6969/CreateUser \
    -H 'Content-Type: application/json' \
    -d '{"name":"Bob","age":30}'

  curl -X POST \
    http://localhost:6969/CreateUser \
    -H 'Content-Type: application/json' \
    -d '{"name":"Charlie","age":28}'

  curl -X POST \
    http://localhost:6969/CreateUser \
    -H 'Content-Type: application/json' \
    -d '{"name":"Diana","age":22}'

  curl -X POST \
    http://localhost:6969/CreateFollow \
    -H 'Content-Type: application/json' \
    -d '{"follower_id":"<bob_id>","following_id":"<alice_id>"}'

  curl -X POST \
    http://localhost:6969/CreateFollow \
    -H 'Content-Type: application/json' \
    -d '{"follower_id":"<charlie_id>","following_id":"<alice_id>"}'

  curl -X POST \
    http://localhost:6969/CreateFollow \
    -H 'Content-Type: application/json' \
    -d '{"follower_id":"<diana_id>","following_id":"<alice_id>"}'

  curl -X POST \
    http://localhost:6969/GetUserDetails \
    -H 'Content-Type: application/json' \
    -d '{}'
  ```
</CodeGroup>
