1010
1111import type { ValidationContext } from '../index' ;
1212import { GraphQLError } from '../../error' ;
13- import { suggestionList } from '../../jsutils/suggestionList' ;
13+ import suggestionList from '../../jsutils/suggestionList' ;
14+ import quotedOrList from '../../jsutils/quotedOrList' ;
1415import type { Field } from '../../language/ast' ;
1516import type { GraphQLSchema } from '../../type/schema' ;
1617import type { GraphQLOutputType } from '../../type/definition' ;
@@ -28,13 +29,11 @@ export function undefinedFieldMessage(
2829 suggestedFieldNames : Array < string >
2930) : string {
3031 let message = `Cannot query field "${ fieldName } " on type "${ type } ".` ;
31- const MAX_LENGTH = 5 ;
3232 if ( suggestedTypeNames . length !== 0 ) {
33- const suggestions = quotedOrList ( suggestedTypeNames . slice ( 0 , MAX_LENGTH ) ) ;
33+ const suggestions = quotedOrList ( suggestedTypeNames ) ;
3434 message += ` Did you mean to use an inline fragment on ${ suggestions } ?` ;
3535 } else if ( suggestedFieldNames . length !== 0 ) {
36- const suggestions = quotedOrList ( suggestedFieldNames . slice ( 0 , MAX_LENGTH ) ) ;
37- message += ` Did you mean ${ suggestions } ?` ;
36+ message += ` Did you mean ${ quotedOrList ( suggestedFieldNames ) } ?` ;
3837 }
3938 return message ;
4039}
@@ -139,15 +138,3 @@ function getSuggestedFieldNames(
139138 // Otherwise, must be a Union type, which does not define fields.
140139 return [ ] ;
141140}
142-
143- /**
144- * Given [ A, B, C ] return '"A", "B", or "C"'.
145- */
146- function quotedOrList ( items : Array < string > ) : string {
147- return items . map ( item => `"${ item } "` ) . reduce ( ( list , quoted , index ) =>
148- list +
149- ( items . length > 2 ? ', ' : ' ' ) +
150- ( index === items . length - 1 ? 'or ' : '' ) +
151- quoted
152- ) ;
153- }
0 commit comments