diff --git a/packages/commands/validate/__tests__/validate-command.test.ts b/packages/commands/validate/__tests__/validate-command.test.ts index 94fcec4bc0..4086e33320 100644 --- a/packages/commands/validate/__tests__/validate-command.test.ts +++ b/packages/commands/validate/__tests__/validate-command.test.ts @@ -11,6 +11,7 @@ const schema = buildSchema(/* GraphQL */ ` title: String createdAt: String modifiedAt: String + deprecatedTitle: String @deprecated(reason: "Will be deleted") } type Query { @@ -60,6 +61,16 @@ const validate = createCommand({ `), location: 'valid-document.graphql', }, + { + document: parse(/* GraphQL */ ` + query post { + post { + deprecatedTitle + } + } + `), + location: 'with-deprecated-only.graphql', + }, ]; }, }, @@ -116,4 +127,11 @@ describe('validate', () => { expect(spyReporter).not.toHaveBeenCalledNormalized('document.graphql:'); }); + + test('should log deprecation when file has only deprecation', async () => { + await mockCommand(validate, 'validate "*.graphql" schema.graphql'); + + expect(spyReporter).toHaveBeenCalledNormalized('in with-deprecated-only.graphql'); + expect(spyReporter).toHaveBeenCalledNormalized('The field Post.deprecatedTitle is deprecated. Will be deleted'); + }) }); diff --git a/packages/commands/validate/src/index.ts b/packages/commands/validate/src/index.ts index 63e61d134a..5fd220ebf7 100644 --- a/packages/commands/validate/src/index.ts +++ b/packages/commands/validate/src/index.ts @@ -366,7 +366,7 @@ function printInvalidDocuments( } for (const doc of invalidDocuments) { - if (doc.errors.length) { + if (doc[listKey].length) { for (const line of renderErrors(doc.source.name, doc[listKey], isError)) { Logger.log(line); }