Skip to content

Commit 25e3a63

Browse files
authoredAug 28, 2020
fix(gatsby): fix materialization edge case with nullish values (#26677)
1 parent 19020c2 commit 25e3a63

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed
 

‎packages/gatsby/src/schema/__tests__/node-model.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ describe(`NodeModel`, () => {
550550
})
551551
})
552552

553-
describe(`prepare nodes caching`, () => {
553+
describe(`materialization`, () => {
554554
let resolveBetterTitleMock
555555
let resolveOtherTitleMock
556556
beforeEach(async () => {
@@ -590,12 +590,21 @@ describe(`NodeModel`, () => {
590590
store.dispatch({
591591
type: `CREATE_TYPES`,
592592
payload: [
593+
typeBuilders.buildInterfaceType({
594+
name: `TestNestedInterface`,
595+
fields: {
596+
foo: { type: `String` },
597+
},
598+
resolveType: value => value.kind,
599+
}),
600+
593601
typeBuilders.buildObjectType({
594602
name: `TestNested`,
595603
fields: {
596604
foo: { type: `String` },
597605
bar: { type: `String` },
598606
},
607+
interfaces: [`TestNestedInterface`],
599608
}),
600609

601610
typeBuilders.buildObjectType({
@@ -624,6 +633,14 @@ describe(`NodeModel`, () => {
624633
type: `TestNested`,
625634
resolve: source => source.nested,
626635
},
636+
arrayWithNulls: {
637+
type: `[TestNestedInterface]`,
638+
resolve: source => [
639+
null,
640+
{ kind: `TestNested`, foo: source.id },
641+
undefined,
642+
],
643+
},
627644
},
628645
}),
629646
],
@@ -755,6 +772,23 @@ describe(`NodeModel`, () => {
755772
expect(result2.length).toBe(1)
756773
expect(result2[0].id).toBe(`id2`)
757774
})
775+
776+
it(`handles nulish values within array of interface type`, async () => {
777+
nodeModel.replaceFiltersCache()
778+
const result = await nodeModel.runQuery(
779+
{
780+
query: {
781+
filter: { arrayWithNulls: { elemMatch: { foo: { eq: `id1` } } } },
782+
},
783+
firstOnly: false,
784+
type: `Test`,
785+
},
786+
{ path: `/` }
787+
)
788+
expect(result).toBeTruthy()
789+
expect(result.length).toEqual(1)
790+
expect(result[0].id).toEqual(`id1`)
791+
})
758792
})
759793

760794
describe(`node tracking`, () => {

‎packages/gatsby/src/schema/node-model.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -688,15 +688,17 @@ async function resolveRecursive(
688688
) {
689689
innerValue = await Promise.all(
690690
innerValue.map(item =>
691-
resolveRecursive(
692-
nodeModel,
693-
schemaComposer,
694-
schema,
695-
item,
696-
gqlFieldType,
697-
queryField,
698-
_.isObject(fieldToResolve) ? fieldToResolve : queryField
699-
)
691+
item == null
692+
? item
693+
: resolveRecursive(
694+
nodeModel,
695+
schemaComposer,
696+
schema,
697+
item,
698+
gqlFieldType,
699+
queryField,
700+
_.isObject(fieldToResolve) ? fieldToResolve : queryField
701+
)
700702
)
701703
)
702704
}

0 commit comments

Comments
 (0)
Please sign in to comment.