crystal
crystal copied to clipboard
@notNull annotation on function generates unexpected result
Test case:
CREATE TABLE tu(x bigint);
INSERT INTO tu(x) VALUES(1);
create function fu() returns tu as $$ select * from tu LIMIT 1 $$ language sql;
Now add a smart comment @notNull
on the function, it makes FuPayload
not null. But as mentioned in the last issue, the function throw an error so that is incorrect. So it should turn CreateTuPayload { ..., tu: Tu, ... }
into CreateTuPayload { ..., tu: Tu!, ... }
to show it can't return null
I’m inclined to agree 👍
And ideally there would be another annotation @notThrows
which removes the top-level nullability.
And for a function that returns a primitive (?), you would need to add @notThrows @notNull
to handle both reasons postgraphile could possibly need a null
No, all non-trivial root-level fields should be nullable - you don’t generally control all the situations under which it might throw - what if the postgres server is unplugged in the middle of the transaction? What if a unique constraint is violated? Etc