Skip to content

Commit 1922d0d

Browse files
test(validation): add empty-selection case from 16.x.x backport (#4580)
This PR adds the `object type having only one selection` test from backport #4291 of original PR #4228 Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
1 parent 43a0d9f commit 1922d0d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/validation/__tests__/ScalarLeafsRule-test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,37 @@ describe('Validate: Scalar leafs', () => {
166166
},
167167
]);
168168
});
169+
170+
it('object type having only one selection', () => {
171+
const doc: DocumentNode = {
172+
kind: Kind.DOCUMENT,
173+
definitions: [
174+
{
175+
kind: Kind.OPERATION_DEFINITION,
176+
operation: OperationTypeNode.QUERY,
177+
selectionSet: {
178+
kind: Kind.SELECTION_SET,
179+
selections: [
180+
{
181+
kind: Kind.FIELD,
182+
name: { kind: Kind.NAME, value: 'human' },
183+
selectionSet: { kind: Kind.SELECTION_SET, selections: [] },
184+
},
185+
],
186+
},
187+
},
188+
],
189+
};
190+
191+
// We can't leverage expectErrors since it doesn't support passing in the
192+
// documentNode directly. We have to do this because this is technically
193+
// an invalid document.
194+
const errors = validate(testSchema, doc, [ScalarLeafsRule]);
195+
expectJSON(errors).toDeepEqual([
196+
{
197+
message:
198+
'Field "human" of type "Human" must have at least one field selected.',
199+
},
200+
]);
201+
});
169202
});

0 commit comments

Comments
 (0)