-
Notifications
You must be signed in to change notification settings - Fork 114
Description
Using the example app as the starting point, I modeled a folder heirarchy using a "folders" resource that refers to another "folders" resource through a parent attribute. There is a case where a folders resource doesn't have a parent as it will be the root folder. The folders resource can be retrieved and shows the following relationship attribute for parent:
parent": {
"meta":
{
"relation": "primary",
"readOnly": false
},
"links":
{
"self": "http://localhost:8080/rest/folders/6b017640-827c-4d50-8dcc-79d766abb408/relationships/parent",
"related": "http://localhost:8080/rest/folders/6b017640-827c-4d50-8dcc-79d766abb408/parent"
},
"data": null
}
The problem is if you follow the "related" link it will crash the server with the following exception...
/jsonapi-test/node_modules/jsonapi-server/lib/postProcess.js:41
map[dataItem.type] = map[dataItem.type] || [ ];
^
TypeError: Cannot read property 'type' of null
at /jsonapi-test/node_modules/jsonapi-server/lib/postProcess.js:41:17
at Array.reduce (native)
at Object.postProcess._fetchRelatedResources (/jsonapi-test/node_modules/jsonapi-server/lib/postProcess.js:40:36)
at async.waterfall.relatedResources (/jsonapi-test/node_modules/jsonapi-server/lib/routes/related.js:51:21)
at fn (/jsonapi-test/node_modules/async/lib/async.js:746:34)
at /jsonapi-test/node_modules/async/lib/async.js:1213:16
at /jsonapi-test/node_modules/async/lib/async.js:166:37
at /jsonapi-test/node_modules/async/lib/async.js:706:43
at /jsonapi-test/node_modules/async/lib/async.js:167:37
at Immediate._onImmediate (/jsonapi-test/node_modules/async/lib/async.js:1206:34)
It seems to me a valid use case but in this case the links attribute would need to be removed but the issue would still remain that if somebody manually creates their own link it will bring down the server.
I've put up a test repository showing my set up at https://github.com/dalane/jsonapi-test