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 { // protected readonly XDataServiceConfiguration configuration; protected readonly IXBaseRepository repository; protected 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 ), resolve: async context => await repository .GetAsync( includeBuilder: null, id: context.GetIdArgument(), ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument() ) .ToDynamicObject() ); // // GetAll ... FieldAsync>( name: helper.GetInQueryCollectionName(), arguments: new QueryArguments( XGraphQLHelper.IgnoreSoftDeletedArgument ), resolve: async context => await repository .GetAllAsync( orderBuilder: null, includeBuilder: null, ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument() ) .ToDynamicObject() ); // // FindOne ... FieldAsync( name: helper.GetFindOneName(), arguments: new QueryArguments( XGraphQLHelper.SearchQueryArgument, XGraphQLHelper.IgnoreSoftDeletedArgument ), resolve: async (context) => { // var searchQuery = context.GetSearchQueryArgument(); Expression> whereClase = pe => pe .PropValuesContains(searchQuery); // return await repository .FindOneAsync( includeBuilder: null, predicate: whereClase, ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument() ) .ToDynamicObject(); } ); // // FindMany ... FieldAsync>( name: helper.GetFindManyName(), arguments: new QueryArguments( XGraphQLHelper.SearchQueryArgument, XGraphQLHelper.IgnoreSoftDeletedArgument ), resolve: async (context) => { // var searchQuery = context.GetSearchQueryArgument(); Expression> whereClase = pe => pe .PropValuesContains(searchQuery); // return await repository .FindManyAsync( orderBuilder: null, includeBuilder: null, predicate: whereClase, ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument() ) .ToDynamicObject(); } ); // // Query ... FieldAsync>( name: helper.GetQueryName(), arguments: new QueryArguments( XGraphQLHelper.QueryArgument, XGraphQLHelper.IgnoreSoftDeletedArgument ), resolve: async context => await repository .QueryAsync( predicate: null, orderBuilder: null, includeBuilder: null, query: context.GetQueryArgument(), ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument() ) .ToDynamicObject() ); // // Count ... FieldAsync( name: helper.GetCountName(), arguments: new QueryArguments( XGraphQLHelper.IgnoreSoftDeletedArgument ), resolve: async context => await repository .CountAsync( ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument() ) ); // // Exists ... FieldAsync( name: helper.GetExistsName(), arguments: new QueryArguments( XGraphQLHelper.GetIdArgument(), XGraphQLHelper.IgnoreSoftDeletedArgument ), resolve: async context => await repository.IsExistsAsync( id: context.GetIdArgument(), ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument() ) ); #endregion } } }