Skip to content

Commit b4c5f4b

Browse files
committed
add support for non IAsyncQueryProvider
1 parent 686251c commit b4c5f4b

11 files changed

+138
-5
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;NU5104;CS1573;CS9107;NU1608;NU1109</NoWarn>
5-
<Version>32.1.0</Version>
5+
<Version>32.2.0</Version>
66
<LangVersion>preview</LangVersion>
77
<AssemblyVersion>1.0.0</AssemblyVersion>
88
<PackageTags>EntityFrameworkCore, EntityFramework, GraphQL</PackageTags>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
global using System.Security.Claims;
22
global using Microsoft.AspNetCore.Http;
33
global using Microsoft.EntityFrameworkCore.Metadata;
4+
global using Microsoft.EntityFrameworkCore.Query;
45
global using Microsoft.Extensions.DependencyInjection;

src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_First.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,14 @@ FieldType BuildFirstField<TSource, TReturn>(
170170
TReturn? first;
171171
try
172172
{
173-
first = await query.FirstOrDefaultAsync(context.CancellationToken);
173+
if (query.Provider is IAsyncQueryProvider)
174+
{
175+
first = await query.FirstOrDefaultAsync(context.CancellationToken);
176+
}
177+
else
178+
{
179+
first = query.FirstOrDefault();
180+
}
174181
}
175182
catch (TaskCanceledException)
176183
{

src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Queryable.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,14 @@ FieldType BuildQueryField<TSource, TReturn>(
121121

122122
try
123123
{
124-
list = await query
125-
.ToListAsync(context.CancellationToken);
124+
if (query.Provider is IAsyncQueryProvider)
125+
{
126+
list = await query.ToListAsync(context.CancellationToken);
127+
}
128+
else
129+
{
130+
list = query.ToList();
131+
}
126132
}
127133
catch (TaskCanceledException)
128134
{

src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Single.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,14 @@ FieldType BuildSingleField<TSource, TReturn>(
171171
TReturn? single;
172172
try
173173
{
174-
single = await query.SingleOrDefaultAsync(context.CancellationToken);
174+
if (query.Provider is IAsyncQueryProvider)
175+
{
176+
single = await query.SingleOrDefaultAsync(context.CancellationToken);
177+
}
178+
else
179+
{
180+
single = query.SingleOrDefault();
181+
}
175182
}
176183
catch (TaskCanceledException)
177184
{
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"data": {
3+
"iQueryable": [
4+
{
5+
"property": "Foo"
6+
}
7+
]
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"data": {
3+
"iQueryableFirst": {
4+
"property": "Foo"
5+
}
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"data": {
3+
"iQueryableSingle": {
4+
"property": "Foo"
5+
}
6+
}
7+
}

src/Tests/IntegrationTests/IntegrationTests.SchemaPrint.verified.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@
9090
parentEntityViewNullableFirst(where: [WhereExpression!]): ParentEntityView
9191
ownedParent(id: ID, ids: [ID!], where: [WhereExpression!]): OwnedParent
9292
ownedParentFirst(id: ID, ids: [ID!], where: [WhereExpression!]): OwnedParent
93+
iQueryableSingle(id: ID, ids: [ID!], where: [WhereExpression!]): Parent
94+
iQueryableFirst(id: ID, ids: [ID!], where: [WhereExpression!]): Parent
95+
iQueryable(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [Parent!]!
9396
nullQueryableSingle(id: ID, ids: [ID!], where: [WhereExpression!]): Parent
9497
nullQueryableFirst(id: ID, ids: [ID!], where: [WhereExpression!]): Parent
9598
nullTaskQueryableSingle(id: ID, ids: [ID!], where: [WhereExpression!]): Parent

src/Tests/IntegrationTests/IntegrationTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,6 +3022,51 @@ static IEnumerable<Type> GetGraphQlTypes() =>
30223022
.GetTypes()
30233023
.Where(_ => !_.IsAbstract && _.IsAssignableTo<GraphType>());
30243024

3025+
[Fact]
3026+
public async Task IQueryableFirst()
3027+
{
3028+
var query =
3029+
"""
3030+
{
3031+
iQueryableFirst(id: "00000000-0000-0000-0000-000000000001") {
3032+
property
3033+
}
3034+
}
3035+
""";
3036+
await using var database = await sqlInstance.Build();
3037+
await RunQuery(database, query, null, null, false, []);
3038+
}
3039+
3040+
[Fact]
3041+
public async Task IQueryableSingle()
3042+
{
3043+
var query =
3044+
"""
3045+
{
3046+
iQueryableSingle(id: "00000000-0000-0000-0000-000000000001") {
3047+
property
3048+
}
3049+
}
3050+
""";
3051+
await using var database = await sqlInstance.Build();
3052+
await RunQuery(database, query, null, null, false, []);
3053+
}
3054+
3055+
[Fact]
3056+
public async Task IQueryable()
3057+
{
3058+
var query =
3059+
"""
3060+
{
3061+
iQueryable(id: "00000000-0000-0000-0000-000000000001") {
3062+
property
3063+
}
3064+
}
3065+
""";
3066+
await using var database = await sqlInstance.Build();
3067+
await RunQuery(database, query, null, null, false, []);
3068+
}
3069+
30253070
[Fact]
30263071
public async Task SingleNullQueryableSingle()
30273072
{

0 commit comments

Comments
 (0)