Skip to content

Commit 81b06d9

Browse files
authored
Used pure resolver for errors field in custom mutation payloads (#7691)
1 parent a9f442c commit 81b06d9

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/HotChocolate/Core/src/Types.Mutations/MutationConventionTypeInterceptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,10 @@ private void TryApplyPayloadConvention(
395395
new ObjectFieldDefinition(
396396
options.PayloadErrorsFieldName,
397397
type: errorListTypeRef,
398-
resolver: ctx =>
398+
pureResolver: ctx =>
399399
{
400400
ctx.ScopedContextData.TryGetValue(Errors, out var errors);
401-
return new ValueTask<object?>(errors);
401+
return errors;
402402
}));
403403

404404
// collect error factories for middleware

src/HotChocolate/Core/test/Types.Mutations.Tests/AnnotationBasedMutations.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,21 @@ public async Task SimpleMutation_Override_Payload()
436436
schema.MatchSnapshot();
437437
}
438438

439+
[Fact]
440+
public async Task SimpleMutation_Override_Payload_WithError()
441+
{
442+
var schema =
443+
await new ServiceCollection()
444+
.AddGraphQL()
445+
.AddCostAnalyzer()
446+
.AddMutationType<SimpleMutationPayloadOverrideWithError>()
447+
.AddMutationConventions(true)
448+
.ModifyOptions(o => o.StrictValidation = false)
449+
.BuildSchemaAsync();
450+
451+
schema.MatchSnapshot();
452+
}
453+
439454
[Fact]
440455
public async Task SimpleMutation_Override_Input()
441456
{
@@ -1356,6 +1371,15 @@ public DoSomethingPayload DoSomething(string something)
13561371
}
13571372
}
13581373

1374+
public class SimpleMutationPayloadOverrideWithError
1375+
{
1376+
[Error(typeof(CustomException))]
1377+
public DoSomethingPayload DoSomething()
1378+
{
1379+
return new DoSomethingPayload();
1380+
}
1381+
}
1382+
13591383
public class DoSomethingPayload
13601384
{
13611385
public string MyResult1 { get; set; } = default!;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
schema {
2+
mutation: SimpleMutationPayloadOverrideWithError
3+
}
4+
5+
interface Error {
6+
message: String!
7+
}
8+
9+
type CustomError implements Error {
10+
message: String!
11+
}
12+
13+
type DoSomethingPayload {
14+
myResult1: String
15+
myResult2: String
16+
errors: [DoSomethingError!]
17+
}
18+
19+
type SimpleMutationPayloadOverrideWithError {
20+
doSomething: DoSomethingPayload!
21+
}
22+
23+
union DoSomethingError = CustomError

0 commit comments

Comments
 (0)