Skip to content

Commit

Permalink
Fixed projections with multiple interceptors. (#2836)
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn authored Jan 13, 2021
1 parent bb459e3 commit 14f799f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using HotChocolate.Execution.Processing;

namespace HotChocolate.Data.Projections.Handlers
{
/// <summary>
/// This wrapper is used to combined two interceptors and create a chain
/// </summary>
internal class ProjectionInterceptorCombinator<T>
: IProjectionFieldInterceptor<T>
where T : IProjectionVisitorContext
{
private readonly IProjectionFieldInterceptor _current;
private readonly IProjectionFieldInterceptor _next;

public ProjectionInterceptorCombinator(
IProjectionFieldInterceptor current,
IProjectionFieldInterceptor next)
{
_current = current;
_next = next;
}

public bool CanHandle(ISelection selection) => true;

public void BeforeProjection(
T context,
ISelection selection)
{
if (_current is IProjectionFieldInterceptor<T> currentHandler)
{
currentHandler.BeforeProjection(context, selection);
}

if (_next is IProjectionFieldInterceptor<T> nextHandler)
{
nextHandler.BeforeProjection(context, selection);
}
}

public void AfterProjection(T context, ISelection selection)
{
if (_next is IProjectionFieldInterceptor<T> nextHandler)
{
nextHandler.AfterProjection(context, selection);
}

if (_current is IProjectionFieldInterceptor<T> currentHandler)
{
currentHandler.AfterProjection(context, selection);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using HotChocolate.Data.Projections.Handlers;
using HotChocolate.Execution.Processing;

namespace HotChocolate.Data.Projections.Expressions.Handlers
Expand All @@ -22,7 +23,7 @@ public bool CanHandle(ISelection selection) =>
_handler.CanHandle(selection);

public IProjectionFieldHandler Wrap(IProjectionFieldInterceptor interceptor) =>
_handler.Wrap(interceptor);
_handler.Wrap(new ProjectionInterceptorCombinator<T>(_interceptor, interceptor));

public T OnBeforeEnter(T context, ISelection selection) =>
_handler.OnBeforeEnter(context, selection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ argVisitor is VisitFilterArgument argumentVisitor &&
out IReadOnlyDictionary<NameString, ArgumentValue>? coercedArgs) &&
coercedArgs.TryGetValue(argumentName, out var argumentValue) &&
argumentValue.Argument.Type is IFilterInputType filterInputType &&
argumentValue.ValueLiteral is {} valueNode &&
argumentValue.ValueLiteral is { } valueNode &&
valueNode is not NullValueNode)
{
QueryableFilterContext filterContext =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ public class FooNullable
public bool? BarBool { get; set; }

[UseFiltering]
[UseSorting]
public List<BarNullableDeep?>? ObjectArray { get; set; }

public BarNullableDeep? NestedObject { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ public class Foo

public bool BarBool { get; set; }

[UseFiltering]
[UseSorting]
public List<BarDeep> ObjectArray { get; set; }

Expand Down

0 comments on commit 14f799f

Please sign in to comment.