Skip to content

Commit 4bdfbcc

Browse files
author
Jan Lenoch
authored
Merge pull request #16 from Kentico/circular-references
Handle circular references when serializing node content
2 parents 3f119c1 + b92ef84 commit 4bdfbcc

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gatsby-source-kentico-cloud",
33
"description": "Gatsby source plugin for Kentico Cloud",
4-
"version": "2.0.0-beta1",
4+
"version": "2.0.0-beta2",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/Kentico/gatsby-source-kentico-cloud"

src/normalize.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,24 @@ of valid objects.`);
242242
const createKcArtifactNode =
243243
(nodeId, kcArtifact, artifactKind, typeName = ``,
244244
additionalNodeData = null) => {
245-
const nodeContent = JSON.stringify(kcArtifact);
245+
let processedProperties = [];
246+
247+
// Handle circular references when serializing.
248+
const nodeContent = JSON.stringify(kcArtifact, (key, value) =>{
249+
if (typeof value === `object` && value !== null) {
250+
if (processedProperties.indexOf(value) !== -1) {
251+
try {
252+
return JSON.parse(JSON.stringify(value));
253+
} catch (error) {
254+
return;
255+
}
256+
}
257+
processedProperties.push(value);
258+
}
259+
return value;
260+
});
261+
262+
processedProperties = null;
246263

247264
const nodeContentDigest = crypto
248265
.createHash(`md5`)

0 commit comments

Comments
 (0)