Skip to content

Commit 8e073bb

Browse files
committed
added a test for an edge case around unions
1 parent fef0f6c commit 8e073bb

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

test/analysis/buildTypeWeights.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,6 @@ describe('Test buildTypeWeightsFromSchema function', () => {
703703
});
704704
});
705705

706-
707706
test('object types', () => {
708707
schema = buildSchema(`
709708
union SearchResult = Human | Droid
@@ -833,6 +832,40 @@ describe('Test buildTypeWeightsFromSchema function', () => {
833832
});
834833
});
835834

835+
test('Unions with no fields overlapping', () => {
836+
schema = buildSchema(`
837+
union SearchResult = Human | Droid
838+
type Human{
839+
name: String
840+
homePlanet: String
841+
}
842+
type Droid {
843+
primaryFunction: String
844+
id: String
845+
}
846+
`);
847+
expect(buildTypeWeightsFromSchema(schema)).toEqual({
848+
searchresult: {
849+
weight: 1,
850+
fields: {},
851+
},
852+
human: {
853+
weight: 1,
854+
fields: {
855+
name: { weight: 0 },
856+
homePlanet: { weight: 0 },
857+
},
858+
},
859+
droid: {
860+
weight: 1,
861+
fields: {
862+
primaryFunction: { weight: 0 },
863+
id: { weight: 0 },
864+
},
865+
},
866+
});
867+
});
868+
836869
describe('Not null operator (!) is used', () => {
837870
test('on a scalar, enum or object type', () => {
838871
schema = buildSchema(`

0 commit comments

Comments
 (0)