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

Rename enable Filter and Sorting Context #4919

Merged
merged 3 commits into from
Apr 4, 2022
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 @@ -30,15 +30,15 @@ public FilterContext(
}

/// <inheritdoc />
public void EnableFilterExecution(bool enable = true)
public void Handled(bool isHandled)
{
if (enable)
if (isHandled)
{
_context.LocalContextData = _context.LocalContextData.Remove(SkipFilteringKey);
_context.LocalContextData = _context.LocalContextData.SetItem(SkipFilteringKey, true);
}
else
{
_context.LocalContextData = _context.LocalContextData.SetItem(SkipFilteringKey, true);
_context.LocalContextData = _context.LocalContextData.Remove(SkipFilteringKey);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ context.LocalContextData[ContextValueNodeKey] is IValueNode node
new(context, filterInput, filter, context.Service<InputParser>());

// disable the execution of filtering by default
filterContext.EnableFilterExecution(false);
filterContext.Handled(true);

return filterContext;
}
Expand Down
10 changes: 5 additions & 5 deletions src/HotChocolate/Data/src/Data/Filters/Context/IFilterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
namespace HotChocolate.Data.Filters;

/// <summary>
/// Encapuslates all filter specific information
/// Encapsulates all filter specific information
/// </summary>
public interface IFilterContext : IFilterInfo
{
/// <summary>
/// Enables the filter exceution if <paramref name="skip"/> is <c>true</c>.
/// You want to enable the execution of the filtering when you do not handle the execution
/// Specifies the sorting execution if <paramref name="isHandled"/> is <c>false</c>.
/// You want to enable the execution of the sorting when you do not handle the execution
/// manually
/// </summary>
/// <param name="enable">If true, filtering is applied on the result of the resolver</param>
void EnableFilterExecution(bool enable = true);
/// <param name="isHandled">If false, sorting is applied on the result of the resolver</param>
void Handled(bool isHandled);

/// <summary>
/// Serializes the input object to a dictionary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
namespace HotChocolate.Data.Sorting;

/// <summary>
/// Encapuslates all sorting specific information
/// Encapsulates all sorting specific information
/// </summary>
public interface ISortingContext
{
/// <summary>
/// Enables the sorting exceution if <paramref name="enable"/> is <c>true</c>.
/// Specifies the sorting execution if <paramref name="isHandled"/> is <c>false</c>.
/// You want to enable the execution of the sorting when you do not handle the execution
/// manually
/// </summary>
/// <param name="enable">If true, sorting is applied on the result of the resolver</param>
void EnableSortingExecution(bool enable = true);
/// <param name="isHandled">If false, sorting is applied on the result of the resolver</param>
void Handled(bool isHandled);

/// <summary>
/// Serializes the input object to a dictionary
Expand Down
22 changes: 11 additions & 11 deletions src/HotChocolate/Data/src/Data/Sorting/Context/SortingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace HotChocolate.Data.Sorting;

/// <summary>
/// Encapuslates all sorting specific information
/// Encapsulated all sorting specific information
/// </summary>
public class SortingContext : ISortingContext
{
Expand All @@ -29,20 +29,20 @@ public SortingContext(
? listValueNode.Items
.Select(x => new SortingInfo(type, x, inputParser))
.ToArray()
: new[] { new SortingInfo(type, valueNode, inputParser) };
: new[] {new SortingInfo(type, valueNode, inputParser)};
_context = context;
}

/// <inheritdoc />
public void EnableSortingExecution(bool enable = true)
public void Handled(bool isHandled)
{
if (enable)
if (isHandled)
{
_context.LocalContextData = _context.LocalContextData.Remove(SkipSortingKey);
_context.LocalContextData = _context.LocalContextData.SetItem(SkipSortingKey, true);
}
else
{
_context.LocalContextData = _context.LocalContextData.SetItem(SkipSortingKey, true);
_context.LocalContextData = _context.LocalContextData.Remove(SkipSortingKey);
}
}

Expand All @@ -53,12 +53,12 @@ public IReadOnlyList<IReadOnlyList<ISortingFieldInfo>> GetFields()
/// <inheritdoc />
public IList<IDictionary<string, object?>> ToList()
=> _value
.Select(x => Serialize(x))
.OfType<IDictionary<string, object?>>()
.Where(x => x.Count > 0)
.ToArray();
.Select(Serialize)
.OfType<IDictionary<string, object?>>()
.Where(x => x.Count > 0)
.ToArray();

private object? Serialize(ISortingValueNode? value)
private static object? Serialize(ISortingValueNode? value)
{
switch (value)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using HotChocolate.Data.Sorting.Expressions;
using HotChocolate.Language;
using HotChocolate.Resolvers;
using HotChocolate.Types;
Expand Down Expand Up @@ -35,8 +34,8 @@ public static class SortingContextResolverContextExtensions
SortingContext sortingContext =
new(context, sortingInput, sorting, context.Service<InputParser>());

// disable the execution of sortinging by default
sortingContext.EnableSortingExecution(false);
// disable the execution of sorting by default
sortingContext.Handled(true);

return sortingContext;
}
Expand Down