11using System ;
22using System . Collections . Generic ;
33using System . Linq ;
4+ using System . Reflection ;
45using GraphQL . Builders ;
56using GraphQL . Types ;
67using Microsoft . EntityFrameworkCore ;
@@ -10,6 +11,9 @@ namespace GraphQL.EntityFramework
1011 partial class EfGraphQLService < TDbContext >
1112 where TDbContext : DbContext
1213 {
14+ static MethodInfo addQueryableConnection = typeof ( EfGraphQLService < TDbContext > )
15+ . GetMethod ( "AddQueryableConnection" , BindingFlags . Instance | BindingFlags . NonPublic ) ! ;
16+
1317 public void AddQueryConnectionField < TReturn > (
1418 IComplexGraphType graph ,
1519 string name ,
@@ -20,7 +24,9 @@ public void AddQueryConnectionField<TReturn>(
2024 string ? description = null )
2125 where TReturn : class
2226 {
23- BuildQueryConnectionField ( graph , name , resolve , arguments , pageSize , itemGraphType , description ) ;
27+ itemGraphType ??= GraphTypeFinder . FindGraphType < TReturn > ( ) ;
28+ var addConnectionT = addQueryableConnection . MakeGenericMethod ( typeof ( object ) , itemGraphType , typeof ( TReturn ) ) ;
29+ addConnectionT . Invoke ( this , new object ? [ ] { graph , name , resolve , arguments , pageSize , description } ) ;
2430 }
2531
2632 public void AddQueryConnectionField < TSource , TReturn > (
@@ -33,27 +39,22 @@ public void AddQueryConnectionField<TSource, TReturn>(
3339 string ? description = null )
3440 where TReturn : class
3541 {
36- BuildQueryConnectionField ( graph , name , resolve , arguments , pageSize , itemGraphType , description ) ;
42+ itemGraphType ??= GraphTypeFinder . FindGraphType < TReturn > ( ) ;
43+ var addConnectionT = addQueryableConnection . MakeGenericMethod ( typeof ( TSource ) , itemGraphType , typeof ( TReturn ) ) ;
44+ addConnectionT . Invoke ( this , new object ? [ ] { graph , name , resolve , arguments , pageSize , description } ) ;
3745 }
3846
39- void BuildQueryConnectionField < TSource , TReturn > (
47+ void AddQueryableConnection < TSource , TGraph , TReturn > (
4048 IComplexGraphType graph ,
4149 string name ,
4250 Func < ResolveEfFieldContext < TDbContext , TSource > , IQueryable < TReturn > > ? resolve ,
4351 IEnumerable < QueryArgument > ? arguments ,
4452 int pageSize ,
45- Type ? itemGraphType ,
4653 string ? description )
54+ where TGraph : IGraphType
4755 where TReturn : class
4856 {
49- Guard . AgainstWhiteSpace ( nameof ( name ) , name ) ;
50- Guard . AgainstNegative ( nameof ( pageSize ) , pageSize ) ;
51-
52- itemGraphType ??= GraphTypeFinder . FindGraphType < TReturn > ( ) ;
53- var fieldType = GetFieldType < TSource > ( name , itemGraphType ) ;
54-
55- var builder = ConnectionBuilder < TSource > . Create < FakeGraph > ( name ) ;
56- SetField ( builder , fieldType ) ;
57+ var builder = ConnectionBuilder < TSource > . Create < TGraph > ( name ) ;
5758 if ( description != null )
5859 {
5960 builder . Description ( description ) ;
0 commit comments