mathematic-inc / ts-japi

A highly-modular (typescript-friendly)-framework agnostic library for serializing data to the JSON:API specification
Apache License 2.0
203 stars 16 forks source link

Allow null for empty to-one relationships #22

Closed jaridmargolin closed 3 years ago

jaridmargolin commented 3 years ago

Description

Update to allow null for empty to-one relationships as defined in the JSON:API spec: https://jsonapi.org/format/#document-resource-object-related-resource-links

Resource linkage MUST be represented as one of the following:

* null for empty to-one relationships.
* an empty array ([]) for empty to-many relationships.
* a single resource identifier object for non-empty to-one relationships.
& an array of resource identifier objects for non-empty to-many relationships.

Details

In order to support this, changes needed to be applied to two modules:

Notes

One thing I find interesting, is that the fetch method used in Relator was typed to support resolving with null, which meant that this error was getting thrown at runtime rather than at compile time. This leads me to believe that the intent was for null to be supported and that the behavior encountered when actually returning null is a bug.

Anyways, happy to make any requested changes.

changeset-bot[bot] commented 3 years ago

⚠️ No Changeset found

Latest commit: 3cc478c698dfed210f1b6d8f95d05223ce82c0bc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

jrandolf commented 3 years ago

Thanks for the PR. Looks great. Could you add a change set? This will help CD.

jaridmargolin commented 3 years ago

Hi @jun-sheaf. Thanks for the quick response.

I was attempting to follow the documentation posted by the @changeset-bot but I ran into a few issues.

Do you mind me asking, have you configured and used changeset on this particular project? If so, do you have any accompanying documentation? I browsed the contributing doc and didn't see anything referenced.

jrandolf commented 3 years ago

It seems I did not set up changesets (I thought I did, perhaps I forgot to commit). I'll just merge and set it up.

By the way, you have to init the changeset, not just create a .changeset folder.

jaridmargolin commented 3 years ago

Wanted to drop a quick thank you... for merging the PR so quickly AND for cutting a release. Rare to see a turnaround that quick!