From 595f3b1cfa0ae27a20d8c882dd38a4ed7ea18667 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Fri, 12 Feb 2021 12:34:13 +0100 Subject: [PATCH] Include ValidationFailure.ErrorCode in ExecutionError.Code. --- .../ValidationMiddleware.cs | 3 ++- ...grationTests.AsyncComplexInvalid.verified.txt | 16 ++++++++++++++-- .../IntegrationTests.AsyncInvalid.verified.txt | 8 +++++++- .../IntegrationTests.ComplexInvalid.verified.txt | 16 ++++++++++++++-- ...IntegrationTests.ComplexInvalid2.verified.txt | 16 ++++++++++++++-- ...ationTests.DerivedComplexInvalid.verified.txt | 16 ++++++++++++++-- src/Tests/IntegrationTests.Invalid.verified.txt | 8 +++++++- 7 files changed, 72 insertions(+), 11 deletions(-) diff --git a/src/GraphQL.FluentValidation/ValidationMiddleware.cs b/src/GraphQL.FluentValidation/ValidationMiddleware.cs index 871a027d..41d70c60 100644 --- a/src/GraphQL.FluentValidation/ValidationMiddleware.cs +++ b/src/GraphQL.FluentValidation/ValidationMiddleware.cs @@ -26,7 +26,8 @@ static ExecutionError ToExecutionError(ValidationFailure failure) { return new($"{failure.PropertyName}: {failure.ErrorMessage}") { - Path = new List {failure.PropertyName} + Path = new List {failure.PropertyName}, + Code = failure.ErrorCode }; } } \ No newline at end of file diff --git a/src/Tests/IntegrationTests.AsyncComplexInvalid.verified.txt b/src/Tests/IntegrationTests.AsyncComplexInvalid.verified.txt index c1901725..0446fcd9 100644 --- a/src/Tests/IntegrationTests.AsyncComplexInvalid.verified.txt +++ b/src/Tests/IntegrationTests.AsyncComplexInvalid.verified.txt @@ -4,13 +4,25 @@ "message": "Inner: Inner async test failed msg.", "path": [ "Inner" - ] + ], + "extensions": { + "code": "AsyncPredicateValidator", + "codes": [ + "AsyncPredicateValidator" + ] + } }, { "message": "Inner.Content: 'Content' must not be empty.", "path": [ "Inner.Content" - ] + ], + "extensions": { + "code": "NotEmptyValidator", + "codes": [ + "NotEmptyValidator" + ] + } } ], "data": { diff --git a/src/Tests/IntegrationTests.AsyncInvalid.verified.txt b/src/Tests/IntegrationTests.AsyncInvalid.verified.txt index ee0caad3..c8f29a25 100644 --- a/src/Tests/IntegrationTests.AsyncInvalid.verified.txt +++ b/src/Tests/IntegrationTests.AsyncInvalid.verified.txt @@ -4,7 +4,13 @@ "message": "Content: The specified condition was not met for 'Content'.", "path": [ "Content" - ] + ], + "extensions": { + "code": "AsyncPredicateValidator", + "codes": [ + "AsyncPredicateValidator" + ] + } } ], "data": { diff --git a/src/Tests/IntegrationTests.ComplexInvalid.verified.txt b/src/Tests/IntegrationTests.ComplexInvalid.verified.txt index 905291a1..9969ca3f 100644 --- a/src/Tests/IntegrationTests.ComplexInvalid.verified.txt +++ b/src/Tests/IntegrationTests.ComplexInvalid.verified.txt @@ -4,13 +4,25 @@ "message": "Inner.Content: 'Content' must not be empty.", "path": [ "Inner.Content" - ] + ], + "extensions": { + "code": "NotEmptyValidator", + "codes": [ + "NotEmptyValidator" + ] + } }, { "message": "Items: 'Items' must not be empty.", "path": [ "Items" - ] + ], + "extensions": { + "code": "NotEmptyValidator", + "codes": [ + "NotEmptyValidator" + ] + } } ], "data": { diff --git a/src/Tests/IntegrationTests.ComplexInvalid2.verified.txt b/src/Tests/IntegrationTests.ComplexInvalid2.verified.txt index 96510fe4..ec4ebb05 100644 --- a/src/Tests/IntegrationTests.ComplexInvalid2.verified.txt +++ b/src/Tests/IntegrationTests.ComplexInvalid2.verified.txt @@ -4,13 +4,25 @@ "message": "Inner: 'Inner' must not be empty.", "path": [ "Inner" - ] + ], + "extensions": { + "code": "NotEmptyValidator", + "codes": [ + "NotEmptyValidator" + ] + } }, { "message": "Items: 'Items' must not be empty.", "path": [ "Items" - ] + ], + "extensions": { + "code": "NotEmptyValidator", + "codes": [ + "NotEmptyValidator" + ] + } } ], "data": { diff --git a/src/Tests/IntegrationTests.DerivedComplexInvalid.verified.txt b/src/Tests/IntegrationTests.DerivedComplexInvalid.verified.txt index c19b17a2..b103127b 100644 --- a/src/Tests/IntegrationTests.DerivedComplexInvalid.verified.txt +++ b/src/Tests/IntegrationTests.DerivedComplexInvalid.verified.txt @@ -4,13 +4,25 @@ "message": "Inner.Content: 'Content' must not be empty.", "path": [ "Inner.Content" - ] + ], + "extensions": { + "code": "NotEmptyValidator", + "codes": [ + "NotEmptyValidator" + ] + } }, { "message": "Items: 'Items' must not be empty.", "path": [ "Items" - ] + ], + "extensions": { + "code": "NotEmptyValidator", + "codes": [ + "NotEmptyValidator" + ] + } } ], "data": { diff --git a/src/Tests/IntegrationTests.Invalid.verified.txt b/src/Tests/IntegrationTests.Invalid.verified.txt index bef250cb..e40f8bcd 100644 --- a/src/Tests/IntegrationTests.Invalid.verified.txt +++ b/src/Tests/IntegrationTests.Invalid.verified.txt @@ -4,7 +4,13 @@ "message": "Content: 'Content' must not be empty.", "path": [ "Content" - ] + ], + "extensions": { + "code": "NotEmptyValidator", + "codes": [ + "NotEmptyValidator" + ] + } } ], "data": {