This repository was archived by the owner on Jan 25, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,6 +72,9 @@ export const JSONAPIDeserializer = {
7272 resource : JSONApiResource ,
7373 resolvedMap : T
7474 ) : T [ K ] {
75+ if ( ! resource . id || ! resource . type ) {
76+ return ;
77+ }
7578 const key = `${ resource . id } -${ resource . type } ` ;
7679
7780 return get ( resolvedMap , key ) ;
@@ -87,7 +90,6 @@ export const JSONAPIDeserializer = {
8790 const type = data . type ;
8891
8992 const resolvedItem = this . getResolvedItem ( data , resolvedMap ) ;
90-
9193 if ( resolvedItem ) {
9294 return resolvedItem ;
9395 }
Original file line number Diff line number Diff line change 11import { JSONAPIDeserializer , JSONAPISerializer } from "../src" ;
22
3+ test ( "JSONAPIDeserializer:compound relationships w/o ids" , async ( ) => {
4+ var jsonapiResponse = {
5+ data : {
6+ type : "email-lists" ,
7+ relationships : {
8+ emails : {
9+ data : [
10+ {
11+ type : "emails" ,
12+ attributes : {
13+ email : "email-1@mail.com" ,
14+ } ,
15+ } ,
16+ {
17+ type : "emails" ,
18+ attributes : {
19+ email : "email-2@mail.com" ,
20+ } ,
21+ } ,
22+ ] ,
23+ } ,
24+ } ,
25+ } ,
26+ } ;
27+
28+ // @ts -ignore @todo check this type
29+ const output = JSONAPIDeserializer . deserialize ( jsonapiResponse ) ;
30+ expect ( output . data . emails [ 0 ] . email ) . toEqual ( "email-1@mail.com" ) ;
31+ expect ( output . data . emails [ 1 ] . email ) . toEqual ( "email-2@mail.com" ) ;
32+ } ) ;
33+
334test ( "JSONAPIDeserializer:basic attributes" , async ( ) => {
435 const jsonapiResponse = {
536 data : {
You can’t perform that action at this time.
0 commit comments