73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
using xCommons.Extensions;
|
|
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;
|
|
|
|
//
|
|
protected 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()}";
|
|
}
|
|
}
|
|
} |