Joystream / Joystream/hydra

QN typeguard for relation loading

Open
#492 0 comments 1 reaction 1 assignee View on GitHub

@ondratra is already working on this.

Since May 25, 2022.

enhancement med-prio qn-hydra-board
Dominant language
TypeScript
Stars
50
Forks
43
PR merge metrics
No merged PRs in 30d

Description

Sometimes we encounter a hardly spotted bug in the mappings when we rely on some relation being loaded that is actually not loaded.

// invalid case
const video = await store.get(Video, { where: { id: SomeId } })
console.log(video.channel) // undefined; 

// valid case
const video = await store.get(Video, { where: { id: SomeId }, relations: ['channel'] })
console.log(video.channel)

As shown in the example, if a developer forgets to add relations: ['myEntity'] and then tries to access it, the error occurs. Currently, this is not caught by a compiler.

Let's try to improve our Typescript type guards for DatabaseManager so that .get and other methods return type that signals what relations are actually loaded and triggers compilation errors when not-loaded relations are used.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.