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

Added support for IQueryable Projections #1446

Merged
merged 41 commits into from
Mar 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4776a59
Added resolver metadata
michaelstaib Feb 4, 2020
924c991
feat(Selection): add project
PascalSenn Feb 4, 2020
bf6c250
Merge branch 'feature_entity_framework' of https://github.com/ChilliC…
PascalSenn Feb 4, 2020
f659a00
feat(Selection): add selection middleware
PascalSenn Feb 4, 2020
1364c30
feat(Selection): add selection attribute
PascalSenn Feb 4, 2020
bd0880b
feat(Resolver): add resolver meta data and parent attribute
PascalSenn Feb 6, 2020
9e1cab0
fix format
PascalSenn Feb 6, 2020
841c12a
feat(Resolver): injecting parent depends on all proeprties
PascalSenn Feb 6, 2020
7814985
feat(Resolver): add context annotator and fix format
PascalSenn Feb 10, 2020
8dacbd4
feat(Resolver): resolver metadata to object field
PascalSenn Feb 10, 2020
e5aeebd
test(Resolver): add tests for resolver meta data
PascalSenn Feb 10, 2020
ef8e779
Merge remote-tracking branch 'origin/version_10_0_0_master' into feat…
michaelstaib Feb 13, 2020
8345948
updated sdk
michaelstaib Feb 13, 2020
4828601
feat(Selection): add selection visitor
PascalSenn Feb 17, 2020
c681897
Merge branch 'feature_entity_framework' of https://github.com/ChilliC…
PascalSenn Feb 17, 2020
2bcd944
feat(Selection): remove Parent(field) finish visitor
PascalSenn Feb 23, 2020
721423a
fix format
PascalSenn Feb 23, 2020
16defc6
Merge branch 'version_10_0_0_master' into feature_entity_framework
michaelstaib Feb 23, 2020
1b780be
feat(Selection): add paging to use selection
PascalSenn Feb 24, 2020
1e627e4
Merge branch 'version_10_0_0_master' into feature_entity_framework
michaelstaib Feb 24, 2020
fb11b69
feat(Selection): add support for nested filter and sort
PascalSenn Feb 25, 2020
3dd56ce
Merge branch 'feature_entity_framework' of https://github.com/ChilliC…
PascalSenn Feb 25, 2020
c3aebd5
feat(Selection): add support for paging & cleanup
PascalSenn Feb 27, 2020
46fa951
cleanup
PascalSenn Feb 27, 2020
ecc0d6c
Merge branch 'version_10_0_0_master' into feature_entity_framework
michaelstaib Feb 28, 2020
704f2ca
test(Selection): add integration tests
PascalSenn Mar 5, 2020
3f8ada7
Merge branch 'feature_entity_framework' of https://github.com/ChilliC…
PascalSenn Mar 5, 2020
2ec13e7
fix format
PascalSenn Mar 5, 2020
6fff609
formatting
michaelstaib Mar 6, 2020
5922da7
using order
michaelstaib Mar 6, 2020
66d1e0a
formatting
michaelstaib Mar 6, 2020
4ee071e
namespaces should be plural
michaelstaib Mar 6, 2020
0ae3111
Added selection to build configuration
michaelstaib Mar 6, 2020
1acc785
feat(Types): remove resolver metadata
PascalSenn Mar 6, 2020
4de986c
Merge branch 'feature_entity_framework' of https://github.com/ChilliC…
PascalSenn Mar 6, 2020
8fbd1b1
feat(Sorting): fix sort
PascalSenn Mar 7, 2020
67cfb4c
feat(Sorting): remove old extension methods
PascalSenn Mar 7, 2020
a495c7b
Merge branch 'version_10_0_0_master' into feature_entity_framework
PascalSenn Mar 7, 2020
4c0767b
test(Selection): fix test cases
PascalSenn Mar 7, 2020
4e07cc7
fixed test project files and updated squadron
michaelstaib Mar 7, 2020
c537201
disabled sql server tests
michaelstaib Mar 7, 2020
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
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "3.0.100"
"version": "3.1.101"
}
}
2 changes: 1 addition & 1 deletion src/Core/Abstractions/ParentAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace HotChocolate
{
Expand Down
70 changes: 70 additions & 0 deletions src/Core/Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Types.Sorting.Tests", "Type
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Types.Sorting.Mongo.Tests", "Types.Sorting.Mongo.Tests\Types.Sorting.Mongo.Tests.csproj", "{E8843255-77EB-471F-B682-528BB4B5D1D5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Types.Selection", "Types.Selection\Types.Selection.csproj", "{0FD6B6D1-00AB-42CF-800F-4039A976A75A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Types.Selection.Abstractions.Tests", "Types.Selection.Abstractions.Tests\Types.Selection.Abstractions.Tests.csproj", "{726D5295-3F4E-4A1A-8F3B-0EA8EC456B48}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Types.Selection.InMemory.Tests", "Types.Selection.InMemory.Tests\Types.Selection.InMemory.Tests.csproj", "{3DB2E3F5-0DBE-4B91-A335-D82F8794324B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Types.Selection.Mongo.Tests", "Types.Selection.Mongo.Tests\Types.Selection.Mongo.Tests.csproj", "{21AA751A-4C29-414C-B476-EE9204A48DDD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Types.Selection.SqlServer.Tests", "Types.Selection.SqlServer.Tests\Types.Selection.SqlServer.Tests.csproj", "{07674D84-4A5C-4608-BECE-03630D38275F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -449,6 +459,66 @@ Global
{E8843255-77EB-471F-B682-528BB4B5D1D5}.Release|x64.Build.0 = Release|Any CPU
{E8843255-77EB-471F-B682-528BB4B5D1D5}.Release|x86.ActiveCfg = Release|Any CPU
{E8843255-77EB-471F-B682-528BB4B5D1D5}.Release|x86.Build.0 = Release|Any CPU
{0FD6B6D1-00AB-42CF-800F-4039A976A75A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0FD6B6D1-00AB-42CF-800F-4039A976A75A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FD6B6D1-00AB-42CF-800F-4039A976A75A}.Debug|x64.ActiveCfg = Debug|Any CPU
{0FD6B6D1-00AB-42CF-800F-4039A976A75A}.Debug|x64.Build.0 = Debug|Any CPU
{0FD6B6D1-00AB-42CF-800F-4039A976A75A}.Debug|x86.ActiveCfg = Debug|Any CPU
{0FD6B6D1-00AB-42CF-800F-4039A976A75A}.Debug|x86.Build.0 = Debug|Any CPU
{0FD6B6D1-00AB-42CF-800F-4039A976A75A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FD6B6D1-00AB-42CF-800F-4039A976A75A}.Release|Any CPU.Build.0 = Release|Any CPU
{0FD6B6D1-00AB-42CF-800F-4039A976A75A}.Release|x64.ActiveCfg = Release|Any CPU
{0FD6B6D1-00AB-42CF-800F-4039A976A75A}.Release|x64.Build.0 = Release|Any CPU
{0FD6B6D1-00AB-42CF-800F-4039A976A75A}.Release|x86.ActiveCfg = Release|Any CPU
{0FD6B6D1-00AB-42CF-800F-4039A976A75A}.Release|x86.Build.0 = Release|Any CPU
{726D5295-3F4E-4A1A-8F3B-0EA8EC456B48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{726D5295-3F4E-4A1A-8F3B-0EA8EC456B48}.Debug|Any CPU.Build.0 = Debug|Any CPU
{726D5295-3F4E-4A1A-8F3B-0EA8EC456B48}.Debug|x64.ActiveCfg = Debug|Any CPU
{726D5295-3F4E-4A1A-8F3B-0EA8EC456B48}.Debug|x64.Build.0 = Debug|Any CPU
{726D5295-3F4E-4A1A-8F3B-0EA8EC456B48}.Debug|x86.ActiveCfg = Debug|Any CPU
{726D5295-3F4E-4A1A-8F3B-0EA8EC456B48}.Debug|x86.Build.0 = Debug|Any CPU
{726D5295-3F4E-4A1A-8F3B-0EA8EC456B48}.Release|Any CPU.ActiveCfg = Release|Any CPU
{726D5295-3F4E-4A1A-8F3B-0EA8EC456B48}.Release|Any CPU.Build.0 = Release|Any CPU
{726D5295-3F4E-4A1A-8F3B-0EA8EC456B48}.Release|x64.ActiveCfg = Release|Any CPU
{726D5295-3F4E-4A1A-8F3B-0EA8EC456B48}.Release|x64.Build.0 = Release|Any CPU
{726D5295-3F4E-4A1A-8F3B-0EA8EC456B48}.Release|x86.ActiveCfg = Release|Any CPU
{726D5295-3F4E-4A1A-8F3B-0EA8EC456B48}.Release|x86.Build.0 = Release|Any CPU
{3DB2E3F5-0DBE-4B91-A335-D82F8794324B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3DB2E3F5-0DBE-4B91-A335-D82F8794324B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3DB2E3F5-0DBE-4B91-A335-D82F8794324B}.Debug|x64.ActiveCfg = Debug|Any CPU
{3DB2E3F5-0DBE-4B91-A335-D82F8794324B}.Debug|x64.Build.0 = Debug|Any CPU
{3DB2E3F5-0DBE-4B91-A335-D82F8794324B}.Debug|x86.ActiveCfg = Debug|Any CPU
{3DB2E3F5-0DBE-4B91-A335-D82F8794324B}.Debug|x86.Build.0 = Debug|Any CPU
{3DB2E3F5-0DBE-4B91-A335-D82F8794324B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3DB2E3F5-0DBE-4B91-A335-D82F8794324B}.Release|Any CPU.Build.0 = Release|Any CPU
{3DB2E3F5-0DBE-4B91-A335-D82F8794324B}.Release|x64.ActiveCfg = Release|Any CPU
{3DB2E3F5-0DBE-4B91-A335-D82F8794324B}.Release|x64.Build.0 = Release|Any CPU
{3DB2E3F5-0DBE-4B91-A335-D82F8794324B}.Release|x86.ActiveCfg = Release|Any CPU
{3DB2E3F5-0DBE-4B91-A335-D82F8794324B}.Release|x86.Build.0 = Release|Any CPU
{21AA751A-4C29-414C-B476-EE9204A48DDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{21AA751A-4C29-414C-B476-EE9204A48DDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{21AA751A-4C29-414C-B476-EE9204A48DDD}.Debug|x64.ActiveCfg = Debug|Any CPU
{21AA751A-4C29-414C-B476-EE9204A48DDD}.Debug|x64.Build.0 = Debug|Any CPU
{21AA751A-4C29-414C-B476-EE9204A48DDD}.Debug|x86.ActiveCfg = Debug|Any CPU
{21AA751A-4C29-414C-B476-EE9204A48DDD}.Debug|x86.Build.0 = Debug|Any CPU
{21AA751A-4C29-414C-B476-EE9204A48DDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{21AA751A-4C29-414C-B476-EE9204A48DDD}.Release|Any CPU.Build.0 = Release|Any CPU
{21AA751A-4C29-414C-B476-EE9204A48DDD}.Release|x64.ActiveCfg = Release|Any CPU
{21AA751A-4C29-414C-B476-EE9204A48DDD}.Release|x64.Build.0 = Release|Any CPU
{21AA751A-4C29-414C-B476-EE9204A48DDD}.Release|x86.ActiveCfg = Release|Any CPU
{21AA751A-4C29-414C-B476-EE9204A48DDD}.Release|x86.Build.0 = Release|Any CPU
{07674D84-4A5C-4608-BECE-03630D38275F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07674D84-4A5C-4608-BECE-03630D38275F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07674D84-4A5C-4608-BECE-03630D38275F}.Debug|x64.ActiveCfg = Debug|Any CPU
{07674D84-4A5C-4608-BECE-03630D38275F}.Debug|x64.Build.0 = Debug|Any CPU
{07674D84-4A5C-4608-BECE-03630D38275F}.Debug|x86.ActiveCfg = Debug|Any CPU
{07674D84-4A5C-4608-BECE-03630D38275F}.Debug|x86.Build.0 = Debug|Any CPU
{07674D84-4A5C-4608-BECE-03630D38275F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07674D84-4A5C-4608-BECE-03630D38275F}.Release|Any CPU.Build.0 = Release|Any CPU
{07674D84-4A5C-4608-BECE-03630D38275F}.Release|x64.ActiveCfg = Release|Any CPU
{07674D84-4A5C-4608-BECE-03630D38275F}.Release|x64.Build.0 = Release|Any CPU
{07674D84-4A5C-4608-BECE-03630D38275F}.Release|x86.ActiveCfg = Release|Any CPU
{07674D84-4A5C-4608-BECE-03630D38275F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 3 additions & 0 deletions src/Core/Core/InternalsVisibleTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("HotChocolate.Types.Selections")]
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Squadron.Redis" Version="0.3.0" />
<PackageReference Include="Squadron.Redis" Version="0.5.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Squadron.Redis" Version="0.3.0" />
<PackageReference Include="Squadron.Redis" Version="0.5.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Squadron.Mongo" Version="0.3.0" />
<PackageReference Include="Squadron.Mongo" Version="0.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Types.Filters/QueryableFilterMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -26,7 +26,7 @@ public async Task InvokeAsync(IMiddlewareContext context)
{
await _next(context).ConfigureAwait(false);

var filter = context.Argument<IValueNode>("where");
IValueNode filter = context.Argument<IValueNode>("where");

if (filter is null || filter is NullValueNode)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Core/Types.Filters/QueryableFilterVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public Expression<Func<TSource, bool>> CreateFilter<TSource>()
_parameter);
}

public Expression CreateFilter()
{
return Expression.Lambda(Level.Peek().Peek(), _parameter);
}

protected Stack<Queue<Expression>> Level { get; } =
new Stack<Queue<Expression>>();

Expand Down
14 changes: 14 additions & 0 deletions src/Core/Types.Selection.Abstractions.Tests/IResolverProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using HotChocolate.Resolvers;
using Microsoft.Extensions.DependencyInjection;

namespace HotChocolate.Types.Selections
{
public interface IResolverProvider
{
public (IServiceCollection, Func<IResolverContext, IEnumerable<TResult>>)
CreateResolver<TResult>(params TResult[] results)
where TResult : class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using HotChocolate.Execution;
using HotChocolate.Resolvers;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

namespace HotChocolate.Types.Selections
{
public abstract class SelectionAttributeTestsBase
{

private readonly IResolverProvider _provider;
private readonly bool _setId;

protected SelectionAttributeTestsBase(IResolverProvider provider, bool setId = false)
{
_provider = provider;
_setId = setId;
}

[Fact]
public void Execute_Selection_MultipleScalar()
{
// arrange
IServiceCollection services;
Func<IResolverContext, IEnumerable<Foo>> resolver;
(services, resolver) = _provider.CreateResolver(
Foo.Create("aa", 1, _setId),
Foo.Create("bb", 2, _setId));

IQueryable<Foo> resultCtx = null;
ISchema schema = SchemaBuilder.New()
.AddServices(services.BuildServiceProvider())
.AddQueryType<Query>(d =>
d.Field(t => t.Foos)
.Resolver(resolver)
.Use(next => async ctx =>
{
await next(ctx).ConfigureAwait(false);
resultCtx = ctx.Result as IQueryable<Foo>;
}))
.Create();
IQueryExecutor executor = schema.MakeExecutable();

// act
executor.Execute(
"{ foos { bar baz } }");

// assert
Assert.NotNull(resultCtx);
Assert.Collection(resultCtx.ToArray(),
x =>
{
Assert.Equal("aa", x.Bar);
Assert.Equal(1, x.Baz);
Assert.Null(x.Nested);
Assert.Null(x.NestedCollection);
},
x =>
{
Assert.Equal("bb", x.Bar);
Assert.Equal(2, x.Baz);
Assert.Null(x.Nested);
Assert.Null(x.NestedCollection);
});
}

public class Query
{
[UseSelection]
public IQueryable<Foo> Foos { get; }
}

public class Foo
{
private static int idCounter = 1;

[Key]
public int Id { get; set; }

public string Bar { get; set; }

public int Baz { get; set; }

public NestedFoo Nested { get; set; }

public List<NestedFoo> NestedCollection { get; set; }

public static Foo Create(string bar, int baz, bool setId)
{
var value = new Foo
{
Bar = bar,
Baz = baz,
Nested = new NestedFoo()
{
Bar = "nested" + bar,
Baz = baz * 2
},
NestedCollection = new List<NestedFoo>()
{
new NestedFoo()
{
Bar = "nestedcollection" + bar,
Baz = baz * 3
},
}
};
if (setId)
{
value.Id = ++idCounter;
}
return value;
}
}

public class NestedFoo
{
[Key]
public int Id { get; set; }

public string Bar { get; set; }

public int Baz { get; set; }
}
}
}
Loading