From 5946a761814846d0e76a66b47c99cea41d3f1a9d Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 1 May 2025 11:02:50 +1000 Subject: [PATCH 1/2] sql preview --- src/Directory.Packages.props | 2 +- src/GraphQL.EntityFramework/EfGraphQLConventions.cs | 11 ++++------- .../GraphApi/EfGraphQLService.cs | 5 +---- .../GraphApi/EfGraphQLService_First.cs | 10 +--------- .../EfGraphQLService_NavigationConnection.cs | 2 -- .../GraphApi/EfGraphQLService_Queryable.cs | 12 ++---------- .../GraphApi/EfGraphQLService_QueryableConnection.cs | 3 --- .../GraphApi/EfGraphQLService_Single.cs | 10 +--------- src/Tests/IntegrationTests/IntegrationTests.cs | 10 ++++------ src/Tests/IntegrationTests/QueryExecutor.cs | 6 ++---- 10 files changed, 16 insertions(+), 55 deletions(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index c435ff26..58b6b036 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -14,7 +14,7 @@ - + diff --git a/src/GraphQL.EntityFramework/EfGraphQLConventions.cs b/src/GraphQL.EntityFramework/EfGraphQLConventions.cs index 7f609607..345ab93d 100644 --- a/src/GraphQL.EntityFramework/EfGraphQLConventions.cs +++ b/src/GraphQL.EntityFramework/EfGraphQLConventions.cs @@ -18,8 +18,7 @@ public static void RegisterInContainer( ResolveDbContext? resolveDbContext = null, IModel? model = null, ResolveFilters? resolveFilters = null, - bool disableTracking = false, - bool disableAsync = false) + bool disableTracking = false) #endregion @@ -28,7 +27,7 @@ public static void RegisterInContainer( RegisterScalarsAndArgs(services); services.AddHttpContextAccessor(); services.AddTransient(); - services.AddSingleton(provider => Build(resolveDbContext, model, resolveFilters, provider, disableTracking, disableAsync)); + services.AddSingleton(provider => Build(resolveDbContext, model, resolveFilters, provider, disableTracking)); services.AddSingleton>(provider => provider.GetRequiredService>()); } @@ -37,8 +36,7 @@ static EfGraphQLService Build( IModel? model, ResolveFilters? filters, IServiceProvider provider, - bool disableTracking, - bool disableAsync) + bool disableTracking) where TDbContext : DbContext { model ??= ResolveModel(provider); @@ -49,8 +47,7 @@ static EfGraphQLService Build( model, dbContextResolver, filters, - disableTracking, - disableAsync); + disableTracking); } static TDbContext DbContextFromProvider(IServiceProvider provider, IServiceProvider? requestServices) diff --git a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService.cs b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService.cs index 60e8bae4..1b3dc161 100644 --- a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService.cs +++ b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService.cs @@ -6,7 +6,6 @@ public partial class EfGraphQLService : { ResolveFilters? resolveFilters; bool disableTracking; - bool disableAsync; ResolveDbContext resolveDbContext; IReadOnlyDictionary> keyNames; @@ -15,12 +14,10 @@ public EfGraphQLService( IModel model, ResolveDbContext resolveDbContext, ResolveFilters? resolveFilters = null, - bool disableTracking = false, - bool disableAsync = false) + bool disableTracking = false) { this.resolveFilters = resolveFilters; this.disableTracking = disableTracking; - this.disableAsync = disableAsync; this.resolveDbContext = resolveDbContext; keyNames = model.GetKeyNames(); diff --git a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_First.cs b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_First.cs index 40f580ed..0b2ccf66 100644 --- a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_First.cs +++ b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_First.cs @@ -159,14 +159,7 @@ FieldType BuildFirstField( TReturn? first; try { - if (disableAsync) - { - first = query.FirstOrDefault(); - } - else - { - first = await query.FirstOrDefaultAsync(context.CancellationToken); - } + first = await query.FirstOrDefaultAsync(context.CancellationToken); } catch (TaskCanceledException) { @@ -184,7 +177,6 @@ FieldType BuildFirstField( GraphType: {graphType.FullName} TSource: {typeof(TSource).FullName} TReturn: {typeof(TReturn).FullName} - DisableAsync: {disableAsync} OmitQueryArguments: {omitQueryArguments} Nullable: {nullable} KeyNames: {JoinKeys(names)} diff --git a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_NavigationConnection.cs b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_NavigationConnection.cs index 135ef051..54d552ad 100644 --- a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_NavigationConnection.cs +++ b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_NavigationConnection.cs @@ -41,7 +41,6 @@ public ConnectionBuilder AddNavigationConnectionField ItemGraphType: {itemGraphType.FullName} TSource: {typeof(TSource).FullName} TReturn: {typeof(TReturn).FullName} - DisableAsync: {disableAsync} """, exception); } @@ -88,7 +87,6 @@ ConnectionBuilder AddEnumerableConnection( TGraph: {typeof(TGraph).FullName} TSource: {typeof(TSource).FullName} TReturn: {typeof(TReturn).FullName} - DisableAsync: {disableAsync} """, exception); } diff --git a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Queryable.cs b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Queryable.cs index b67ded24..75a60f19 100644 --- a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Queryable.cs +++ b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Queryable.cs @@ -109,15 +109,8 @@ FieldType BuildQueryField( try { - if (disableAsync) - { - list = query.ToList(); - } - else - { - list = await query - .ToListAsync(context.CancellationToken); - } + list = await query + .ToListAsync(context.CancellationToken); } catch (TaskCanceledException) { @@ -137,7 +130,6 @@ FieldType BuildQueryField( TReturn: {typeof(TReturn).FullName} DisableTracking: {disableTracking} HasId: {hasId} - DisableAsync: {disableAsync} KeyNames: {JoinKeys(names)} Query: {query.ToQueryString()} """, diff --git a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_QueryableConnection.cs b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_QueryableConnection.cs index c4ba3e4a..973b139e 100644 --- a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_QueryableConnection.cs +++ b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_QueryableConnection.cs @@ -56,7 +56,6 @@ public ConnectionBuilder AddQueryConnectionField( Failed to execute query for field `{name}` ItemGraphType: {itemGraphType.FullName} TReturn: {typeof(TReturn).FullName} - DisableAsync: {disableAsync} """, exception); } @@ -114,7 +113,6 @@ public ConnectionBuilder AddQueryConnectionField( ItemGraphType: {itemGraphType.FullName} TSource: {typeof(TSource).FullName} TReturn: {typeof(TReturn).FullName} - DisableAsync: {disableAsync} """, exception); } @@ -175,7 +173,6 @@ ConnectionBuilder AddQueryableConnection( TGraph: {typeof(TGraph).FullName} TSource: {typeof(TSource).FullName} TReturn: {typeof(TReturn).FullName} - DisableAsync: {disableAsync} KeyNames: {JoinKeys(names)} Query: {query.ToQueryString()} """, diff --git a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Single.cs b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Single.cs index 50b894d6..4d3b1c9d 100644 --- a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Single.cs +++ b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Single.cs @@ -160,14 +160,7 @@ FieldType BuildSingleField( TReturn? single; try { - if (disableAsync) - { - single = query.SingleOrDefault(); - } - else - { - single = await query.SingleOrDefaultAsync(context.CancellationToken); - } + single = await query.SingleOrDefaultAsync(context.CancellationToken); } catch (TaskCanceledException) { @@ -185,7 +178,6 @@ FieldType BuildSingleField( GraphType: {graphType.FullName} TSource: {typeof(TSource).FullName} TReturn: {typeof(TReturn).FullName} - DisableAsync: {disableAsync} OmitQueryArguments: {omitQueryArguments} Nullable: {nullable} KeyNames: {JoinKeys(names)} diff --git a/src/Tests/IntegrationTests/IntegrationTests.cs b/src/Tests/IntegrationTests/IntegrationTests.cs index 0c714451..809c4a9a 100644 --- a/src/Tests/IntegrationTests/IntegrationTests.cs +++ b/src/Tests/IntegrationTests/IntegrationTests.cs @@ -692,7 +692,6 @@ public async Task Connection_page_back() await using var database = await sqlInstance.Build(); await RunQuery(database, query, null, null, false, entities.ToArray()); - } [Fact] @@ -1129,7 +1128,7 @@ public async Task Single_Found_Large_Text_NoAsync() }; await using var database = await sqlInstance.Build(); - await RunQuery(database, query, null, null, false, [entity1, entity2], true); + await RunQuery(database, query, null, null, false, [entity1, entity2]); } [Fact] @@ -1156,7 +1155,7 @@ public async Task First_Found_Large_Text_NoAsync() }; await using var database = await sqlInstance.Build(); - await RunQuery(database, query, null, null, false, [entity1, entity2], true); + await RunQuery(database, query, null, null, false, [entity1, entity2]); } [Fact] @@ -2406,7 +2405,7 @@ public async Task Query_Large_Text_NoAsync() entity4.Children.Add(entity5); await using var database = await sqlInstance.Build(); - await RunQuery(database, query, null, null, false, [entity1, entity2, entity3, entity4, entity5], true); + await RunQuery(database, query, null, null, false, [entity1, entity2, entity3, entity4, entity5]); } [Fact] @@ -3078,7 +3077,6 @@ static async Task RunQuery( Filters? filters, bool disableTracking, object[] entities, - bool disableAsync = false, [CallerFilePath] string sourceFile = "") { var dbContext = database.Context; @@ -3099,7 +3097,7 @@ static async Task RunQuery( string result; try { - result = await QueryExecutor.ExecuteQuery(query, services, context, inputs, filters, disableTracking, disableAsync); + result = await QueryExecutor.ExecuteQuery(query, services, context, inputs, filters, disableTracking); } catch (ExecutionError executionError) { diff --git a/src/Tests/IntegrationTests/QueryExecutor.cs b/src/Tests/IntegrationTests/QueryExecutor.cs index b79244ca..5ee7227b 100644 --- a/src/Tests/IntegrationTests/QueryExecutor.cs +++ b/src/Tests/IntegrationTests/QueryExecutor.cs @@ -6,8 +6,7 @@ public static async Task ExecuteQuery( TDbContext data, Inputs? inputs, Filters? filters, - bool disableTracking, - bool disableAsync) + bool disableTracking) where TDbContext : DbContext { EfGraphQLConventions.RegisterInContainer( @@ -15,8 +14,7 @@ public static async Task ExecuteQuery( (_, _) => data, data.Model, _ => filters, - disableTracking, - disableAsync); + disableTracking); await using var provider = services.BuildServiceProvider(); using var schema = new Schema(provider); var executer = new EfDocumentExecuter(); From 17d455b67f24ce5924c05019dc8de0bc10f4a7cb Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 1 May 2025 01:04:05 +0000 Subject: [PATCH 2/2] Docs changes --- docs/configuration.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index e6f15340..98225a33 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -22,10 +22,9 @@ public static void RegisterInContainer( ResolveDbContext? resolveDbContext = null, IModel? model = null, ResolveFilters? resolveFilters = null, - bool disableTracking = false, - bool disableAsync = false) + bool disableTracking = false) ``` -snippet source | anchor +snippet source | anchor ```cs EfGraphQLConventions.RegisterInContainer( @@ -123,10 +122,9 @@ public static void RegisterInContainer( ResolveDbContext? resolveDbContext = null, IModel? model = null, ResolveFilters? resolveFilters = null, - bool disableTracking = false, - bool disableAsync = false) + bool disableTracking = false) ``` -snippet source | anchor +snippet source | anchor ```cs EfGraphQLConventions.RegisterInContainer(