Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues in filter combinators. #4490

Merged
merged 4 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override bool TryCombineOperations(
FilterCombinator combinator,
[NotNullWhen(true)] out Expression combined)
{
if (operations.Count < 1)
if (operations.Count == 0)
{
throw ThrowHelper.Filtering_QueryableCombinator_QueueEmpty(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ public override bool TryCombineOperations(
FilterCombinator combinator,
[NotNullWhen(true)] out MongoDbFilterDefinition combined)
{
if (operations.Count < 1)
if (operations.Count == 0)
{
throw new InvalidOperationException();
throw ThrowHelper.Filtering_MongoDbCombinator_QueueEmpty(this);
}

combined = combinator switch
{
FilterCombinator.And => CombineWithAnd(context, operations),
FilterCombinator.Or => CombineWithOr(context, operations),
_ => throw new InvalidOperationException()
_ => throw ThrowHelper
.Filtering_MongoDbCombinator_InvalidCombinator(this, combinator)
};

return true;
Expand Down
12 changes: 12 additions & 0 deletions src/HotChocolate/MongoDb/src/Data/MongoDbResources.Designer.cs

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

7 changes: 6 additions & 1 deletion src/HotChocolate/MongoDb/src/Data/MongoDbResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@
<data name="Paging_SourceIsNotSupported" xml:space="preserve">
<value>The provided source {0} is not supported for mongo paging</value>
</data>

<data name="Filtering_MongoDbCombinator_QueueEmpty" xml:space="preserve">
<value>MongoDbCombinator {0} could not combine expressions. There were no expressions to combine.</value>
</data>
<data name="Filtering_MongoDbCombinator_InvalidCombinator" xml:space="preserve">
<value>MongoDbCombinator {0} could not combine expression. {1} is a invalid combinator</value>
</data>
</root>
19 changes: 19 additions & 0 deletions src/HotChocolate/MongoDb/src/Data/ThrowHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using System.Globalization;
using HotChocolate.Data.Filters;
using HotChocolate.Data.MongoDb.Filters;

namespace HotChocolate.Data.MongoDb
{
Expand All @@ -14,5 +17,21 @@ public static GraphQLException PagingTypeNotSupported(Type type)
.SetCode(ErrorCodes.Data.NoPagingationProviderFound)
.Build());
}

public static InvalidOperationException Filtering_MongoDbCombinator_QueueEmpty(
MongoDbFilterCombinator combinator) =>
new(string.Format(
CultureInfo.CurrentCulture,
MongoDbResources.Filtering_MongoDbCombinator_QueueEmpty,
combinator.GetType()));

public static InvalidOperationException Filtering_MongoDbCombinator_InvalidCombinator(
MongoDbFilterCombinator combinator,
FilterCombinator operation) =>
new(string.Format(
CultureInfo.CurrentCulture,
MongoDbResources.Filtering_MongoDbCombinator_InvalidCombinator,
combinator.GetType(),
operation.ToString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ public override bool TryCombineOperations(
FilterCombinator combinator,
[NotNullWhen(true)] out Condition combined)
{
if (operations.Count < 1)
if (operations.Count == 0)
{
throw new InvalidOperationException();
throw ThrowHelper.Filtering_Neo4JFilterCombinator_QueueEmpty(this);
}

combined = combinator switch
{
FilterCombinator.And => CombineWithAnd(operations),
FilterCombinator.Or => CombineWithOr(operations),
_ => throw new InvalidOperationException()
_ => throw ThrowHelper
.Filtering_Neo4JFilterCombinator_InvalidCombinator(this, combinator)
};

return true;
Expand Down
12 changes: 12 additions & 0 deletions src/HotChocolate/Neo4J/src/Data/Neo4JResources.Designer.cs

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

6 changes: 6 additions & 0 deletions src/HotChocolate/Neo4J/src/Data/Neo4JResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@
<data name="Projection_RelationshipDirectionNotSet" xml:space="preserve">
<value>Relationship direction not set.</value>
</data>
<data name="Filtering_Neo4JCombinator_QueueEmpty" xml:space="preserve">
<value>Neo4JCombinator {0} could not combine expressions. There were no expressions to combine.</value>
</data>
<data name="Filtering_Neo4JCombinator_InvalidCombinator" xml:space="preserve">
<value>Neo4JCombinator {0} could not combine expression. {1} is a invalid combinator</value>
</data>
</root>
20 changes: 20 additions & 0 deletions src/HotChocolate/Neo4J/src/Data/ThrowHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using System.Globalization;
using HotChocolate.Data.Filters;
using HotChocolate.Data.Neo4J.Filtering;

namespace HotChocolate.Data.Neo4J
{
Expand Down Expand Up @@ -36,5 +39,22 @@ public static GraphQLException PagingTypeNotSupported(Type type)
.SetCode(ErrorCodes.Data.NoPagingationProviderFound)
.Build());
}

public static InvalidOperationException Filtering_Neo4JFilterCombinator_QueueEmpty(
Neo4JFilterCombinator combinator) =>
new(string.Format(
CultureInfo.CurrentCulture,
Neo4JResources.Filtering_Neo4JCombinator_QueueEmpty,
combinator.GetType()));

public static InvalidOperationException Filtering_Neo4JFilterCombinator_InvalidCombinator(
Neo4JFilterCombinator combinator,
FilterCombinator operation) =>
new(string.Format(
CultureInfo.CurrentCulture,
Neo4JResources.Filtering_Neo4JCombinator_InvalidCombinator,
combinator.GetType(),
operation.ToString()));

}
}