Skip to content

Commit 58f59dc

Browse files
authored
Include ValidationFailure.ErrorCode in ExecutionError.Code. (#440)
1 parent ec170ca commit 58f59dc

7 files changed

Lines changed: 72 additions & 11 deletions

src/GraphQL.FluentValidation/ValidationMiddleware.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ static ExecutionError ToExecutionError(ValidationFailure failure)
2626
{
2727
return new($"{failure.PropertyName}: {failure.ErrorMessage}")
2828
{
29-
Path = new List<string> {failure.PropertyName}
29+
Path = new List<string> {failure.PropertyName},
30+
Code = failure.ErrorCode
3031
};
3132
}
3233
}

src/Tests/IntegrationTests.AsyncComplexInvalid.verified.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44
"message": "Inner: Inner async test failed msg.",
55
"path": [
66
"Inner"
7-
]
7+
],
8+
"extensions": {
9+
"code": "AsyncPredicateValidator",
10+
"codes": [
11+
"AsyncPredicateValidator"
12+
]
13+
}
814
},
915
{
1016
"message": "Inner.Content: 'Content' must not be empty.",
1117
"path": [
1218
"Inner.Content"
13-
]
19+
],
20+
"extensions": {
21+
"code": "NotEmptyValidator",
22+
"codes": [
23+
"NotEmptyValidator"
24+
]
25+
}
1426
}
1527
],
1628
"data": {

src/Tests/IntegrationTests.AsyncInvalid.verified.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
"message": "Content: The specified condition was not met for 'Content'.",
55
"path": [
66
"Content"
7-
]
7+
],
8+
"extensions": {
9+
"code": "AsyncPredicateValidator",
10+
"codes": [
11+
"AsyncPredicateValidator"
12+
]
13+
}
814
}
915
],
1016
"data": {

src/Tests/IntegrationTests.ComplexInvalid.verified.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44
"message": "Inner.Content: 'Content' must not be empty.",
55
"path": [
66
"Inner.Content"
7-
]
7+
],
8+
"extensions": {
9+
"code": "NotEmptyValidator",
10+
"codes": [
11+
"NotEmptyValidator"
12+
]
13+
}
814
},
915
{
1016
"message": "Items: 'Items' must not be empty.",
1117
"path": [
1218
"Items"
13-
]
19+
],
20+
"extensions": {
21+
"code": "NotEmptyValidator",
22+
"codes": [
23+
"NotEmptyValidator"
24+
]
25+
}
1426
}
1527
],
1628
"data": {

src/Tests/IntegrationTests.ComplexInvalid2.verified.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44
"message": "Inner: 'Inner' must not be empty.",
55
"path": [
66
"Inner"
7-
]
7+
],
8+
"extensions": {
9+
"code": "NotEmptyValidator",
10+
"codes": [
11+
"NotEmptyValidator"
12+
]
13+
}
814
},
915
{
1016
"message": "Items: 'Items' must not be empty.",
1117
"path": [
1218
"Items"
13-
]
19+
],
20+
"extensions": {
21+
"code": "NotEmptyValidator",
22+
"codes": [
23+
"NotEmptyValidator"
24+
]
25+
}
1426
}
1527
],
1628
"data": {

src/Tests/IntegrationTests.DerivedComplexInvalid.verified.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44
"message": "Inner.Content: 'Content' must not be empty.",
55
"path": [
66
"Inner.Content"
7-
]
7+
],
8+
"extensions": {
9+
"code": "NotEmptyValidator",
10+
"codes": [
11+
"NotEmptyValidator"
12+
]
13+
}
814
},
915
{
1016
"message": "Items: 'Items' must not be empty.",
1117
"path": [
1218
"Items"
13-
]
19+
],
20+
"extensions": {
21+
"code": "NotEmptyValidator",
22+
"codes": [
23+
"NotEmptyValidator"
24+
]
25+
}
1426
}
1527
],
1628
"data": {

src/Tests/IntegrationTests.Invalid.verified.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
"message": "Content: 'Content' must not be empty.",
55
"path": [
66
"Content"
7-
]
7+
],
8+
"extensions": {
9+
"code": "NotEmptyValidator",
10+
"codes": [
11+
"NotEmptyValidator"
12+
]
13+
}
814
}
915
],
1016
"data": {

0 commit comments

Comments
 (0)