diff --git a/docs/defining-graphs.md b/docs/defining-graphs.md index f03998c5..275a8863 100644 --- a/docs/defining-graphs.md +++ b/docs/defining-graphs.md @@ -152,7 +152,7 @@ public class OrderGraph : Field("customerName") .ResolveAsync(async context => { - var data = base.ResolveDbContext(context); + var data = ResolveDbContext(context); // CustomerId is available even though it wasn't in the GraphQL query var customer = await data.Customers .Where(c => c.Id == context.Source.CustomerId) diff --git a/docs/filters.md b/docs/filters.md index cc0306ec..75ce20b8 100644 --- a/docs/filters.md +++ b/docs/filters.md @@ -26,7 +26,7 @@ Notes: ```cs -public partial class Filters +public class Filters where TDbContext : DbContext { public delegate bool Filter(object userContext, TDbContext data, ClaimsPrincipal? userPrincipal, TEntity input); diff --git a/src/GraphQL.EntityFramework/Filters/Filters.cs b/src/GraphQL.EntityFramework/Filters/Filters.cs index 968afae3..0254a6c8 100644 --- a/src/GraphQL.EntityFramework/Filters/Filters.cs +++ b/src/GraphQL.EntityFramework/Filters/Filters.cs @@ -2,7 +2,7 @@ namespace GraphQL.EntityFramework; #region FiltersSignature -public partial class Filters +public class Filters where TDbContext : DbContext { public delegate bool Filter(object userContext, TDbContext data, ClaimsPrincipal? userPrincipal, TEntity input); diff --git a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Navigation.cs b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Navigation.cs index df208a02..8d87c15d 100644 --- a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Navigation.cs +++ b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Navigation.cs @@ -3,64 +3,6 @@ partial class EfGraphQLService where TDbContext : DbContext { - [Obsolete("Use the projection-based overload instead")] - public FieldBuilder AddNavigationField( - ComplexGraphType graph, - string name, - Func, TReturn?>? resolve = null, - Type? graphType = null, - IEnumerable? includeNames = null) - where TReturn : class - { - Ensure.NotWhiteSpace(nameof(name), name); - - graphType ??= GraphTypeFinder.FindGraphType(); - - var field = new FieldType - { - Name = name, - Type = graphType - }; - IncludeAppender.SetIncludeMetadata(field, name, includeNames); - - if (resolve is not null) - { - field.Resolver = new FuncFieldResolver( - async context => - { - var fieldContext = BuildContext(context); - - TReturn? result; - try - { - result = resolve(fieldContext); - } - catch (Exception exception) - { - throw new( - $""" - Failed to execute navigation resolve for field `{name}` - GraphType: {graphType.FullName} - TSource: {typeof(TSource).FullName} - TReturn: {typeof(TReturn).FullName} - """, - exception); - } - - if (fieldContext.Filters == null || - await fieldContext.Filters.ShouldInclude(context.UserContext, fieldContext.DbContext, context.User, result)) - { - return result; - } - - return null; - }); - } - - graph.AddField(field); - return new FieldBuilderEx(field); - } - public FieldBuilder AddNavigationField( ComplexGraphType graph, string name, diff --git a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_NavigationConnection.cs b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_NavigationConnection.cs index ea14e1db..93f5de40 100644 --- a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_NavigationConnection.cs +++ b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_NavigationConnection.cs @@ -3,56 +3,12 @@ partial class EfGraphQLService where TDbContext : DbContext { - static MethodInfo addEnumerableConnection = typeof(EfGraphQLService) - .GetMethod("AddEnumerableConnection", BindingFlags.Instance | BindingFlags.NonPublic)!; - static MethodInfo addEnumerableConnectionWithProjection = typeof(EfGraphQLService) .GetMethod("AddEnumerableConnectionWithProjection", BindingFlags.Instance | BindingFlags.NonPublic)!; static MethodInfo addEnumerableConnectionWithProjectionOnly = typeof(EfGraphQLService) .GetMethod("AddEnumerableConnectionWithProjectionOnly", BindingFlags.Instance | BindingFlags.NonPublic)!; - [Obsolete("Use the projection-based overload instead")] - public ConnectionBuilder AddNavigationConnectionField( - ComplexGraphType graph, - string name, - Func, IEnumerable>? resolve = null, - Type? itemGraphType = null, - IEnumerable? includeNames = null, - bool omitQueryArguments = false) - where TReturn : class - { - Ensure.NotWhiteSpace(nameof(name), name); - - itemGraphType ??= GraphTypeFinder.FindGraphType(); - - var addConnectionT = addEnumerableConnection.MakeGenericMethod(typeof(TSource), itemGraphType, typeof(TReturn)); - - try - { - var arguments = new object?[] - { - graph, - name, - resolve, - includeNames, - omitQueryArguments - }; - return (ConnectionBuilder) addConnectionT.Invoke(this, arguments)!; - } - catch (Exception exception) - { - throw new( - $""" - Failed to execute navigation connection for field `{name}` - ItemGraphType: {itemGraphType.FullName} - TSource: {typeof(TSource).FullName} - TReturn: {typeof(TReturn).FullName} - """, - exception); - } - } - public ConnectionBuilder AddNavigationConnectionField( ComplexGraphType graph, string name, diff --git a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_NavigationList.cs b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_NavigationList.cs index 7ced73e7..b56f7477 100644 --- a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_NavigationList.cs +++ b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_NavigationList.cs @@ -3,53 +3,6 @@ partial class EfGraphQLService where TDbContext : DbContext { - [Obsolete("Use the projection-based overload instead")] - public FieldBuilder AddNavigationListField( - ComplexGraphType graph, - string name, - Func, IEnumerable>? resolve = null, - Type? itemGraphType = null, - IEnumerable? includeNames = null, - bool omitQueryArguments = false) - where TReturn : class - { - Ensure.NotWhiteSpace(nameof(name), name); - - var hasId = keyNames.ContainsKey(typeof(TReturn)); - var field = new FieldType - { - Name = name, - Type = MakeListGraphType(itemGraphType), - Arguments = ArgumentAppender.GetQueryArguments(hasId, true, false), - }; - IncludeAppender.SetIncludeMetadata(field, name, includeNames); - - if (resolve is not null) - { - field.Resolver = new FuncFieldResolver>(async context => - { - var fieldContext = BuildContext(context); - var result = resolve(fieldContext); - - if (result is IQueryable) - { - throw new("This API expects the resolver to return a IEnumerable, not an IQueryable. Instead use AddQueryField."); - } - - result = result.ApplyGraphQlArguments(hasId, context, omitQueryArguments); - if (fieldContext.Filters == null) - { - return result; - } - - return await fieldContext.Filters.ApplyFilter(result, context.UserContext, fieldContext.DbContext, context.User); - }); - } - - graph.AddField(field); - return new FieldBuilderEx(field); - } - public FieldBuilder AddNavigationListField( ComplexGraphType graph, string name, diff --git a/src/GraphQL.EntityFramework/GraphApi/EfInterfaceGraphType.cs b/src/GraphQL.EntityFramework/GraphApi/EfInterfaceGraphType.cs index 05acda7d..3651f85b 100644 --- a/src/GraphQL.EntityFramework/GraphApi/EfInterfaceGraphType.cs +++ b/src/GraphQL.EntityFramework/GraphApi/EfInterfaceGraphType.cs @@ -12,15 +12,6 @@ public EfInterfaceGraphType(IEfGraphQLService graphQlService):this(g public IEfGraphQLService GraphQlService { get; } = graphQlService; - [Obsolete("Use the projection-based overload instead")] - public ConnectionBuilder AddNavigationConnectionField( - string name, - Type? graphType = null, - IEnumerable? includeNames = null, - bool omitQueryArguments = false) - where TReturn : class => - GraphQlService.AddNavigationConnectionField(this, name, null, graphType, includeNames, omitQueryArguments); - public ConnectionBuilder AddNavigationConnectionField( string name, Expression?>> projection, @@ -28,14 +19,6 @@ public ConnectionBuilder AddNavigationConnectionField( where TReturn : class => GraphQlService.AddNavigationConnectionField(this, name, projection, graphType); - [Obsolete("Use the projection-based overload instead")] - public FieldBuilder AddNavigationField( - string name, - Type? graphType = null, - IEnumerable? includeNames = null) - where TReturn : class => - GraphQlService.AddNavigationField(this, name, null, graphType, includeNames); - public FieldBuilder AddNavigationField( string name, Expression> projection, @@ -43,15 +26,6 @@ public FieldBuilder AddNavigationField( where TReturn : class => GraphQlService.AddNavigationField(this, name, projection, graphType); - [Obsolete("Use the projection-based overload instead")] - public FieldBuilder AddNavigationListField( - string name, - Type? graphType = null, - IEnumerable? includeNames = null, - bool omitQueryArguments = false) - where TReturn : class => - GraphQlService.AddNavigationListField(this, name, null, graphType, includeNames, omitQueryArguments); - public FieldBuilder AddNavigationListField( string name, Expression?>> projection, diff --git a/src/GraphQL.EntityFramework/GraphApi/EfObjectGraphType.cs b/src/GraphQL.EntityFramework/GraphApi/EfObjectGraphType.cs index 01a98a32..5200ad23 100644 --- a/src/GraphQL.EntityFramework/GraphApi/EfObjectGraphType.cs +++ b/src/GraphQL.EntityFramework/GraphApi/EfObjectGraphType.cs @@ -17,16 +17,6 @@ public class EfObjectGraphType(IEfGraphQLService? exclusions = null) => Mapper.AutoMap(this, GraphQlService, exclusions); - [Obsolete("Use the projection-based overload instead")] - public ConnectionBuilder AddNavigationConnectionField( - string name, - Func, IEnumerable>? resolve = null, - Type? graphType = null, - IEnumerable? includeNames = null, - bool omitQueryArguments = false) - where TReturn : class => - GraphQlService.AddNavigationConnectionField(this, name, resolve, graphType, includeNames, omitQueryArguments); - public ConnectionBuilder AddNavigationConnectionField( string name, Expression> projection, @@ -43,15 +33,6 @@ public ConnectionBuilder AddNavigationConnectionField( where TReturn : class => GraphQlService.AddNavigationConnectionField(this, name, projection, graphType); - [Obsolete("Use the projection-based overload instead")] - public FieldBuilder AddNavigationField( - string name, - Func, TReturn?>? resolve = null, - Type? graphType = null, - IEnumerable? includeNames = null) - where TReturn : class => - GraphQlService.AddNavigationField(this, name, resolve, graphType, includeNames); - public FieldBuilder AddNavigationField( string name, Expression> projection, @@ -67,16 +48,6 @@ public FieldBuilder AddNavigationField( where TReturn : class => GraphQlService.AddNavigationField(this, name, projection, graphType); - [Obsolete("Use the projection-based overload instead")] - public FieldBuilder AddNavigationListField( - string name, - Func, IEnumerable>? resolve = null, - Type? graphType = null, - IEnumerable? includeNames = null, - bool omitQueryArguments = false) - where TReturn : class => - GraphQlService.AddNavigationListField(this, name, resolve, graphType, includeNames, omitQueryArguments); - public FieldBuilder AddNavigationListField( string name, Expression> projection, diff --git a/src/GraphQL.EntityFramework/GraphApi/IEfGraphQLService_Navigation.cs b/src/GraphQL.EntityFramework/GraphApi/IEfGraphQLService_Navigation.cs index 2ca1a9ed..f63d1155 100644 --- a/src/GraphQL.EntityFramework/GraphApi/IEfGraphQLService_Navigation.cs +++ b/src/GraphQL.EntityFramework/GraphApi/IEfGraphQLService_Navigation.cs @@ -3,14 +3,6 @@ //Navigation fields will always be on a typed graph. so use ComplexGraphType not IComplexGraphType public partial interface IEfGraphQLService { - [Obsolete("Use the projection-based overload instead")] - FieldBuilder AddNavigationField(ComplexGraphType graph, - string name, - Func, TReturn?>? resolve = null, - Type? graphType = null, - IEnumerable? includeNames = null) - where TReturn : class; - FieldBuilder AddNavigationField( ComplexGraphType graph, string name, @@ -26,16 +18,6 @@ FieldBuilder AddNavigationField( Type? graphType = null) where TReturn : class; - [Obsolete("Use the projection-based overload instead")] - FieldBuilder AddNavigationListField( - ComplexGraphType graph, - string name, - Func, IEnumerable>? resolve = null, - Type? itemGraphType = null, - IEnumerable? includeNames = null, - bool omitQueryArguments = false) - where TReturn : class; - FieldBuilder AddNavigationListField( ComplexGraphType graph, string name, diff --git a/src/GraphQL.EntityFramework/GraphApi/IEfGraphQLService_NavigationConnection.cs b/src/GraphQL.EntityFramework/GraphApi/IEfGraphQLService_NavigationConnection.cs index 68173439..12888378 100644 --- a/src/GraphQL.EntityFramework/GraphApi/IEfGraphQLService_NavigationConnection.cs +++ b/src/GraphQL.EntityFramework/GraphApi/IEfGraphQLService_NavigationConnection.cs @@ -3,16 +3,6 @@ //Navigation fields will always be on a typed graph. so use ComplexGraphType not IComplexGraphType public partial interface IEfGraphQLService { - [Obsolete("Use the projection-based overload instead")] - ConnectionBuilder AddNavigationConnectionField( - ComplexGraphType graph, - string name, - Func, IEnumerable>? resolve = null, - Type? itemGraphType = null, - IEnumerable? includeNames = null, - bool omitQueryArguments = false) - where TReturn : class; - ConnectionBuilder AddNavigationConnectionField( ComplexGraphType graph, string name, diff --git a/src/Snippets/ProjectionSnippets.cs b/src/Snippets/ProjectionSnippets.cs index a102bcfc..d63cea01 100644 --- a/src/Snippets/ProjectionSnippets.cs +++ b/src/Snippets/ProjectionSnippets.cs @@ -42,7 +42,7 @@ public OrderGraph(IEfGraphQLService graphQlService) : Field("customerName") .ResolveAsync(async context => { - var data = base.ResolveDbContext(context); + var data = ResolveDbContext(context); // CustomerId is available even though it wasn't in the GraphQL query var customer = await data.Customers .Where(c => c.Id == context.Source.CustomerId)