|
1 | 1 | import { describe, it } from 'mocha';
|
2 | 2 |
|
| 3 | +import { expectJSON } from '../../__testUtils__/expectJSON.js'; |
| 4 | + |
| 5 | +import type { DocumentNode } from '../../language/ast.js'; |
| 6 | +import { OperationTypeNode } from '../../language/ast.js'; |
| 7 | +import { Kind } from '../../language/kinds.js'; |
| 8 | + |
3 | 9 | import { ScalarLeafsRule } from '../rules/ScalarLeafsRule.js';
|
| 10 | +import { validate } from '../validate.js'; |
4 | 11 |
|
5 |
| -import { expectValidationErrors } from './harness.js'; |
| 12 | +import { expectValidationErrors, testSchema } from './harness.js'; |
6 | 13 |
|
7 | 14 | function expectErrors(queryStr: string) {
|
8 | 15 | return expectValidationErrors(ScalarLeafsRule, queryStr);
|
@@ -35,6 +42,39 @@ describe('Validate: Scalar leafs', () => {
|
35 | 42 | ]);
|
36 | 43 | });
|
37 | 44 |
|
| 45 | + it('object type having only one selection', () => { |
| 46 | + const doc: DocumentNode = { |
| 47 | + kind: Kind.DOCUMENT, |
| 48 | + definitions: [ |
| 49 | + { |
| 50 | + kind: Kind.OPERATION_DEFINITION, |
| 51 | + operation: OperationTypeNode.QUERY, |
| 52 | + selectionSet: { |
| 53 | + kind: Kind.SELECTION_SET, |
| 54 | + selections: [ |
| 55 | + { |
| 56 | + kind: Kind.FIELD, |
| 57 | + name: { kind: Kind.NAME, value: 'human' }, |
| 58 | + selectionSet: { kind: Kind.SELECTION_SET, selections: [] }, |
| 59 | + }, |
| 60 | + ], |
| 61 | + }, |
| 62 | + }, |
| 63 | + ], |
| 64 | + }; |
| 65 | + |
| 66 | + // We can't leverage expectErrors since it doesn't support passing in the |
| 67 | + // documentNode directly. We have to do this because this is technically |
| 68 | + // an invalid document. |
| 69 | + const errors = validate(testSchema, doc, [ScalarLeafsRule]); |
| 70 | + expectJSON(errors).toDeepEqual([ |
| 71 | + { |
| 72 | + message: |
| 73 | + 'Field "human" of type "Human" must have at least one field selected.', |
| 74 | + }, |
| 75 | + ]); |
| 76 | + }); |
| 77 | + |
38 | 78 | it('interface type missing selection', () => {
|
39 | 79 | expectErrors(`
|
40 | 80 | {
|
|
0 commit comments