Skip to content

Commit 04c75bb

Browse files
authored
fix(gatsby): fix error from ts conversion (#26681)
1 parent 25e3a63 commit 04c75bb

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

packages/gatsby/src/redux/nodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export const saveResolvedNodes = async (
138138
): Promise<void> => {
139139
for (const typeName of nodeTypeNames) {
140140
const nodes = store.getState().nodesByType.get(typeName)
141-
if (!nodes) return
141+
if (!nodes) continue
142142

143143
const resolvedNodes = new Map()
144144
for (const node of nodes.values()) {

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

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,14 @@ describe(`NodeModel`, () => {
580580
contentDigest: `1`,
581581
},
582582
},
583+
// Test2 is a special type that must have no nodes!
584+
{
585+
id: `id3`,
586+
internal: {
587+
type: `Test3`,
588+
contentDigest: `2`,
589+
},
590+
},
583591
])()
584592
store.dispatch({ type: `DELETE_CACHE` })
585593
nodes.forEach(node =>
@@ -590,6 +598,13 @@ describe(`NodeModel`, () => {
590598
store.dispatch({
591599
type: `CREATE_TYPES`,
592600
payload: [
601+
typeBuilders.buildInterfaceType({
602+
name: `TestInterface`,
603+
fields: {
604+
slug: { type: `String` },
605+
},
606+
}),
607+
593608
typeBuilders.buildInterfaceType({
594609
name: `TestNestedInterface`,
595610
fields: {
@@ -609,7 +624,7 @@ describe(`NodeModel`, () => {
609624

610625
typeBuilders.buildObjectType({
611626
name: `Test`,
612-
interfaces: [`Node`],
627+
interfaces: [`Node`, `TestInterface`],
613628
fields: {
614629
betterTitle: {
615630
type: `String`,
@@ -641,6 +656,30 @@ describe(`NodeModel`, () => {
641656
undefined,
642657
],
643658
},
659+
slug: {
660+
type: `String`,
661+
resolve: source => source.id,
662+
},
663+
},
664+
}),
665+
typeBuilders.buildObjectType({
666+
name: `Test2`,
667+
interfaces: [`Node`, `TestInterface`],
668+
fields: {
669+
slug: {
670+
type: `String`,
671+
resolve: source => source.id,
672+
},
673+
},
674+
}),
675+
typeBuilders.buildObjectType({
676+
name: `Test3`,
677+
interfaces: [`Node`, `TestInterface`],
678+
fields: {
679+
slug: {
680+
type: `String`,
681+
resolve: source => source.id,
682+
},
644683
},
645684
}),
646685
],
@@ -789,6 +828,22 @@ describe(`NodeModel`, () => {
789828
expect(result.length).toEqual(1)
790829
expect(result[0].id).toEqual(`id1`)
791830
})
831+
832+
it(`handles fields with custom resolvers on interfaces having multiple implementations`, async () => {
833+
nodeModel.replaceFiltersCache()
834+
const result = await nodeModel.runQuery(
835+
{
836+
query: {
837+
filter: { slug: { eq: `id3` } },
838+
},
839+
firstOnly: true,
840+
type: `TestInterface`,
841+
},
842+
{ path: `/` }
843+
)
844+
expect(result).toBeTruthy()
845+
expect(result.id).toEqual(`id3`)
846+
})
792847
})
793848

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

0 commit comments

Comments
 (0)