Skip to content

Commit

Permalink
Merge pull request #16 from Kentico/circular-references
Browse files Browse the repository at this point in the history
Handle circular references when serializing node content
  • Loading branch information
Jan Lenoch authored Oct 30, 2018
2 parents 3f119c1 + b92ef84 commit 4bdfbcc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby-source-kentico-cloud",
"description": "Gatsby source plugin for Kentico Cloud",
"version": "2.0.0-beta1",
"version": "2.0.0-beta2",
"repository": {
"type": "git",
"url": "https://github.com/Kentico/gatsby-source-kentico-cloud"
Expand Down
19 changes: 18 additions & 1 deletion src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,24 @@ of valid objects.`);
const createKcArtifactNode =
(nodeId, kcArtifact, artifactKind, typeName = ``,
additionalNodeData = null) => {
const nodeContent = JSON.stringify(kcArtifact);
let processedProperties = [];

// Handle circular references when serializing.
const nodeContent = JSON.stringify(kcArtifact, (key, value) =>{
if (typeof value === `object` && value !== null) {
if (processedProperties.indexOf(value) !== -1) {
try {
return JSON.parse(JSON.stringify(value));
} catch (error) {
return;
}
}
processedProperties.push(value);
}
return value;
});

processedProperties = null;

const nodeContentDigest = crypto
.createHash(`md5`)
Expand Down

0 comments on commit 4bdfbcc

Please sign in to comment.