Skip to content

Commit f4078e1

Browse files
glen-84michaelstaib
authored andcommitted
Improved error message when query/mutation conventions are not enabled (#8130)
1 parent bd92368 commit f4078e1

File tree

4 files changed

+73
-13
lines changed

4 files changed

+73
-13
lines changed

src/HotChocolate/Core/src/Types.Errors/Properties/ErrorResources.Designer.cs

Lines changed: 32 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/HotChocolate/Core/src/Types.Errors/Properties/ErrorResources.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
2020
</resheader>
2121
<data name="ErrorConventionDisabled_Message" xml:space="preserve">
22-
<value>Adding an error type `{0}` to field `{1}` failed as error conventions weren't enabled.</value>
22+
<value>Adding an error type `{0}` to field `{1}` failed as query or mutation conventions were not enabled.</value>
2323
</data>
2424
<data name="ThrowHelper_ErrorObjectType_MessageWasNotDefinedOnError" xml:space="preserve">
2525
<value>Error while building type {0}. The runtime type {1} does not define a property named `Message`</value>

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,26 @@ public async Task InferErrorEvenIfExplicitFieldBindingIsUsed()
13031303
schema.Print().MatchSnapshot();
13041304
}
13051305

1306+
[Fact]
1307+
public async Task MutationWithError_MutationConventionsNotEnabled_ThrowsSchemaException()
1308+
{
1309+
// arrange
1310+
async Task Act() =>
1311+
await new ServiceCollection()
1312+
.AddGraphQL()
1313+
.AddMutationType<MutationWithUnionResult1>()
1314+
.BuildSchemaAsync();
1315+
1316+
// act & assert
1317+
var exception =
1318+
(SchemaException?)(await Assert.ThrowsAsync<SchemaException>(Act)).Errors[0].Exception;
1319+
1320+
Assert.Equal(
1321+
"Adding an error type `CustomException` to field `doSomething` failed as query or "
1322+
+ "mutation conventions were not enabled.",
1323+
exception?.Errors[0].Message);
1324+
}
1325+
13061326
public class ExplicitMutation
13071327
{
13081328
public FieldResult<int, ExplicitCustomError> DoSomething(int status)

src/HotChocolate/Core/test/Types.Queries.Tests/AnnotationBasedSchemaTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,26 @@ async Task Error() =>
394394
exception.Errors[0].Message.MatchSnapshot();
395395
}
396396

397+
[Fact]
398+
public async Task QueryWithError_QueryConventionsNotEnabled_ThrowsSchemaException()
399+
{
400+
// arrange
401+
async Task Act() =>
402+
await new ServiceCollection()
403+
.AddGraphQL()
404+
.AddQueryType<QueryWithFieldResultAndException>()
405+
.BuildSchemaAsync();
406+
407+
// act & assert
408+
var exception =
409+
(SchemaException?)(await Assert.ThrowsAsync<SchemaException>(Act)).Errors[0].Exception;
410+
411+
Assert.Equal(
412+
"Adding an error type `InvalidUserIdException` to field `userById` failed as query or "
413+
+ "mutation conventions were not enabled.",
414+
exception?.Errors[0].Message);
415+
}
416+
397417
public class QueryWithException
398418
{
399419
[Error<UserNotFoundException>]

0 commit comments

Comments
 (0)