I have three type-graphql objects (and typeorm entities): Entry (dictionary headwords), Meaning (meanings of headwords) and Pronunciation (transcriptions of headwords).
There's a many-to-many relationship between Entry and Meaning, and one-to-many between Entry and Pronunciation.
I have the GraphQL query searchEntries which takes a query and returns matching Entry objects with linked Meaning and Pronunciation objects.
In my Entry.ts file, I defined the relationships of Entry like this (@Field() comes from type-graphql):
@Field(() => [Pronunciation], { nullable: "itemsAndList" })
@OneToMany(() => Pronunciation, (pronunciation) => pronunciation.entry, {
nullable: true,
})
pronunciations: Relation<Pronunciation[]> | undefined;
@Field(() => [Meaning], { nullable: "itemsAndList" })
@ManyToMany(() => Meaning, (meaning) => meaning.entries, { nullable: true })
meanings: Relation<Meaning[]> | undefined;
So, as you can see, GraphQL should know that fields pronunciations and meanings of Entry are nullable.
However, I'm getting this error (from graphql):
Cannot return null for non-nullable field Pronunciation.id.
I notice that children elements of pronunciations and meanings are still non-nullable:

Why doesn't GraphQL infer that if the parent element is nullable, its children are nullable as well?
Additional info: I'm fetching the data using typeorm's raw SQL query, and the printed result looks like this:
[
{
id: 86,
headword: 'lightning',
createdAt: 2023-02-17T07:12:27.825Z,
updatedAt: 2023-02-17T07:12:27.825Z,
meanings: [ [Object], [Object], [Object] ],
pronunciations: [ [Object], [Object], [Object] ]
}
]
(I'm using JSON_AGG(JSON_BUILD_OBJECT()) for arrays of meanings and pronunciations, and left joins for joining tables.)
Any help would be greatly appreciated!
JSON_BUILD_OBJECT()that returns fields like this:[{ id: null, transcription: null, notes: null, userId: null },...]instead of returning a null object. Searching for a workaroundidofPronunciationreturnsnull; where in your schema is specified that it cannot be.