mswjs / mswjs/data

Non-nullable self-referencing relations

Open
#318 5 comments 0 reactions 1 assignee View on GitHub

@kettanaito is already working on this.

Since Oct 5, 2025.

Dominant language
TypeScript
Stars
1.1k
Forks
67
Avg merge
9m
Merged PRs (30d)
5

Description

It is currently impossible to provide a self-referencing object(s) to Zod (I believe any schema library) as it will attempt to crawl it deeply and end up stuck in an infinite loop. Currently, this is circumvented by:

  1. Circular relations being marked as .optional() so their values in the schema are not required.
  2. All relations are detected when sanitizing and replaced with .getDefaultValue() from the appropriate relation class.

Need to decide if this is acceptable or a better approach can be recommended.

  • Sucks interfering with the user-defined schema. Some relations may be required but there's no way to describe that.

Contributor guide

No contributing guide indexed for this repository

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.