-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for IQueryable Projections (#1446)
- Loading branch information
1 parent
6dbe61e
commit 8302ae7
Showing
57 changed files
with
3,512 additions
and
885 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"sdk": { | ||
"version": "3.0.100" | ||
"version": "3.1.101" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using System; | ||
using System; | ||
|
||
namespace HotChocolate | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("HotChocolate.Types.Selections")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/Core/Types.Selection.Abstractions.Tests/IResolverProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
src/Core/Types.Selection.Abstractions.Tests/SelectionAttributeTestsBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} | ||
} |
Oops, something went wrong.