Adding Logic to Queries
Use RapidQL to make smarter request with embeded logic
RapidQL let's you bake logic into your queried, in the form of @if(), @elseif() and @else directives.
The @if statement
The following statement will check if the variable a in the context is equal to the string "hello", and only if so it'll print the value of a:
{
@if(val1: "hello", val2:a, comparison:"==") {
a
}
}
Shorthads
Some @if operators have a short hand. For instance, instead of typing:
{
@if(val1: "hello", val2:a, comparison:"==") {
a
}
}
You can type:
{
@equal(val1: "hello", val2:a) {
a
}
}
Elseif, Else
After an initial @if (or shorthand) expression, you can add an @elseif or @else block. For instance:
{
@if(val1: "hello", val2:a, comparison:"==") {
a
} @elseif (val1: "hello", val2:b, comparison:"==") {
b
} @else () {
c
}
}
Updated almost 5 years ago