Expression Result
This field available in PRO
version only.
The purpose of this field is to create synthetic fields based on data from another fields or to modify the shape of resulted json by writing expressions.
Examples
How to create custom field for current_user based on user display name and email.
- Query
- Result
query {
current_user {
name: display_name @private
email: user_email @private
user_info: expression_result(expression: "{{name ~ '(email: ' ~ email ~ ')'}}")
}
}
{
"current_user": {
"user_info": "Volodymyr Denchyk(email: [email protected])"
}
}
How to transform the shape of resulted json.
Let's pretend the situation we need to get such json in dynamic data:
{
"post": {
"title": "post title",
"content": "post content",
"image": "https://builderius.io/some_image.png"
}
}
Ok, let's write the query:
- Query
- Result
query {
post: queried_post {
title: post_title
content: post_content
image: featured_image {
file_url
}
}
}
{
"post": {
"title": "post title",
"content": "post content",
"image": {
"file_url": "https://builderius.io/some_image.png"
}
}
}
As we can see - the result is not what we want. Even aliases didn't help.
So let's use field expression_result
to modify the shape of our json.
- Query
- Result
query {
post: queried_post {
title: post_title
content: post_content
featured_image @private {
file_url
}
image: expression_result(expression: "{{{featured_image.file_url}}}")
}
}
{
"post": {
"title": "post title",
"content": "post content",
"image": "https://builderius.io/some_image.png"
}
}