using System; using System.Linq.Expressions; using GraphQL.Types; using xCommons.Extensions; using xDataService.Configuration; using xDataService.Constants; using xDataService.Extensions; using xDataService.Interfaces; using xDataService.Models; using xModels.Base; namespace xDataService.GraphQL { public abstract class XBaseGraphQLQuery : ObjectGraphType, IXBaseGraphQLQuery where TEntity : XBaseEntity where TGraph : IGraphType where TGraphKey : IGraphType { // private readonly XDataServiceConfiguration configuration; private readonly IXBaseRepository repository; private readonly IXBaseGraphQLTypeHelper helper; // public XBaseGraphQLQuery ( XDataServiceConfiguration configuration, IXBaseRepository repository, IXBaseGraphQLTypeHelper helper ) { // this.helper = helper; this.repository = repository; this.configuration = configuration; // Name = GetType ().Name; // #region Retrieve ... // // Get ... FieldAsync ( name: helper.GetInQuerySingleName (), arguments: new QueryArguments ( XGraphQLHelper.GetIdArgument (), XGraphQLHelper.IgnoreSoftDeletedArgument, XGraphQLHelper.ContainsDetailArgument ), resolve : async context => await repository .GetAsync ( id: context.GetIdArgument (), ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument (), containsDetail: context.GetContainsDetailArgument () ) .ToDynamicObject () ); // // GetAll ... FieldAsync> ( name: helper.GetInQueryCollectionName (), arguments: new QueryArguments ( XGraphQLHelper.IgnoreSoftDeletedArgument, XGraphQLHelper.ContainsDetailArgument ), resolve : async context => await repository .GetAllAsync ( ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument (), containsDetail: context.GetContainsDetailArgument () ) .ToDynamicObject () ); // // FindOne ... FieldAsync ( name: helper.GetFindOneName (), arguments: new QueryArguments ( XGraphQLHelper.SearchQueryArgument, XGraphQLHelper.IgnoreSoftDeletedArgument, XGraphQLHelper.ContainsDetailArgument ), resolve : async (context) => { // var searchQuery = context.GetSearchQueryArgument (); Expression> whereClase = pe => pe .PropValuesContains (searchQuery); // return await repository .FindOneAsync ( whereClause: whereClase, ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument (), containsDetail: context.GetContainsDetailArgument () ) .ToDynamicObject (); } ); // // FindMany ... FieldAsync> ( name: helper.GetFindManyName (), arguments: new QueryArguments ( XGraphQLHelper.SearchQueryArgument, XGraphQLHelper.IgnoreSoftDeletedArgument, XGraphQLHelper.ContainsDetailArgument ), resolve : async (context) => { // var searchQuery = context.GetSearchQueryArgument (); Expression> whereClase = pe => pe .PropValuesContains (searchQuery); // return await repository .FindManyAsync ( whereClause: whereClase, ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument (), containsDetail: context.GetContainsDetailArgument () ) .ToDynamicObject (); } ); // // Query ... FieldAsync> ( name: helper.GetQueryName (), arguments: new QueryArguments ( XGraphQLHelper.QueryArgument, XGraphQLHelper.IgnoreSoftDeletedArgument ), resolve : async context => await repository .QueryAsync ( query: context.GetQueryArgument (), ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument () ) .ToDynamicObject () ); // // Count ... FieldAsync ( name: helper.GetCountName (), resolve: async context => await repository .CountAsync () ); // // Exists ... FieldAsync ( name: helper.GetExistsName (), arguments: new QueryArguments ( XGraphQLHelper.GetIdArgument () ), resolve : async context => await repository.IsExistsAsync ( context.GetIdArgument () ) ); #endregion } } }