I have looked at the examples and as far as i can tell i followed them to the letter... my @ManyToOne join runs in query as expected but the @OneToMany doesn't seem to fire when included in my graphql playground call.. all other data for User comes back as expected with the exception of the device info
This is in my User.ts entity:
@Field(type => [Devices], { nullable: true })
@OneToMany(() => Devices, devices => devices.user)
devices: Devices[];
This is the entry in my Devices.ts Entity:
Field(type => User)
@ManyToOne(type => User, { lazy: true })
@JoinColumn([{ name: "userId", referencedColumnName: "userId" }])
user: User;
Before i added the nullable: true above i was just getting an error saying can't return null for required blah blah... I thought maybe i had a device with no user but that was not the case.. In the terminal query output it only queries the user table and makes no attempt at getting devices...
My graphql call is super simple but just returns nulls for all devices:
{
users{
name
phone
devices{
deviceId
}
}
}
My @ManyToOne also returned nulls for user until i set { lazy: true } and i am not sure why for that either.. There is obviously no setting like that for @OneToMany.. I am a sequelize, javascript baby and this is my first crack at TypeORM so any help would be appreciated. Or if there is relevant code i have not put in, let me know and i'll do it up.. Cheers in advance
Interesting.... I barely saw an example of this anywhere but I ended up adding
{ lazy: true }
to the @OneToMany
calls as well and they now work. I didn't realize that was an option
@Field(type => [Devices], { nullable: true, })
@OneToMany(() => Devices, devices => devices.user, { lazy: true })
devices: Devices[];