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 @@ -484,9 +484,8 @@ export class JSONAPISerializer {
484484 if ( value ?. id ) {
485485 output . id = value . id ;
486486 }
487- serializedRelationships [ kebabCase ( property ) ] = isNull ( value )
488- ? null
489- : output ;
487+ serializedRelationships [ kebabCase ( property ) ] =
488+ isNull ( value ) || isUndefined ( value ) ? null : output ;
490489 }
491490 }
492491 }
Original file line number Diff line number Diff line change @@ -634,3 +634,33 @@ test("JSONAPIDeserializer: polymorphic megapost", async () => {
634634
635635 expect ( data . items [ 0 ] . author . profile . avatar . url ) . toEqual ( "avatar-1.jpg" ) ;
636636} ) ;
637+
638+ test ( "JSONAPISerializer: null relationship with data null" , async ( ) => {
639+ const inputData = {
640+ id : "1" ,
641+ name : "El discurso del rey" ,
642+ duration : 120 ,
643+ director : null ,
644+ } ;
645+
646+ const movieSerializer = new MovieSerializer ( ) ;
647+ const output = movieSerializer . serialize ( { data : inputData } ) ;
648+ const { data } = output ;
649+
650+ expect ( data . relationships . director . data ) . toBeNull ( ) ;
651+ } ) ;
652+
653+ test ( "JSONAPISerializer: undefined relationship with data null" , async ( ) => {
654+ const inputData = {
655+ id : "1" ,
656+ name : "El discurso del rey" ,
657+ duration : 120 ,
658+ director : undefined ,
659+ } ;
660+
661+ const movieSerializer = new MovieSerializer ( ) ;
662+ const output = movieSerializer . serialize ( { data : inputData } ) ;
663+ const { data } = output ;
664+
665+ expect ( data . relationships . director . data ) . toBeNull ( ) ;
666+ } ) ;
You can’t perform that action at this time.
0 commit comments