Don't understand if-else statement syntax error


#1

I have this migrator script that I wrote :
match
$movie isa movie has movie_id <movie_id>;
$user isa user has user_id <user_id>;
insert
(watched_movie: $movie, movie_watcher: $user) isa movie_watched;

    if ( <rating> == "-1")
    do { 
        (unrated_movie: $movie, movie_watcher: $user) isa movie_not_rated;
    };
    else { 
        (rated_movie: $movie, movie_watcher: $user) isa movie_rated
        has user_rating <rating>;
    };

But when I try to run it, the grail console gives me this error:
extraneous input '}' expecting {<EOF>, ',', ';', ':', 'for', 'if', 'elseif', 'else', 'do', 'in', '=', '!=', 'and', 'or', 'not', '>', '>=', '<', '<=', '(', ')', '[', ']', '$', '"', ''', 'null', BOOLEAN, ID, STRING, VAR_GRAQL, ID_MACRO}

which doesn’t make sense to me as the structure of the if-else statement is something took from the documentation.


#2

Hei @CasualCoder,

have you tried removing the ; after the }?

if ( <rating> == "-1")
    do { 
        (unrated_movie: $movie, movie_watcher: $user) isa movie_not_rated;
    }
    else { 
        (rated_movie: $movie, movie_watcher: $user) isa movie_rated
        has user_rating <rating>;
    }

#3

Yeah I did, still the same thing. I wonder if graql supports this sort of syntax.


#4

I ended up solving it by writing two if cases like so

    if ( <rating> = "-1") do {
        (unrated_movie: $movie, movie_watcher: $user) isa movie_not_rated;
    }
    
    if ( <rating> != "-1") do {
        (rated_movie: $movie, movie_rater: $user) isa movie_rated has user_rating @double(<rating>); 
    }

It’s not ideal but at least it worked.