crystal icon indicating copy to clipboard operation
crystal copied to clipboard

@notNull annotation on function generates unexpected result

Open husseinhere opened this issue 3 years ago • 3 comments

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

husseinhere avatar Feb 28 '22 22:02 husseinhere

I’m inclined to agree 👍

benjie avatar Mar 02 '22 23:03 benjie

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

husseinhere avatar Mar 03 '22 18:03 husseinhere

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

benjie avatar Mar 03 '22 23:03 benjie