Skip to content

Commit

Permalink
Improved error messages for missing conventions (#2457)
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn committed Oct 18, 2020
1 parent 5c419eb commit a9e91a9
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/HotChocolate/Data/src/Data/DataResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/HotChocolate/Data/src/Data/DataResources.resx
Expand Up @@ -93,7 +93,10 @@
<value>The filter type cannot be inferred from `System.Object`.</value>
</data>
<data name="FilterDescriptorContextExtensions_NoConvention" xml:space="preserve">
<value>No filter convention found for scope `{0}`.</value>
<value>No filter convention found for scope `{0}`. Register a convention with `AddConvention&lt;IFilterConvention, TYourConvention&gt;("{0}")` on the schema builder.</value>
</data>
<data name="FilterDescriptorContextExtensions_NoConvention_Default" xml:space="preserve">
<value>No default filter convention found. Call `AddFiltering()` on the schema builder.</value>
</data>
<data name="SortProvider_NoFieldHandlersConfigured" xml:space="preserve">
<value>The sort provider `{0}` does not specify and field handler.</value>
Expand All @@ -102,7 +105,10 @@
<value>The sort provider `{0}` does not specify and operation handler.</value>
</data>
<data name="SortDescriptorContextExtensions_NoConvention" xml:space="preserve">
<value>No sorting convention found for scope `{0}`.</value>
<value>No sorting convention found for scope `{0}`. Register a convention with `AddConvention&lt;ISortConvention, TYourConvention&gt;("{0}")` on the schema builder.</value>
</data>
<data name="SortDescriptorContextExtensions_NoConvention_Default" xml:space="preserve">
<value>No default sorting convention found. Call `AddSorting()` on the schema builder.</value>
</data>
<data name="SortInterceptor_NoFieldHandlerFoundForField" xml:space="preserve">
<value>For the field {0} of type {1} was no field handler found.</value>
Expand Down
8 changes: 6 additions & 2 deletions src/HotChocolate/Data/src/Data/ThrowHelper.cs
Expand Up @@ -79,7 +79,9 @@ internal static class ThrowHelper
new SchemaException(
SchemaErrorBuilder.New()
.SetMessage(
DataResources.FilterDescriptorContextExtensions_NoConvention,
scope is null
? DataResources.FilterDescriptorContextExtensions_NoConvention_Default
: DataResources.FilterDescriptorContextExtensions_NoConvention,
scope ?? "none")
.SetExtension(nameof(scope), scope)
.Build());
Expand Down Expand Up @@ -109,7 +111,9 @@ internal static class ThrowHelper
new SchemaException(
SchemaErrorBuilder.New()
.SetMessage(
DataResources.SortDescriptorContextExtensions_NoConvention,
scope is null
? DataResources.SortDescriptorContextExtensions_NoConvention_Default
: DataResources.SortDescriptorContextExtensions_NoConvention,
scope ?? "none")
.SetExtension(nameof(scope), scope)
.Build());
Expand Down
Expand Up @@ -243,6 +243,40 @@ public void FilterInputType_ExplicitBinding_BindFields()
schema.ToString().MatchSnapshot();
}

[Fact]
public void FilterInputType_Should_ThrowException_WhenNoConventionIsRegistered()
{
// arrange
ISchemaBuilder builder = SchemaBuilder.New()
.AddQueryType(c =>
c.Name("Query")
.Field("foo")
.Resolve(new List<Foo>())
.UseFiltering("Foo"));

// act
// assert
SchemaException exception = Assert.Throws<SchemaException>(() => builder.Create());
exception.Message.MatchSnapshot();
}

[Fact]
public void FilterInputType_Should_ThrowException_WhenNoConventionIsRegisteredDefault()
{
// arrange
ISchemaBuilder builder = SchemaBuilder.New()
.AddQueryType(c =>
c.Name("Query")
.Field("foo")
.Resolve(new List<Foo>())
.UseFiltering());

// act
// assert
SchemaException exception = Assert.Throws<SchemaException>(() => builder.Create());
exception.Message.MatchSnapshot();
}

public class FooDirectiveType
: DirectiveType<FooDirective>
{
Expand Down
@@ -0,0 +1,6 @@
For more details look at the `Errors` property.

1. For more details look at the `Errors` property.

1. No filter convention found for scope `Foo`. Register a convention with `AddConvention<IFilterConvention, TYourConvention>("Foo")` on the schema builder.
(HotChocolate.Data.Filters.FilterInputType<HotChocolate.Data.Tests.FilterInputTypeTest.Foo>)
@@ -0,0 +1,6 @@
For more details look at the `Errors` property.

1. For more details look at the `Errors` property.

1. No default filter convention found. Call `AddFiltering()` on the schema builder.
(HotChocolate.Data.Filters.FilterInputType<HotChocolate.Data.Tests.FilterInputTypeTest.Foo>)
Expand Up @@ -156,6 +156,40 @@ public void SortInput_AddName()
schema.ToString().MatchSnapshot();
}

[Fact]
public void SortInputType_Should_ThrowException_WhenNoConventionIsRegistered()
{
// arrange
ISchemaBuilder builder = SchemaBuilder.New()
.AddQueryType(c =>
c.Name("Query")
.Field("foo")
.Resolve(new List<Foo>())
.UseSorting("Foo"));

// act
// assert
SchemaException exception = Assert.Throws<SchemaException>(() => builder.Create());
exception.Message.MatchSnapshot();
}

[Fact]
public void SortInputType_Should_ThrowException_WhenNoConventionIsRegisteredDefault()
{
// arrange
ISchemaBuilder builder = SchemaBuilder.New()
.AddQueryType(c =>
c.Name("Query")
.Field("foo")
.Resolve(new List<Foo>())
.UseSorting());

// act
// assert
SchemaException exception = Assert.Throws<SchemaException>(() => builder.Create());
exception.Message.MatchSnapshot();
}

public class FooDirectiveType
: DirectiveType<FooDirective>
{
Expand Down
@@ -0,0 +1,6 @@
For more details look at the `Errors` property.

1. For more details look at the `Errors` property.

1. No sorting convention found for scope `Foo`. Register a convention with `AddConvention<ISortConvention, TYourConvention>("Foo")` on the schema builder.
(HotChocolate.Data.Sorting.SortInputType<HotChocolate.Data.Tests.SortInputTypeTest.Foo>)
@@ -0,0 +1,6 @@
For more details look at the `Errors` property.

1. For more details look at the `Errors` property.

1. No default sorting convention found. Call `AddSorting()` on the schema builder.
(HotChocolate.Data.Sorting.SortInputType<HotChocolate.Data.Tests.SortInputTypeTest.Foo>)

0 comments on commit a9e91a9

Please sign in to comment.