Skip to content

Commit ef4f5ae

Browse files
gkelloggdavidlehn
authored andcommitted
Values of @graph are allways in an array.
1 parent b703a19 commit ef4f5ae

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/compact.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,10 @@ api.compact = ({
368368
nestResult, itemActiveProperty, compactedItem,
369369
{propertyIsArray: (!options.compactArrays || container.includes('@set'))});
370370
} else {
371-
// wrap using @graph alias
371+
// wrap using @graph alias, value is always an array
372+
if(!_isArray(compactedItem)) {
373+
compactedItem = [compactedItem]
374+
}
372375
compactedItem = {
373376
[api.compactIri({activeCtx, iri: '@graph', relativeTo: {vocab: true}})]: compactedItem
374377
};
@@ -844,11 +847,12 @@ api.removePreserve = (ctx, input, options) => {
844847
}
845848

846849
// recurse through properties
850+
const graphAlias = api.compactIri({activeCtx: ctx, iri: '@graph', relativeTo: {vocab: true}});
847851
for(const prop in input) {
848852
let result = api.removePreserve(ctx, input[prop], options);
849853
const container = _getContextValue(ctx, prop, '@container') || [];
850854
if(options.compactArrays && _isArray(result) && result.length === 1 &&
851-
container.length === 0) {
855+
container.length === 0 && prop !== graphAlias) {
852856
result = result[0];
853857
}
854858
input[prop] = result;

0 commit comments

Comments
 (0)