@@ -2,9 +2,7 @@ import { describe, it } from 'node:test';
22
33import { expectJSON } from '../../__testUtils__/expectJSON.ts' ;
44
5- import type { DocumentNode } from '../../language/ast.ts' ;
6- import { OperationTypeNode } from '../../language/ast.ts' ;
7- import { Kind } from '../../language/kinds.ts' ;
5+ import { parse } from '../../language/parser.ts' ;
86
97import { ScalarLeafsRule } from '../rules/ScalarLeafsRule.ts' ;
108import { validate } from '../validate.ts' ;
@@ -42,35 +40,22 @@ describe('Validate: Scalar leafs', () => {
4240 ] ) ;
4341 } ) ;
4442
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.
43+ it ( 'object type having no selections is allowed' , ( ) => {
44+ const doc = parse ( '{ human { } }' ) ;
45+
46+ const errors = validate ( testSchema , doc , [ ScalarLeafsRule ] ) ;
47+ expectJSON ( errors ) . toDeepEqual ( [ ] ) ;
48+ } ) ;
49+
50+ it ( 'scalar selection is still rejected with an empty selection set' , ( ) => {
51+ const doc = parse ( '{ human { name { } } }' ) ;
52+
6953 const errors = validate ( testSchema , doc , [ ScalarLeafsRule ] ) ;
7054 expectJSON ( errors ) . toDeepEqual ( [
7155 {
7256 message :
73- 'Field "human" of type "Human" must have at least one field selected.' ,
57+ 'Field "name" must not have a selection since type "String" has no subfields.' ,
58+ locations : [ { line : 1 , column : 16 } ] ,
7459 } ,
7560 ] ) ;
7661 } ) ;
@@ -166,37 +151,4 @@ describe('Validate: Scalar leafs', () => {
166151 } ,
167152 ] ) ;
168153 } ) ;
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- } ) ;
202154} ) ;
0 commit comments