Skip to content

Commit

Permalink
fix(gatsby): fix error from ts conversion (#26681)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladar committed Aug 28, 2020
1 parent 25e3a63 commit 04c75bb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby/src/redux/nodes.ts
Expand Up @@ -138,7 +138,7 @@ export const saveResolvedNodes = async (
): Promise<void> => {
for (const typeName of nodeTypeNames) {
const nodes = store.getState().nodesByType.get(typeName)
if (!nodes) return
if (!nodes) continue

const resolvedNodes = new Map()
for (const node of nodes.values()) {
Expand Down
57 changes: 56 additions & 1 deletion packages/gatsby/src/schema/__tests__/node-model.js
Expand Up @@ -580,6 +580,14 @@ describe(`NodeModel`, () => {
contentDigest: `1`,
},
},
// Test2 is a special type that must have no nodes!
{
id: `id3`,
internal: {
type: `Test3`,
contentDigest: `2`,
},
},
])()
store.dispatch({ type: `DELETE_CACHE` })
nodes.forEach(node =>
Expand All @@ -590,6 +598,13 @@ describe(`NodeModel`, () => {
store.dispatch({
type: `CREATE_TYPES`,
payload: [
typeBuilders.buildInterfaceType({
name: `TestInterface`,
fields: {
slug: { type: `String` },
},
}),

typeBuilders.buildInterfaceType({
name: `TestNestedInterface`,
fields: {
Expand All @@ -609,7 +624,7 @@ describe(`NodeModel`, () => {

typeBuilders.buildObjectType({
name: `Test`,
interfaces: [`Node`],
interfaces: [`Node`, `TestInterface`],
fields: {
betterTitle: {
type: `String`,
Expand Down Expand Up @@ -641,6 +656,30 @@ describe(`NodeModel`, () => {
undefined,
],
},
slug: {
type: `String`,
resolve: source => source.id,
},
},
}),
typeBuilders.buildObjectType({
name: `Test2`,
interfaces: [`Node`, `TestInterface`],
fields: {
slug: {
type: `String`,
resolve: source => source.id,
},
},
}),
typeBuilders.buildObjectType({
name: `Test3`,
interfaces: [`Node`, `TestInterface`],
fields: {
slug: {
type: `String`,
resolve: source => source.id,
},
},
}),
],
Expand Down Expand Up @@ -789,6 +828,22 @@ describe(`NodeModel`, () => {
expect(result.length).toEqual(1)
expect(result[0].id).toEqual(`id1`)
})

it(`handles fields with custom resolvers on interfaces having multiple implementations`, async () => {
nodeModel.replaceFiltersCache()
const result = await nodeModel.runQuery(
{
query: {
filter: { slug: { eq: `id3` } },
},
firstOnly: true,
type: `TestInterface`,
},
{ path: `/` }
)
expect(result).toBeTruthy()
expect(result.id).toEqual(`id3`)
})
})

describe(`node tracking`, () => {
Expand Down

0 comments on commit 04c75bb

Please sign in to comment.