Skip to content

Commit d2bf6f5

Browse files
stefanprobstfreiksenet
authored andcommitted
fix(schema): Add tests for incorrect list counting (#12824)
* fix(schema): Fix incorrect list counting * Add tests
1 parent d25b39d commit d2bf6f5

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

packages/gatsby/src/schema/infer/__tests__/merge-types.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ const nodes = [
3737
},
3838
{
3939
id: `id2`,
40+
internal: { type: `ArrayTest` },
41+
array: [{ foo: true }],
42+
},
43+
{
44+
id: `id3`,
4045
internal: { type: `LinkTest` },
4146
link___NODE: `id1`,
4247
links___NODE: [`id1`],
@@ -283,6 +288,40 @@ describe(`merges explicit and inferred type definitions`, () => {
283288
expect(fields.explicitDate.resolve).toBeUndefined()
284289
})
285290

291+
it(`honors array depth when merging types`, async () => {
292+
const typeDefs = `
293+
type FooBar {
294+
bar: Boolean
295+
}
296+
type ArrayTest implements Node {
297+
array: [FooBar]
298+
}
299+
`
300+
store.dispatch({ type: `CREATE_TYPES`, payload: typeDefs })
301+
await build({})
302+
const { schema } = store.getState()
303+
const { foo, bar } = schema.getType(`FooBar`).getFields()
304+
expect(foo.type.toString()).toBe(`Boolean`)
305+
expect(bar.type.toString()).toBe(`Boolean`)
306+
})
307+
308+
it(`does not merge types when array depth does not match`, async () => {
309+
const typeDefs = `
310+
type FooBar {
311+
bar: Boolean
312+
}
313+
type ArrayTest implements Node {
314+
array: FooBar
315+
}
316+
`
317+
store.dispatch({ type: `CREATE_TYPES`, payload: typeDefs })
318+
await build({})
319+
const { schema } = store.getState()
320+
const { foo, bar } = schema.getType(`FooBar`).getFields()
321+
expect(foo).toBeUndefined()
322+
expect(bar.type.toString()).toBe(`Boolean`)
323+
})
324+
286325
it(`preserves foreign-key resolvers on ___NODE fields when noDefaultResolvers: false`, async () => {
287326
const typeDefs = `
288327
type LinkTest implements Node {

0 commit comments

Comments
 (0)