Skip to content

Instantly share code, notes, and snippets.

@srmagura
Last active April 5, 2023 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srmagura/1d2ad4c6a57b2f7fc612e180bf725afd to your computer and use it in GitHub Desktop.
Save srmagura/1d2ad4c6a57b2f7fc612e180bf725afd to your computer and use it in GitHub Desktop.
// OrgMembership.ts
@ManyToOne(() => User, { ref: true, onDelete: 'cascade' })
user: Ref<User>;
// User.ts
@OneToMany(() => OrgMembership, 'user') // 'user' is actually type-safe. You can't just enter any string
orgMemberships = new Collection<OrgMembership>(this);
// Notice there is no @Field() on either end of the relationship. If you try
// this, the GraphQL response will contain an object with the correct ID, but no
// other fields.
//
// So we will use @ResolveField() to load related entities for GraphQL API
// calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment