Skip to content
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

Ignore relationships that don't have data property #778

Merged
merged 5 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
concat,
insert,
assocPath,
pickBy,
} from 'ramda';
import { mapIndexed, reduceIndexed, ensureArray, isArray } from 'ramda-adjunct';

Expand All @@ -24,7 +25,11 @@ import { mapIndexed, reduceIndexed, ensureArray, isArray } from 'ramda-adjunct';
// RelPath = {path: String, key: ResourceKey}

// getRelationships :: Resource -> Relationships
const getRelationships = pipe(propOr({}, ['relationships']), keys);
const getRelationships = pipe(
propOr({}, ['relationships']),
pickBy(has('data')),
keys
);

// resourceKey :: ResourceRel -> ResourceKey
const resourceKey = ({ type, id }) => `${type}-${id}`;
Expand Down
23 changes: 20 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,27 @@ describe('jsonApiMerge', function () {
};

specify('should throw error', function () {
const included = jsonApiMerge(jsonApiData.included, jsonApiData.included);
const thunk = () => jsonApiMerge(included, jsonApiData.data);
const expected = {
id: 1,
type: 'resource',
attributes: {
name: 'Resource name',
},
relationships: {
related: {
links: {
related: {
href: 'http://example.com/related-resource/',
title: 'Related',
},
},
},
},
};

assert.throws(thunk, TypeError);
const actual = jsonApiMerge(jsonApiData.included, jsonApiData.data);

assert.deepEqual(actual, expected);
});
});

Expand Down