Skip to main content
@tags: return, output, response, results, projection, formatting

TL;DR

  • Return a list of element: RETURN users
  • Return multiple lists of elements: RETURN users, posts
  • Project specific fields: RETURN users::{ name, age }
  • Return IDs only: RETURN users::ID
  • Exclude specific fields: RETURN users::!{ email }
  • Return scalar values: RETURN count
  • Return literal values: RETURN "success"
  • No payload: RETURN NONE
Note: When using the Python SDK, the return values are wrapped in an array for multiple query calls, so you will need to access the first element of the array to get the result of the first call.

Return elements

  • Schema:
N::User {
    name: String,
    age: U8,
    email: String
}
  • Query:
QUERY GetAllUsers() =>
    users <- N<User>
    RETURN users
  • Output:
{
  "users": [
    { "name": "Alice", "age": 25, "email": "[email protected]" },
    { "name": "Bob", "age": 30, "email": "[email protected]" },
    { "name": "Charlie", "age": 28, "email": "[email protected]" },
  ]
}

Return multiple elements

  • Schema:
N::User {
    name: String,
    age: U8,
    email: String
}

N::Post {
    title: String,
    content: String
}

E::User_to_Post {
    From: User,
    To: Post
}
  • Query:
QUERY GetUserAndPosts(user_id: ID) =>
    user <- N<User>(user_id)
    posts <- user::Out<User_to_Post>
    RETURN user, posts
  • Output:
{
  "user": {"name": "Alice", "age": 25, "email": "[email protected]"},
  "posts": [ 
    {"title": "My First Post", "content": "This is my first blog post!"}, 
    ...,
  ]
}

Include fields

  • Schema:
N::User {
    name: String,
    age: U8,
    email: String
}
  • Query:
QUERY FindUsers() =>
    users <- N<User>::RANGE(0, 10)
    RETURN users::{ name, age }
  • Output:
{
  "users": [
    { "name": "Alice", "age": 25 },
    { "name": "Bob", "age": 30 },
    { "name": "Charlie", "age": 28 }
  ]
}

Return IDs only

  • Schema:
N::User {
    name: String,
    age: U8,
    email: String
}
  • Query:
QUERY FindUserIDs() =>
    users <- N<User>::RANGE(0, 10)
    RETURN users::ID
  • Output:
{
  "users": [
    "c2ca233f-0cd8-4fae-8136-b40593792071",
    "d3db344g-1de9-5gbf-9247-c51604803082",
    "e4ec455h-2ef0-6hcg-0358-d62715914193"
  ]
}

Exclude fields

  • Schema:
N::User {
    name: String,
    age: U8,
    email: String
}
  • Query:
QUERY FindUsersNoEmail() =>
    users <- N<User>::RANGE(0, 10)
    RETURN users::!{ email }
  • Output:
{
  "users": [
    { "name": "Alice", "age": 25 },
    { "name": "Bob", "age": 30 },
    { "name": "Charlie", "age": 28 }
  ]
}

Return nested elements

  • Schema:
N::User {
    name: String,
    age: U8,
    email: String
}

N::Post {
    title: String,
    content: String
}

E::User_to_Post {
    From: User,
    To: Post
}
  • Query:
QUERY FindFriends(user_id: ID) =>
    user <- N<User>(user_id)
    posts <- user::Out<User_to_Post>::RANGE(20)
    RETURN user::|u|{
        userID: u::ID,
        posts: posts::{
            postID: ID,
            creatorID: u::ID,
            ..
        }
    }
  • Output:
{
  "user": {
    "userID": "c2ca233f-0cd8-4fae-8136-b40593792071",
    "posts": [
      {
        "postID": "d3db344g-1de9-5gbf-9247-c51604803082",
        "creatorID": "c2ca233f-0cd8-4fae-8136-b40593792071",
        "title": "My First Post",
        "content": "This is my first blog post!"
      },
      {
        "postID": "e4ec455h-2ef0-6hcg-0358-d62715914193",
        "creatorID": "c2ca233f-0cd8-4fae-8136-b40593792071",
        "title": "Weekend Plans",
        "content": "Planning to explore the city."
      }
    ]
  }
}

Return scalar values

  • Schema:
N::User {
    name: String,
    age: U8,
    email: String
}
  • Query:
QUERY CountUsers() =>
    user_count <- N<User>::COUNT
    RETURN user_count
  • Output:
{
  "user_count": 42
}

Return literal values

  • Schema:
N::City {
    name: String,
    population: U32
}
  • Query:
QUERY DeleteCity(city_id: ID) =>
    DROP N<City>(city_id)
    RETURN "success"
  • Output:
{
  "result": "success"
}

Return no payload

  • Schema:
N::City {
    name: String,
    population: U32
}
  • Query:
QUERY DeleteCityQuietly(city_id: ID) =>
    DROP N<City>(city_id)
    RETURN NONE
  • Output:
{}