Skip to content

Commit 7e51263

Browse files
authored
fix(gatsby): tolerate null object values (#12756)
fix(gatsby): tolerate null object values (#12756)
1 parent e6498e7 commit 7e51263

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

packages/gatsby/src/schema/infer/__tests__/__snapshots__/infer.js.snap

+20
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ Object {
167167
],
168168
},
169169
],
170+
"anObjectArrayWithNull": Array [
171+
Object {
172+
"anotherObjectArray": Array [
173+
Object {
174+
"baz": "quz",
175+
},
176+
],
177+
},
178+
null,
179+
],
170180
"date": "1012",
171181
"deepObject": Object {
172182
"deepObject": Object {
@@ -216,6 +226,16 @@ Object {
216226
],
217227
},
218228
],
229+
"anObjectArrayWithNull": Array [
230+
Object {
231+
"anotherObjectArray": Array [
232+
Object {
233+
"baz": "quz",
234+
},
235+
],
236+
},
237+
null,
238+
],
219239
"date": "1984",
220240
"deepObject": null,
221241
"domain": null,

packages/gatsby/src/schema/infer/__tests__/infer.js

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const makeNodes = () => [
2828
{ aString: `some string`, aNumber: 2, anArray: [1, 2] },
2929
{ anotherObjectArray: [{ bar: 10 }] },
3030
],
31+
anObjectArrayWithNull: [{ anotherObjectArray: [{ baz: `quz` }] }, null],
3132
deepObject: {
3233
level: 1,
3334
deepObject: {
@@ -63,6 +64,7 @@ const makeNodes = () => [
6364
anArray: [1, 2, 5, 4],
6465
aNestedArray: [[1, 2, 3, 4]],
6566
anObjectArray: [{ anotherObjectArray: [{ baz: `quz` }] }],
67+
anObjectArrayWithNull: [{ anotherObjectArray: [{ baz: `quz` }] }, null],
6668
"with space": 3,
6769
"with-hyphen": 4,
6870
123: 24,
@@ -987,6 +989,11 @@ describe(`GraphQL type inference`, () => {
987989
baz
988990
}
989991
},
992+
anObjectArrayWithNull {
993+
anotherObjectArray {
994+
baz
995+
}
996+
}
990997
deepObject {
991998
level
992999
deepObject {

packages/gatsby/src/schema/infer/example-value.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ module.exports = {
2222
}
2323

2424
const getExampleObject = ({
25-
nodes,
25+
nodes: rawNodes,
2626
prefix,
2727
typeConflictReporter,
2828
ignoreFields = [],
2929
}) => {
30+
const nodes = rawNodes.filter(node => node != null)
3031
const allKeys = nodes.reduce(
3132
(acc, node) =>
3233
Object.keys(node).forEach(

packages/gatsby/src/schema/utils/get-value-at.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ const getValueAt = (obj, selector) => {
33
return selectors.reduce((acc, key) => {
44
if (acc && typeof acc === `object`) {
55
if (Array.isArray(acc)) {
6-
return acc.map(a => a[key]).filter(a => a !== undefined)
6+
return acc
7+
.map(a => (a && typeof a === `object` ? a[key] : undefined))
8+
.filter(a => a !== undefined)
79
}
810
return acc[key]
911
}

0 commit comments

Comments
 (0)