This commit is contained in:
2026-05-08 04:30:04 +03:30
parent afe5c74d09
commit 34afd95640
20 changed files with 1022 additions and 713 deletions
+100 -78
View File
@@ -9,164 +9,186 @@ using xDataService.Interfaces;
using xDataService.Models;
using xModels.Base;
namespace xDataService.GraphQL {
public abstract class XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey> : ObjectGraphType, IXBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
where TEntity : XBaseEntity<TKey>
where TGraph : IGraphType
where TGraphKey : IGraphType {
//
private readonly XDataServiceConfiguration configuration;
private readonly IXBaseRepository<TEntity, TKey> repository;
private readonly IXBaseGraphQLTypeHelper<TEntity, TKey> helper;
namespace xDataService.GraphQL
{
public abstract class XBaseGraphQLQuery : ObjectGraphType, IXBaseGraphQLQuery { }
public abstract class XBaseGraphQLQuery<TEntity, TKey> : XBaseGraphQLQuery, IXBaseGraphQLQuery<TEntity, TKey>
where TEntity : XBaseEntity<TKey>
{
//
public XBaseGraphQLQuery (
protected readonly XDataServiceConfiguration configuration;
protected readonly IXBaseRepository<TEntity, TKey> repository;
protected readonly IXBaseGraphQLTypeHelper<TEntity, TKey> helper;
public XBaseGraphQLQuery(
XDataServiceConfiguration configuration,
IXBaseRepository<TEntity, TKey> repository,
IXBaseGraphQLTypeHelper<TEntity, TKey> helper
) {
)
{
//
this.helper = helper;
this.repository = repository;
this.configuration = configuration;
//
Name = GetType ().Name;
Name = GetType().Name;
}
}
public abstract class XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey> : XBaseGraphQLQuery<TEntity, TKey>, IXBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
where TEntity : XBaseEntity<TKey>
where TGraph : IGraphType
where TGraphKey : IGraphType
{
//
public XBaseGraphQLQuery(
XDataServiceConfiguration configuration,
IXBaseRepository<TEntity, TKey> repository,
IXBaseGraphQLTypeHelper<TEntity, TKey> helper
) : base(
helper: helper,
repository: repository,
configuration: configuration
)
{
//
#region Retrieve ...
//
// Get ...
FieldAsync<TGraph> (
name: helper.GetInQuerySingleName (),
arguments: new QueryArguments (
XGraphQLHelper.GetIdArgument<TGraphKey> (),
FieldAsync<TGraph>(
name: helper.GetInQuerySingleName(),
arguments: new QueryArguments(
XGraphQLHelper.GetIdArgument<TGraphKey>(),
XGraphQLHelper.IgnoreSoftDeletedArgument
),
resolve : async context =>
resolve: async context =>
await repository
.GetAsync (
.GetAsync(
includeBuilder: null,
id: context.GetIdArgument<TKey> (),
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument ()
id: context.GetIdArgument<TKey>(),
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument()
)
.ToDynamicObject ()
.ToDynamicObject()
);
//
// GetAll ...
FieldAsync<ListGraphType<TGraph>> (
name: helper.GetInQueryCollectionName (),
arguments: new QueryArguments (
FieldAsync<ListGraphType<TGraph>>(
name: helper.GetInQueryCollectionName(),
arguments: new QueryArguments(
XGraphQLHelper.IgnoreSoftDeletedArgument
),
resolve : async context =>
resolve: async context =>
await repository
.GetAllAsync (
.GetAllAsync(
orderBuilder: null,
includeBuilder: null,
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument ()
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument()
)
.ToDynamicObject ()
.ToDynamicObject()
);
//
// FindOne ...
FieldAsync<TGraph> (
name: helper.GetFindOneName (),
arguments: new QueryArguments (
FieldAsync<TGraph>(
name: helper.GetFindOneName(),
arguments: new QueryArguments(
XGraphQLHelper.SearchQueryArgument,
XGraphQLHelper.IgnoreSoftDeletedArgument
),
resolve : async (context) => {
resolve: async (context) =>
{
//
var searchQuery = context.GetSearchQueryArgument ();
var searchQuery = context.GetSearchQueryArgument();
Expression<Func<TEntity, bool>> whereClase = pe => pe
.PropValuesContains (searchQuery);
.PropValuesContains(searchQuery);
//
return await repository
.FindOneAsync (
.FindOneAsync(
includeBuilder: null,
predicate: whereClase,
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument ()
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument()
)
.ToDynamicObject ();
.ToDynamicObject();
}
);
//
// FindMany ...
FieldAsync<ListGraphType<TGraph>> (
name: helper.GetFindManyName (),
arguments: new QueryArguments (
FieldAsync<ListGraphType<TGraph>>(
name: helper.GetFindManyName(),
arguments: new QueryArguments(
XGraphQLHelper.SearchQueryArgument,
XGraphQLHelper.IgnoreSoftDeletedArgument
),
resolve : async (context) => {
resolve: async (context) =>
{
//
var searchQuery = context.GetSearchQueryArgument ();
var searchQuery = context.GetSearchQueryArgument();
Expression<Func<TEntity, bool>> whereClase = pe => pe
.PropValuesContains (searchQuery);
.PropValuesContains(searchQuery);
//
return await repository
.FindManyAsync (
.FindManyAsync(
orderBuilder: null,
includeBuilder: null,
predicate: whereClase,
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument ()
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument()
)
.ToDynamicObject ();
.ToDynamicObject();
}
);
//
// Query ...
FieldAsync<XGraphQueryResult<TEntity, TGraph>> (
name: helper.GetQueryName (),
arguments: new QueryArguments (
FieldAsync<XGraphQueryResult<TEntity, TGraph>>(
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<IntGraphType> (
name: helper.GetCountName (),
arguments: new QueryArguments (
XGraphQLHelper.IgnoreSoftDeletedArgument
),
resolve: async context =>
await repository
.CountAsync (
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument ()
.QueryAsync(
predicate: null,
orderBuilder: null,
includeBuilder: null,
query: context.GetQueryArgument(),
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument()
)
.ToDynamicObject()
);
//
// Count ...
FieldAsync<IntGraphType>(
name: helper.GetCountName(),
arguments: new QueryArguments(
XGraphQLHelper.IgnoreSoftDeletedArgument
),
resolve: async context =>
await repository
.CountAsync(
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument()
)
);
//
// Exists ...
FieldAsync<BooleanGraphType> (
name: helper.GetExistsName (),
arguments: new QueryArguments (
XGraphQLHelper.GetIdArgument<TGraphKey> (),
FieldAsync<BooleanGraphType>(
name: helper.GetExistsName(),
arguments: new QueryArguments(
XGraphQLHelper.GetIdArgument<TGraphKey>(),
XGraphQLHelper.IgnoreSoftDeletedArgument
),
resolve : async context =>
await repository.IsExistsAsync (
id: context.GetIdArgument<TKey> (),
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument ()
resolve: async context =>
await repository.IsExistsAsync(
id: context.GetIdArgument<TKey>(),
ignoreSoftDeleteds: context.GetIgnoreSoftDeletedArgument()
)
);
#endregion
+108 -56
View File
@@ -3,62 +3,114 @@ using xDataService.Configuration;
using xDataService.Interfaces;
using xModels.Base;
namespace xDataService.GraphQL {
public abstract class XBaseGraphQLTypeHelper<TEntity, TKey> : IXBaseGraphQLTypeHelper<TEntity, TKey>
where TEntity : XBaseEntity<TKey> {
//
private readonly XDataServiceConfiguration configuration;
namespace xDataService.GraphQL
{
public abstract class XBaseGraphQLTypeHelper : IXBaseGraphQLTypeHelper
{
//
protected readonly XDataServiceConfiguration configuration;
//
public XBaseGraphQLTypeHelper (
XDataServiceConfiguration configuration = null
) {
this.configuration = configuration;
}
//
public abstract string GetInQueryCollectionName ();
public abstract string GetInQuerySingleName ();
//
public string GetFindOneName () {
return $"find{GetInQuerySingleName ().ToNormalString().Capitalize()}";
}
public string GetFindManyName () {
return $"find{GetInQueryCollectionName ().ToNormalString().Capitalize()}";
}
public string GetQueryName () {
return $"query{GetInQueryCollectionName().ToNormalString().Capitalize()}";
}
public string GetCountName () {
return $"count{GetInQueryCollectionName().ToNormalString().Capitalize()}";
}
public string GetExistsName () {
return $"exists{GetInQuerySingleName().ToNormalString().Capitalize()}";
}
public string GetGraphQLPath (string baseGraphPath = null) {
//
baseGraphPath = baseGraphPath.IsNullOrEmpty () ?
configuration.IsNull () || configuration.GraphQLBasePath.IsNullOrEmpty () ?
"" :
configuration.GraphQLBasePath :
baseGraphPath;
//
var basePath = baseGraphPath
.EndsWith ("/") ?
baseGraphPath
.Substring (0, baseGraphPath.Length - 1) :
baseGraphPath;
//
return $"{basePath}/{GetInQueryCollectionName().ToNormalString()}";
}
//
public XBaseGraphQLTypeHelper(
XDataServiceConfiguration configuration
)
{
this.configuration = configuration;
}
public abstract string GetInQuerySingleName();
public abstract string GetInQueryCollectionName();
//
#region Actions ...
public virtual string GetCountName()
{
return string.Empty;
}
public virtual string GetExistsName()
{
return string.Empty;
}
public virtual string GetFindManyName()
{
return string.Empty;
}
public virtual string GetFindOneName()
{
return string.Empty;
}
public virtual string GetGraphQLPath(string baseGraphPath = null)
{
return string.Empty;
}
public virtual string GetQueryName()
{
return string.Empty;
}
#endregion
}
public abstract class XBaseGraphQLTypeHelper<TEntity, TKey> : XBaseGraphQLTypeHelper, IXBaseGraphQLTypeHelper<TEntity, TKey>
where TEntity : XBaseEntity<TKey>
{
//
public XBaseGraphQLTypeHelper(
XDataServiceConfiguration configuration = null
) : base(configuration)
{ }
//
#region Actions ...
public override string GetFindOneName()
{
return $"find{GetInQuerySingleName().ToNormalString().Capitalize()}";
}
public override string GetFindManyName()
{
return $"find{GetInQueryCollectionName().ToNormalString().Capitalize()}";
}
public override string GetQueryName()
{
return $"query{GetInQueryCollectionName().ToNormalString().Capitalize()}";
}
public override string GetCountName()
{
return $"count{GetInQueryCollectionName().ToNormalString().Capitalize()}";
}
public override string GetExistsName()
{
return $"exists{GetInQuerySingleName().ToNormalString().Capitalize()}";
}
public override string GetGraphQLPath(string baseGraphPath = null)
{
//
baseGraphPath = baseGraphPath.IsNullOrEmpty() ?
configuration.IsNull() || configuration.GraphQLBasePath.IsNullOrEmpty() ?
"" :
configuration.GraphQLBasePath :
baseGraphPath;
//
var basePath = baseGraphPath
.EndsWith("/") ?
baseGraphPath
.Substring(0, baseGraphPath.Length - 1) :
baseGraphPath;
//
return $"{basePath}/{GetInQueryCollectionName().ToNormalString()}";
}
#endregion
}
}