diff --git a/src/validation/rules/FieldsOnCorrectType.js b/src/validation/rules/FieldsOnCorrectType.js index 902df79447..fc6fb185e1 100644 --- a/src/validation/rules/FieldsOnCorrectType.js +++ b/src/validation/rules/FieldsOnCorrectType.js @@ -34,26 +34,23 @@ export function FieldsOnCorrectType(context: ValidationContext): ASTVisitor { // This field doesn't exist, lets look for suggestions. const schema = context.getSchema(); const fieldName = node.name.value; + // First determine if there are any suggested types to condition on. - const suggestedTypeNames = getSuggestedTypeNames( - schema, - type, - fieldName, + let suggestion = didYouMean( + 'to use an inline fragment on', + getSuggestedTypeNames(schema, type, fieldName), ); + // If there are no suggested types, then perhaps this was a typo? - const suggestedFieldNames = - suggestedTypeNames.length !== 0 - ? [] - : getSuggestedFieldNames(schema, type, fieldName); + if (suggestion === '') { + suggestion = didYouMean(getSuggestedFieldNames(type, fieldName)); + } // Report an error, including helpful suggestions. context.reportError( new GraphQLError( `Cannot query field "${fieldName}" on type "${type.name}".` + - (didYouMean( - 'to use an inline fragment on', - suggestedTypeNames, - ) || didYouMean(suggestedFieldNames)), + suggestion, node, ), ); @@ -110,7 +107,6 @@ function getSuggestedTypeNames( * that may be the result of a typo. */ function getSuggestedFieldNames( - _schema: GraphQLSchema, type: GraphQLOutputType, fieldName: string, ): Array {