-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Errors when response has empty relationships #3
Comments
The problem does not come from the empty included field. Look at your last_message in your example: The reason it crashes on line 53 is because the data field does not have type subfield. Thank you very much for your contribution. I will review it and I will post a comment here at a later date. |
I'm using https://github.com/Netflix/fast_jsonapi and it's not directly compatible with this lib without making some backend changes. Basically, if a model has a relationship and it's empty (by empty I mean it's null), |
Yeah, I got it and you are right that a null value must not give an error. |
In my backend I have a conversation model that olds a foreign_key to the last sent message in that conversation. If there is no last message, this normaliser fails.
Example:
Uncaught (in promise) TypeError: Cannot read property 'constructor' of null at normalize (index.js:57)
(Normalize-JSON-API/src/index.ts
Line 51 in 7443bb3
I also had occasions where it would fail on line 53 (
Normalize-JSON-API/src/index.ts
Line 53 in 7443bb3
relation.data[0]
would be undefined.I have temporarily fixed this in the backend by not serializing fields that are empty but that's going to be cumbersome to do across all serializers.
Also, if the serializer does not include any relationship, and thus the
included
attribute does not exist, the normalizer crashes as well (Normalize-JSON-API/src/functions/find-items.ts
Line 23 in 7443bb3
The text was updated successfully, but these errors were encountered: