116 lines
3.0 KiB
C#
116 lines
3.0 KiB
C#
using xCommons.Extensions;
|
|
using xDataService.Configuration;
|
|
using xDataService.Interfaces;
|
|
using xModels.Base;
|
|
|
|
namespace xDataService.GraphQL
|
|
{
|
|
public abstract class XBaseGraphQLTypeHelper : IXBaseGraphQLTypeHelper
|
|
{
|
|
//
|
|
protected readonly XDataServiceConfiguration configuration;
|
|
|
|
//
|
|
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
|
|
}
|
|
} |