Skip to content

Commit ec2b814

Browse files
committed
Started working on simplifying layered data features
1 parent 43e9a88 commit ec2b814

File tree

11 files changed

+153
-11
lines changed

11 files changed

+153
-11
lines changed

src/GreenDonut/src/Core/Selectors/SelectionDataLoaderExtensions.cs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static IDataLoader<TKey, TValue> Include<TKey, TValue>(
148148
/// <param name="query">
149149
/// The queryable to apply the selector to.
150150
/// </param>
151-
/// <param name="key">
151+
/// <param name="keySelector">
152152
/// The DataLoader key.
153153
/// </param>
154154
/// <param name="builder">
@@ -163,8 +163,9 @@ public static IDataLoader<TKey, TValue> Include<TKey, TValue>(
163163
/// <exception cref="ArgumentNullException">
164164
/// Throws if <paramref name="query"/> is <c>null</c>.
165165
/// </exception>
166-
public static IQueryable<T> Select<T>(this IQueryable<T> query,
167-
Expression<Func<T, object?>> key,
166+
public static IQueryable<T> Select<T>(
167+
this IQueryable<T> query,
168+
Expression<Func<T, object?>> keySelector,
168169
ISelectorBuilder builder)
169170
{
170171
if (query is null)
@@ -181,7 +182,43 @@ public static IQueryable<T> Select<T>(this IQueryable<T> query,
181182

182183
if (selector is not null)
183184
{
184-
query = query.Select(Combine(selector, Rewrite(key)));
185+
query = query.Select(Combine(selector, Rewrite(keySelector)));
186+
}
187+
188+
return query;
189+
}
190+
191+
/// <summary>
192+
/// Applies the selector from the DataLoader state to a queryable.
193+
/// </summary>
194+
/// <typeparam name="T">
195+
/// The queryable type.
196+
/// </typeparam>
197+
/// <param name="query">
198+
/// The queryable to apply the selector to.
199+
/// </param>
200+
/// <param name="keySelector">
201+
/// The DataLoader key.
202+
/// </param>
203+
/// <param name="selector">
204+
/// The selector.
205+
/// </param>
206+
/// <returns>
207+
/// Returns the query with the selector applied.
208+
/// </returns>
209+
public static IQueryable<T> Select<T>(
210+
this IQueryable<T> query,
211+
Expression<Func<T, object?>> keySelector,
212+
Expression<Func<T, T>>? selector)
213+
{
214+
if (query is null)
215+
{
216+
throw new ArgumentNullException(nameof(query));
217+
}
218+
219+
if (selector is not null)
220+
{
221+
query = query.Select(Combine(selector, Rewrite(keySelector)));
185222
}
186223

187224
return query;

src/HotChocolate/Primitives/HotChocolate.Primitives.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{B598E71D-7
1111
EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Primitives.Tests", "test\Primitives.Tests\HotChocolate.Primitives.Tests.csproj", "{F7643027-2CEF-4F06-8DFA-46FFA8C17C4F}"
1313
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Data.Primitives", "src\Primitives.Data\HotChocolate.Data.Primitives.csproj", "{A4522BC2-46E0-4242-A57B-CB4474B3F7C6}"
15+
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Data.Primitives.Tests", "test\Primitives.Data.Tests\HotChocolate.Data.Primitives.Tests.csproj", "{834E3126-D4D4-4CD3-A0C6-348A717708B1}"
17+
EndProject
1418
Global
1519
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1620
Debug|Any CPU = Debug|Any CPU
@@ -28,9 +32,19 @@ Global
2832
{F7643027-2CEF-4F06-8DFA-46FFA8C17C4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
2933
{F7643027-2CEF-4F06-8DFA-46FFA8C17C4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
3034
{F7643027-2CEF-4F06-8DFA-46FFA8C17C4F}.Release|Any CPU.Build.0 = Release|Any CPU
35+
{A4522BC2-46E0-4242-A57B-CB4474B3F7C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{A4522BC2-46E0-4242-A57B-CB4474B3F7C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{A4522BC2-46E0-4242-A57B-CB4474B3F7C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
38+
{A4522BC2-46E0-4242-A57B-CB4474B3F7C6}.Release|Any CPU.Build.0 = Release|Any CPU
39+
{834E3126-D4D4-4CD3-A0C6-348A717708B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40+
{834E3126-D4D4-4CD3-A0C6-348A717708B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
41+
{834E3126-D4D4-4CD3-A0C6-348A717708B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
42+
{834E3126-D4D4-4CD3-A0C6-348A717708B1}.Release|Any CPU.Build.0 = Release|Any CPU
3143
EndGlobalSection
3244
GlobalSection(NestedProjects) = preSolution
3345
{F5CEC44C-8AB9-4639-9B38-4F523E3ABF2A} = {42689032-4007-47A4-B045-12D2681BF2CF}
3446
{F7643027-2CEF-4F06-8DFA-46FFA8C17C4F} = {B598E71D-74BD-4055-A2F7-10B7DB892ECB}
47+
{A4522BC2-46E0-4242-A57B-CB4474B3F7C6} = {42689032-4007-47A4-B045-12D2681BF2CF}
48+
{834E3126-D4D4-4CD3-A0C6-348A717708B1} = {B598E71D-74BD-4055-A2F7-10B7DB892ECB}
3549
EndGlobalSection
3650
EndGlobal

src/HotChocolate/Primitives/src/Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
<PropertyGroup>
66
<NoWarn>$(NoWarn);CA1812</NoWarn>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
79
</PropertyGroup>
810

911
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<PackageId>HotChocolate.Data.Primitives</PackageId>
5+
<AssemblyName>HotChocolate.Data.Primitives</AssemblyName>
6+
<RootNamespace>HotChocolate.Data</RootNamespace>
7+
</PropertyGroup>
8+
9+
10+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Linq.Expressions;
2+
3+
namespace HotChocolate.Data;
4+
5+
/// <summary>
6+
/// Represents a sort operation on a field.
7+
/// </summary>
8+
/// <typeparam name="T">
9+
/// The entity type on which the sort operation is applied.
10+
/// </typeparam>
11+
/// <param name="KeySelector">
12+
/// The field on which the sort operation is applied.
13+
/// </param>
14+
/// <param name="Ascending">
15+
/// Specifies the sort directive.
16+
/// If <c>true</c> the sort is ascending, otherwise descending.
17+
/// </param>
18+
public sealed record SortBy<T>(
19+
Expression<Func<T, object>> KeySelector,
20+
bool Ascending = true);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Collections.Immutable;
2+
3+
namespace HotChocolate.Data;
4+
5+
/// <summary>
6+
/// Represents all sort operations applied to an entity type.
7+
/// </summary>
8+
/// <typeparam name="T">
9+
/// The entity type on which the sort operations are applied.
10+
/// </typeparam>
11+
public sealed record SortDefinition<T>
12+
{
13+
/// <summary>
14+
/// Initializes a new instance of <see cref="SortDefinition{T}"/>.
15+
/// </summary>
16+
/// <param name="items">
17+
/// The sort operations.
18+
/// </param>
19+
public SortDefinition(params SortBy<T>[] items)
20+
{
21+
Operations = [..items];
22+
}
23+
24+
/// <summary>
25+
/// Initializes a new instance of <see cref="SortDefinition{T}"/>.
26+
/// </summary>
27+
/// <param name="items">
28+
/// The sort operations.
29+
/// </param>
30+
public SortDefinition(IEnumerable<SortBy<T>> items)
31+
{
32+
Operations = [..items];
33+
}
34+
35+
/// <summary>
36+
/// The sort operations.
37+
/// </summary>
38+
public ImmutableArray<SortBy<T>> Operations { get; init; }
39+
40+
/// <summary>
41+
/// Deconstructs the sort operations.
42+
/// </summary>
43+
/// <param name="operations">
44+
/// The sort operations.
45+
/// </param>
46+
public void Deconstruct(out ImmutableArray<SortBy<T>> operations)
47+
=> operations = Operations;
48+
}

src/HotChocolate/Primitives/src/Primitives/HotChocolate.Primitives.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
<AutoGen>True</AutoGen>
1717
<DependentUpon>AbstractionResources.resx</DependentUpon>
1818
</Compile>
19-
<Compile Update="Properties\PrimitivesResources.Designer.cs">
20-
<DesignTime>True</DesignTime>
21-
<AutoGen>True</AutoGen>
22-
<DependentUpon>PrimitivesResources.resx</DependentUpon>
23-
</Compile>
2419
</ItemGroup>
2520

2621
<ItemGroup>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="Current">
2+
3+
<PropertyGroup>
4+
<AssemblyName>HotChocolate.Data.Primitives.Tests</AssemblyName>
5+
<RootNamespace>HotChocolate.Data</RootNamespace>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\src\Primitives.Data\HotChocolate.Data.Primitives.csproj" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using HotChocolate.Utilities;
2+
3+
namespace HotChocolate.Primitives;
4+

src/HotChocolate/Primitives/test/Primitives.Tests/HotChocolate.Primitives.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<AssemblyName>HotChocolate.Primitives.Tests</AssemblyName>
5-
<RootNamespace>HotChocolate.Primitives</RootNamespace>
5+
<RootNamespace>HotChocolate</RootNamespace>
66
</PropertyGroup>
77

88
<ItemGroup>

0 commit comments

Comments
 (0)