Skip to content

Commit 7705f17

Browse files
mathisdemoslmathi
andauthored
null relationships should not be removed during preprocessing (#320)
Co-authored-by: Mathis Lucka <[email protected]>
1 parent a5cae0c commit 7705f17

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/api/ResourcefulApi.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ export class ResourcefulApi extends Api {
8787
type: startChar.charAt(0).toUpperCase() + relationship.data.type.slice(1)
8888
}
8989
}
90+
} else if (relationship.data === null) {
91+
relationships[name] = {
92+
data: null
93+
}
9094
}
9195
}
9296
data.data.relationships = relationships

test/api/ResourcefulApi.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,20 @@ test('reads the initial module list', () => {
3939

4040
expect(registerModuleMock.mock.calls.length).toBe(3)
4141
})
42+
43+
test('keeps null relationships after preprocessing', () => {
44+
const testResource = {
45+
data: {
46+
id: 1,
47+
type: 'User',
48+
relationships: {
49+
hobbies: {
50+
data: null
51+
}
52+
}
53+
}
54+
}
55+
56+
const preprocessedData = api.preprocessData(testResource)
57+
expect(preprocessedData.data.relationships.hobbies.data).toBe(null)
58+
})

0 commit comments

Comments
 (0)