Simple Remappings

Sometimes, you may want to rename a property that is returned from a traversal. You can access properties of an item by using the name of the property as defined in the schema.

::{ new_name: property_name }

You can use the name directly, or if you want to be more explicit, or in cases where there may be name clashes, you can use the _:: operator.

Example: Direct Access

QUERY findUsers() =>
    users <- N<User>::RANGE(0, 10)
    RETURN users::{
        userID: ID, 
    }

Example: Explicit Access

QUERY findUsers() =>
    users <- N<User>::RANGE(0, 10)
    RETURN users::{
        givenName: _::{name}
    }

Nested Mappings

If you want to access a propertis that traverse from the selected element, you can use the nested variable to continue the traversal. These nested mappings work similarly to closures in rust or anonymous functions in javascript.

  • e.g. |a| { a + 1 } in rust or (a) => { a + 1 } in javascript.

We lean heavily on the rust syntax style for nested remappings. The following is an overview of the syntax:

::|item_name|{
            field: item_name::traversal,
            new_field: other::{
                nested_field: item_name::ID, // here we access the ID from the outer scope
                ..
            },
        }

The important thing to note here, is that if we were to access the ID like we have shown previously: nested_field: ID. This ID would would be the ID of the other item, not the item_name item due to the tighter scope.

Example:

QUERY findFriends(userID: String) =>
  user <- N<User>(userID)
  posts <- user::Out<Posts>::RANGE(20)
  RETURN user::|usr|{
            posts: posts::{
                postID: ID, // accesses the `postID` property from each `posts`
                creatorID: usr::ID, // accesses the `ID` property from each `usr` and maps it to `creatorID`
                ..
            },
        }