subsquid / squid-sdk

The main repo of the squid SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Null unsafety should be explained

Hugo-Trentesaux opened this issue · comments

In this changelog: https://github.com/subsquid/squid-sdk/blob/master/typeorm/typeorm-codegen/CHANGELOG.md

I see multiple references to the fact that non-nullable fields are allowed to be null:

make unique fk fields always nullable
(in 1.3)

always accept null column values to workaround TypeORM issue - field transformation can be run for a null entity
(in 0.2.3)

make entity references always nullable in the database
(in 0.1.0)

I think this is counter-intuitive. For instance:

# this line in the graphql schema
createdIn: Event!

gives

// this line in the typeorm model
@ManyToOne_(() => Event, {nullable: true})
    createdIn!: Event

where there is a mismatch between {nullable: true} annotation and createdIn! exclamation mark.

It should be added to the documentation page https://docs.subsquid.io/sdk/reference/schema-file/intro/