Fix GraphQL Implementation and also UI Playground and add supports for Oracle Provider using EF Core ...

This commit is contained in:
2026-05-13 23:14:37 +03:30
parent 3bb6042b31
commit 99dc78ee4b
11 changed files with 576 additions and 296 deletions
+1 -1
View File
@@ -24,6 +24,6 @@ namespace xDataService.Configuration
/// Holds Seeding items ...
/// nameof(TEntity) => TEntity
/// </summary>
public IDictionary<string, List<dynamic>> SeedItems { get; set; } = new Dictionary<string, List<dynamic>>();
public IDictionary<string, List<object>> SeedItems { get; set; } = new Dictionary<string, List<object>>();
}
}
+3 -1
View File
@@ -6,6 +6,7 @@ namespace xDataService.Constants {
None,
MySQL,
SQLite,
Oracle,
SQLServer,
MongoDB,
}
@@ -16,8 +17,9 @@ namespace xDataService.Constants {
public partial struct ProviderType {
public const string MySQL = "MYSQL";
public const string SQLite = "SQLITE";
public const string SQLServer = "SQLSERVER";
public const string Oracle = "ORACLE";
public const string MongoDB = "MONGODB";
public const string SQLServer = "SQLSERVER";
}
}
+42 -10
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using GraphQL.Server.Ui.Playground;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.Configuration;
@@ -45,10 +46,24 @@ namespace xDataService.DI
.ForEach(db =>
{
//
// TODO: Fix this ...
var sectionName = $"{ConfigurationNodeNames.DATA_SERVICE_NODE}:{nameof(XDataServiceConfiguration.Databases)}:{db.Key}:{nameof(XDataBaseConfiguration.SeedItems)}";
// var seedItems = source.GetSectionAsDictionary(sectionName);
// db.Value.SeedItems = seedItems;
var seedItemsSectionName = $"{ConfigurationNodeNames.DATA_SERVICE_NODE}:{nameof(XDataServiceConfiguration.Databases)}:{db.Key}:{nameof(XDataBaseConfiguration.SeedItems)}";
var section = source.GetSection(seedItemsSectionName);
var sectionJson = source.GetSectionAsJson(seedItemsSectionName);
var sectionDict = sectionJson.FromJSON<Dictionary<string, List<object>>>();
if (!sectionDict.IsNull() &&
sectionDict.Values.HasChild())
{
//
sectionDict
.Keys
.ToList()
.ForEach(entity =>
{
//
// Setting Values to Result ...
result.Databases[db.Key].SeedItems[entity] = sectionDict[entity];
});
}
});
}
@@ -248,7 +263,8 @@ namespace xDataService.DI
public static void UseXDatabase(
this IApplicationBuilder source,
XDatabaseDescriptor descriptor,
bool isDevelopmentEnvironment = false
bool isDevelopmentEnvironment = false,
GraphQLPlaygroundOptions options = null
)
{
//
@@ -265,9 +281,9 @@ namespace xDataService.DI
//
var withPlayground = false;
var isGraphConfigured = false;
if (isDevelopmentEnvironment)
{
//
withPlayground = true;
}
@@ -297,6 +313,7 @@ namespace xDataService.DI
//
// Check Seeder Exists ...
// Execute Seeding Data Task if Exists ...
isValid = r.HasSeeder();
if (isValid)
{
@@ -312,7 +329,8 @@ namespace xDataService.DI
// Seeding ...
seeder
.Seed()
.RunTask();
.GetAwaiter()
.GetResult();
}
}
@@ -323,7 +341,10 @@ namespace xDataService.DI
{
//
// Use WebSockets ...
source.UseWebSockets();
if (!isGraphConfigured)
{
source.UseWebSockets();
}
//
// Inject GraphQL Type Helper ...
@@ -332,7 +353,9 @@ namespace xDataService.DI
if (isValid)
{
//
string graphPath = helper.GetGraphQLPath();
string graphPath = $"{helper.GetGraphQLPath()}";
// string graphPath = $"{dataServiceConfiguration.GraphQLBasePath}{helper.GetGraphQLPath()}";
graphPath = $"{helper.GetGraphQLPath()}";
typeof(XDataServiceHelper).InvokeGenericMethod(
methodName: "UseXGraphQL",
runtimeTypes: [
@@ -352,6 +375,15 @@ namespace xDataService.DI
null
]
);
//
Log($"Register GraphQL: {graphPath}");
}
//
if (!isGraphConfigured)
{
isGraphConfigured = true;
}
}
});
+4 -21
View File
@@ -11,16 +11,17 @@ using xModels.Base;
namespace xDataService.GraphQL
{
public abstract class XBaseGraphQLQuery : ObjectGraphType, IXBaseGraphQLQuery { }
public abstract class XBaseGraphQLQuery<TEntity, TKey> : XBaseGraphQLQuery, IXBaseGraphQLQuery<TEntity, TKey>
public abstract class XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey> : ObjectGraphType, IXBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
where TEntity : XBaseEntity<TKey>
where TGraph : IGraphType
where TGraphKey : IGraphType
{
//
protected readonly XDataServiceConfiguration configuration;
protected readonly IXBaseRepository<TEntity, TKey> repository;
protected readonly IXBaseGraphQLTypeHelper<TEntity, TKey> helper;
//
public XBaseGraphQLQuery(
XDataServiceConfiguration configuration,
IXBaseRepository<TEntity, TKey> repository,
@@ -34,25 +35,7 @@ namespace xDataService.GraphQL
//
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 ...
//
+12 -55
View File
@@ -5,94 +5,52 @@ using xModels.Base;
namespace xDataService.GraphQL
{
public abstract class XBaseGraphQLTypeHelper : IXBaseGraphQLTypeHelper
public abstract class XBaseGraphQLTypeHelper<TEntity, TKey> : IXBaseGraphQLTypeHelper<TEntity, TKey>
where TEntity : XBaseEntity<TKey>
{
//
protected readonly XDataServiceConfiguration configuration;
private readonly XDataServiceConfiguration configuration;
//
public XBaseGraphQLTypeHelper(
XDataServiceConfiguration configuration
XDataServiceConfiguration configuration = null
)
{
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)
{ }
public abstract string GetInQuerySingleName();
//
#region Actions ...
public override string GetFindOneName()
public string GetFindOneName()
{
return $"find{GetInQuerySingleName().ToNormalString().Capitalize()}";
}
public override string GetFindManyName()
public string GetFindManyName()
{
return $"find{GetInQueryCollectionName().ToNormalString().Capitalize()}";
}
public override string GetQueryName()
public string GetQueryName()
{
return $"query{GetInQueryCollectionName().ToNormalString().Capitalize()}";
}
public override string GetCountName()
public string GetCountName()
{
return $"count{GetInQueryCollectionName().ToNormalString().Capitalize()}";
}
public override string GetExistsName()
public string GetExistsName()
{
return $"exists{GetInQuerySingleName().ToNormalString().Capitalize()}";
}
public override string GetGraphQLPath(string baseGraphPath = null)
public string GetGraphQLPath(string baseGraphPath = null)
{
//
baseGraphPath = baseGraphPath.IsNullOrEmpty() ?
@@ -111,6 +69,5 @@ namespace xDataService.GraphQL
//
return $"{basePath}/{GetInQueryCollectionName().ToNormalString()}";
}
#endregion
}
}
+461 -185
View File
@@ -1,4 +1,5 @@
using System;
using GraphQL;
using GraphQL.Server;
using GraphQL.Server.Ui.Playground;
using GraphQL.Types;
@@ -83,6 +84,21 @@ namespace xDataService.Helpers
}, lifetime);
break;
//
// Oracle ...
case XDbProviders.Oracle:
//
source.AddEntityFrameworkOracle();
source.AddDbContext<TContext>(cfg =>
{
//
cfg.UseOracle(
databaseDescriptor.ConnectionString,
databaseDescriptor.OptionsBuilder
);
}, lifetime);
break;
//
// SQLServer ...
case XDbProviders.SQLServer:
@@ -153,6 +169,7 @@ namespace xDataService.Helpers
isValid =
databaseDescriptor.Provider == XDbProviders.MySQL ||
databaseDescriptor.Provider == XDbProviders.SQLite ||
databaseDescriptor.Provider == XDbProviders.Oracle ||
databaseDescriptor.Provider == XDbProviders.SQLServer;
if (isValid)
{
@@ -1223,22 +1240,118 @@ namespace xDataService.Helpers
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
{
//
// Validate Args ...
var isValid = repositoryDescriptor.IsValid();
if (!isValid)
{
return;
}
//
// Chck Seeders ...
isValid = repositoryDescriptor.HasSeeder();
if (isValid)
{
}
//
// GraphQL ...
isValid = repositoryDescriptor.HasGraphSupport();
if (isValid)
{
//
UseXGraphQL<TEntity, TKey, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>(
source,
repositoryDescriptor
);
// UseXGraphQL<TEntity, TKey, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>(
// source,
// repositoryDescriptor
// );
}
}
/// <summary>
/// Register Repository ...
/// </summary>
/// <param name="source"></param>
/// <param name="repositoryDescriptor"></param>
/// <param name="lifetime"></param>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TKeyGeneratorService"></typeparam>
/// <typeparam name="TKeyGeneratorImplementation"></typeparam>
/// <typeparam name="TEventsService"></typeparam>
/// <typeparam name="TEventsImplementation"></typeparam>
/// <typeparam name="TGraph"></typeparam>
/// <typeparam name="TGraphKey"></typeparam>
/// <typeparam name="TGraphQuery"></typeparam>
/// <typeparam name="TGraphTypeHelperService"></typeparam>
/// <typeparam name="TGraphTypeHelperImplementation"></typeparam>
/// <typeparam name="TGraphSchema"></typeparam>
/// <typeparam name="TRepositoryService"></typeparam>
/// <typeparam name="TRepositoryImplementation"></typeparam>
/// <typeparam name="TSeederService"></typeparam>
/// <typeparam name="TSeederImplementation"></typeparam>
/// <returns></returns>
public static void UseXRepository<
TEntity,
TKey,
TKeyGeneratorService,
TKeyGeneratorImplementation,
TEventsService,
TEventsImplementation,
TGraph,
TGraphKey,
TGraphQuery,
TGraphTypeHelperService,
TGraphTypeHelperImplementation,
TGraphSchema,
TRepositoryService,
TRepositoryImplementation,
TSeederService,
TSeederImplementation
>(
IApplicationBuilder source,
XInMemoryRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema, TRepositoryService, TRepositoryImplementation, TSeederService, TSeederImplementation> repositoryDescriptor
)
where TGraphSchema : Schema
where TGraphKey : IGraphType
where TEntity : XBaseEntity<TKey>
where TGraph : XBaseGraphObjectType<TEntity, TKey>
where TSeederService : IXBaseDbSeeder<TEntity, TKey>
where TEventsService : IXBaseRepositoryEvents<TEntity>
where TSeederImplementation : XBaseDbSeeder<TEntity, TKey>
where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
where TRepositoryService : IXBaseRepository<TEntity, TKey>
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
where TRepositoryImplementation : XBaseInMemoryRepository<TEntity, TKey>
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
{
//
// Validate Args ...
var isValid = repositoryDescriptor.IsValid();
if (!isValid)
{
return;
}
//
// Chck Seeders ...
isValid = repositoryDescriptor.HasSeeder();
if (isValid)
{
}
//
// GraphQL ...
isValid = repositoryDescriptor.HasGraphSupport();
if (isValid)
{
//
// UseXGraphQL<TEntity, TKey, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>(
// source,
// repositoryDescriptor
// );
}
}
@@ -1297,101 +1410,311 @@ namespace xDataService.Helpers
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
{
//
// Validate Args ...
var isValid = repositoryDescriptor.IsValid();
if (!isValid)
{
return;
}
//
// Chck Seeders ...
isValid = repositoryDescriptor.HasSeeder();
if (isValid)
{
}
//
// GraphQL ...
isValid = repositoryDescriptor.HasGraphSupport();
if (isValid)
{
//
UseXGraphQL<TEntity, TKey, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>(
source,
repositoryDescriptor
);
// UseXGraphQL<TEntity, TKey, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>(
// source,
// repositoryDescriptor
// );
}
}
// /// <summary>
// /// Register Repository ...
// /// </summary>
// /// <param name="source"></param>
// /// <param name="repositoryDescriptor"></param>
// /// <typeparam name="TEntity"></typeparam>
// /// <typeparam name="TKey"></typeparam>
// /// <typeparam name="TKeyGeneratorService"></typeparam>
// /// <typeparam name="TKeyGeneratorImplementation"></typeparam>
// /// <typeparam name="TEventsService"></typeparam>
// /// <typeparam name="TEventsImplementation"></typeparam>
// /// <typeparam name="TGraph"></typeparam>
// /// <typeparam name="TGraphKey"></typeparam>
// /// <typeparam name="TGraphQuery"></typeparam>
// /// <typeparam name="TGraphTypeHelperService"></typeparam>
// /// <typeparam name="TGraphTypeHelperImplementation"></typeparam>
// /// <typeparam name="TGraphSchema"></typeparam>
// /// <typeparam name="TRepositoryService"></typeparam>
// /// <typeparam name="TRepositoryImplementation"></typeparam>
// /// <typeparam name="TContext"></typeparam>
// /// <returns></returns>
// public static void UseXRepository<
// TEntity,
// TKey,
// TKeyGeneratorService,
// TKeyGeneratorImplementation,
// TEventsService,
// TEventsImplementation,
// TGraph,
// TGraphKey,
// TGraphQuery,
// TGraphTypeHelperService,
// TGraphTypeHelperImplementation,
// TGraphSchema,
// TRepositoryService,
// TRepositoryImplementation,
// TContext
// >(
// IApplicationBuilder source,
// XEFRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema, TRepositoryService, TRepositoryImplementation, TContext> repositoryDescriptor
// )
// where TGraphSchema : Schema
// where TContext : XDbContext
// where TGraphKey : IGraphType
// where TEntity : XBaseEntity<TKey>
// where TGraph : XBaseGraphObjectType<TEntity, TKey>
// where TEventsService : IXBaseRepositoryEvents<TEntity>
// where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
// where TRepositoryService : IXBaseRepository<TEntity, TKey>
// where TEventsImplementation : XBaseRepositoryEvents<TEntity>
// where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
// where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
// where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
// where TRepositoryImplementation : XBaseEFRepository<TEntity, TKey, TContext>
// where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
// {
// //
// var isValid = repositoryDescriptor.IsValid();
// if (!isValid)
// {
// return;
// }
/// <summary>
/// Register Repository ...
/// </summary>
/// <param name="source"></param>
/// <param name="repositoryDescriptor"></param>
/// <param name="lifetime"></param>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TKeyGeneratorService"></typeparam>
/// <typeparam name="TKeyGeneratorImplementation"></typeparam>
/// <typeparam name="TEventsService"></typeparam>
/// <typeparam name="TEventsImplementation"></typeparam>
/// <typeparam name="TGraph"></typeparam>
/// <typeparam name="TGraphKey"></typeparam>
/// <typeparam name="TGraphQuery"></typeparam>
/// <typeparam name="TGraphTypeHelperService"></typeparam>
/// <typeparam name="TGraphTypeHelperImplementation"></typeparam>
/// <typeparam name="TGraphSchema"></typeparam>
/// <typeparam name="TRepositoryService"></typeparam>
/// <typeparam name="TRepositoryImplementation"></typeparam>
/// <typeparam name="TSeederService"></typeparam>
/// <typeparam name="TSeederImplementation"></typeparam>
/// <returns></returns>
public static void UseXRepository<
TEntity,
TKey,
TKeyGeneratorService,
TKeyGeneratorImplementation,
TEventsService,
TEventsImplementation,
TGraph,
TGraphKey,
TGraphQuery,
TGraphTypeHelperService,
TGraphTypeHelperImplementation,
TGraphSchema,
TRepositoryService,
TRepositoryImplementation,
TSeederService,
TSeederImplementation
>(
IApplicationBuilder source,
XMongoRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema, TRepositoryService, TRepositoryImplementation, TSeederService, TSeederImplementation> repositoryDescriptor
)
where TGraphSchema : Schema
where TGraphKey : IGraphType
where TEntity : XBaseEntity<TKey>
where TGraph : XBaseGraphObjectType<TEntity, TKey>
where TSeederService : IXBaseDbSeeder<TEntity, TKey>
where TEventsService : IXBaseRepositoryEvents<TEntity>
where TSeederImplementation : XBaseDbSeeder<TEntity, TKey>
where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
where TRepositoryService : IXBaseRepository<TEntity, TKey>
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
where TRepositoryImplementation : XBaseMongoRepository<TEntity, TKey>
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
{
//
// Validate Args ...
var isValid = repositoryDescriptor.IsValid();
if (!isValid)
{
return;
}
// //
// // GraphQL ...
// isValid = repositoryDescriptor.HasGraphSupport();
// if (isValid)
// {
// //
// UseXGraphQL<TEntity, TKey, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>(
// source,
// repositoryDescriptor
// );
// }
// }
//
// Chck Seeders ...
isValid = repositoryDescriptor.HasSeeder();
if (isValid)
{
}
//
// GraphQL ...
isValid = repositoryDescriptor.HasGraphSupport();
if (isValid)
{
//
// UseXGraphQL<TEntity, TKey, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>(
// source,
// repositoryDescriptor
// );
}
}
/// <summary>
/// Register Repository ...
/// </summary>
/// <param name="source"></param>
/// <param name="repositoryDescriptor"></param>
/// <param name="lifetime"></param>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TKeyGeneratorService"></typeparam>
/// <typeparam name="TKeyGeneratorImplementation"></typeparam>
/// <typeparam name="TEventsService"></typeparam>
/// <typeparam name="TEventsImplementation"></typeparam>
/// <typeparam name="TGraph"></typeparam>
/// <typeparam name="TGraphKey"></typeparam>
/// <typeparam name="TGraphQuery"></typeparam>
/// <typeparam name="TGraphTypeHelperService"></typeparam>
/// <typeparam name="TGraphTypeHelperImplementation"></typeparam>
/// <typeparam name="TGraphSchema"></typeparam>
/// <typeparam name="TRepositoryService"></typeparam>
/// <typeparam name="TRepositoryImplementation"></typeparam>
/// <returns></returns>
public static void UseXRepository<
TEntity,
TKey,
TKeyGeneratorService,
TKeyGeneratorImplementation,
TEventsService,
TEventsImplementation,
TGraph,
TGraphKey,
TGraphQuery,
TGraphTypeHelperService,
TGraphTypeHelperImplementation,
TGraphSchema,
TRepositoryService,
TRepositoryImplementation,
TContext
>(
IApplicationBuilder source,
XEFRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema, TRepositoryService, TRepositoryImplementation, TContext> repositoryDescriptor
)
where TGraphSchema : Schema
where TContext : XDbContext
where TGraphKey : IGraphType
where TEntity : XBaseEntity<TKey>
where TGraph : XBaseGraphObjectType<TEntity, TKey>
where TEventsService : IXBaseRepositoryEvents<TEntity>
where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
where TRepositoryService : IXBaseRepository<TEntity, TKey>
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
where TRepositoryImplementation : XBaseEFRepository<TEntity, TKey, TContext>
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
{
//
// Validate Args ...
var isValid = repositoryDescriptor.IsValid();
if (!isValid)
{
return;
}
//
// Chck Seeders ...
isValid = repositoryDescriptor.HasSeeder();
if (isValid)
{
}
//
// GraphQL ...
isValid = repositoryDescriptor.HasGraphSupport();
if (isValid)
{
// //
// UseXGraphQL<TEntity, TKey, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>(
// source,
// repositoryDescriptor
// );
}
}
/// <summary>
/// Register Repository ...
/// </summary>
/// <param name="source"></param>
/// <param name="repositoryDescriptor"></param>
/// <param name="lifetime"></param>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TKeyGeneratorService"></typeparam>
/// <typeparam name="TKeyGeneratorImplementation"></typeparam>
/// <typeparam name="TEventsService"></typeparam>
/// <typeparam name="TEventsImplementation"></typeparam>
/// <typeparam name="TGraph"></typeparam>
/// <typeparam name="TGraphKey"></typeparam>
/// <typeparam name="TGraphQuery"></typeparam>
/// <typeparam name="TGraphTypeHelperService"></typeparam>
/// <typeparam name="TGraphTypeHelperImplementation"></typeparam>
/// <typeparam name="TGraphSchema"></typeparam>
/// <typeparam name="TRepositoryService"></typeparam>
/// <typeparam name="TRepositoryImplementation"></typeparam>
/// <typeparam name="TSeederService"></typeparam>
/// <typeparam name="TSeederImplementation"></typeparam>
/// <returns></returns>
public static void UseXRepository<
TEntity,
TKey,
TKeyGeneratorService,
TKeyGeneratorImplementation,
TEventsService,
TEventsImplementation,
TGraph,
TGraphKey,
TGraphQuery,
TGraphTypeHelperService,
TGraphTypeHelperImplementation,
TGraphSchema,
TRepositoryService,
TRepositoryImplementation,
TContext,
TSeederService,
TSeederImplementation
>(
IApplicationBuilder source,
XEFRepositoryDescriptor<TEntity, TKey, TKeyGeneratorService, TKeyGeneratorImplementation, TEventsService, TEventsImplementation, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema, TRepositoryService, TRepositoryImplementation, TContext, TSeederService, TSeederImplementation> repositoryDescriptor
)
where TGraphSchema : Schema
where TContext : XDbContext
where TGraphKey : IGraphType
where TEntity : XBaseEntity<TKey>
where TGraph : XBaseGraphObjectType<TEntity, TKey>
where TSeederService : IXBaseDbSeeder<TEntity, TKey>
where TEventsService : IXBaseRepositoryEvents<TEntity>
where TSeederImplementation : XBaseDbSeeder<TEntity, TKey>
where TKeyGeneratorService : IXKeyGenerator<TEntity, TKey>
where TRepositoryService : IXBaseRepository<TEntity, TKey>
where TEventsImplementation : XBaseRepositoryEvents<TEntity>
where TKeyGeneratorImplementation : XKeyGenerator<TEntity, TKey>
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
where TRepositoryImplementation : XBaseEFRepository<TEntity, TKey, TContext>
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
{
//
// Validate Args ...
var isValid = repositoryDescriptor.IsValid();
if (!isValid)
{
return;
}
//
// Chck Seeders ...
isValid = repositoryDescriptor.HasSeeder();
if (isValid)
{
}
//
// GraphQL ...
isValid = repositoryDescriptor.HasGraphSupport();
if (isValid)
{
// //
// UseXGraphQL<TEntity, TKey, TGraph, TGraphKey, TGraphQuery, TGraphTypeHelperService, TGraphTypeHelperImplementation, TGraphSchema>(
// source,
// repositoryDescriptor
// );
}
}
/// <summary>
/// Use GraphQL ...
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TGraph"></typeparam>
/// <typeparam name="TGraphKey"></typeparam>
/// <typeparam name="TGraphQuery"></typeparam>
/// <typeparam name="TGraphTypeHelperService"></typeparam>
/// <typeparam name="TGraphTypeHelperImplementation"></typeparam>
/// <typeparam name="TGraphSchema"></typeparam>
/// <param name="source"></param>
/// <param name="graphPath"></param>
/// <param name="withPlayGround"></param>
/// <param name="options"></param>
public static void UseXGraphQL<
TEntity,
TKey,
@@ -1422,6 +1745,14 @@ namespace xDataService.Helpers
//
if (withPlayGround)
{
//
if (options.IsNull())
{
options = new GraphQLPlaygroundOptions();
}
options.Path = "/ui/playground";
//
source.UseGraphQLPlayground(options);
}
}
@@ -1600,43 +1931,13 @@ namespace xDataService.Helpers
return;
}
//
// Register Graph Schema ...
source.Add(
new ServiceDescriptor(
repositoryDescriptor.GraphSchema,
repositoryDescriptor.GraphSchema,
lifetime
)
);
//
// Register Graph Query ...
source.Add(
new ServiceDescriptor(
repositoryDescriptor.GraphQuery,
repositoryDescriptor.GraphQuery,
lifetime
)
);
//
// Register Graph Type Helper ...
source.Add(
new ServiceDescriptor(
repositoryDescriptor.GraphTypeHelperService,
repositoryDescriptor.GraphTypeHelperImplementation,
lifetime: ServiceLifetime.Singleton
)
);
//
// Register Graph Type ...
source.Add(
new ServiceDescriptor(
repositoryDescriptor.GraphType,
repositoryDescriptor.GraphType,
ServiceLifetime.Singleton
lifetime: ServiceLifetime.Singleton,
serviceType: repositoryDescriptor.GraphType,
implementationType: repositoryDescriptor.GraphType
)
);
@@ -1644,19 +1945,60 @@ namespace xDataService.Helpers
// Register Graph Events ...
source.Add(
new ServiceDescriptor(
typeof(XBaseGraphQLEventType<TEntity, TKey, TGraph>),
typeof(XBaseGraphQLEventType<TEntity, TKey, TGraph>),
ServiceLifetime.Singleton
lifetime: ServiceLifetime.Singleton,
serviceType: typeof(XBaseGraphQLEventType<TEntity, TKey, TGraph>),
implementationType: typeof(XBaseGraphQLEventType<TEntity, TKey, TGraph>)
)
);
//
// Register Graph Type Helper ...
source.Add(
new ServiceDescriptor(
lifetime: ServiceLifetime.Singleton,
serviceType: repositoryDescriptor.GraphTypeHelperService,
implementationType: repositoryDescriptor.GraphTypeHelperImplementation
)
);
//
// Register Graph Query ...
source.Add(
new ServiceDescriptor(
lifetime: lifetime,
serviceType: repositoryDescriptor.GraphQuery,
implementationType: repositoryDescriptor.GraphQuery
)
);
//
// Register Graph Schema ...
source.Add(
new ServiceDescriptor(
serviceType: repositoryDescriptor.GraphSchema,
implementationType: repositoryDescriptor.GraphSchema,
lifetime: lifetime
)
);
//
source.AddSingleton<IDocumentExecuter, DocumentExecuter>();
//
// Register Graph Type Schema ...
var builder = source.GetRegisteredService<IGraphQLBuilder>();
if (builder.IsNull())
{
//
Action<GraphQLOptions> options = x => { };
Action<GraphQLOptions> options = x =>
{
//
x.EnableMetrics = true;
x.UnhandledExceptionDelegate = context =>
{
Console.WriteLine("XGraphQL Error: " + context.OriginalException.Message);
};
};
builder = source.AddGraphQL(options)
.AddNewtonsoftJson(deserializerSettings => { }, serializerSettings => { })
.AddWebSockets()
@@ -1665,72 +2007,6 @@ namespace xDataService.Helpers
}
builder.AddGraphTypes(repositoryDescriptor.GraphSchema);
}
/// <summary>
/// Use GraphQL Middleware ...
/// </summary>
/// <param name="source"></param>
/// <param name="repositoryDescriptor"></param>
/// <param name="lifetime"></param>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TGraph"></typeparam>
/// <typeparam name="TGraphKey"></typeparam>
/// <typeparam name="TGraphQuery"></typeparam>
/// <typeparam name="TGraphTypeHelperService"></typeparam>
/// <typeparam name="TGraphTypeHelperImplementation"></typeparam>
/// <typeparam name="TGraphSchema"></typeparam>
/// <returns></returns>
public static void UseXGraphQL<
TEntity,
TKey,
TGraph,
TGraphKey,
TGraphQuery,
TGraphTypeHelperService,
TGraphTypeHelperImplementation,
TGraphSchema
>(
IApplicationBuilder source,
XRepositoryDescriptor<TEntity, TKey> repositoryDescriptor
)
where TGraphSchema : Schema
where TGraphKey : IGraphType
where TEntity : XBaseEntity<TKey>
where TGraph : XBaseGraphObjectType<TEntity, TKey>
where TGraphTypeHelperService : IXBaseGraphQLTypeHelper<TEntity, TKey>
where TGraphQuery : XBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
where TGraphTypeHelperImplementation : XBaseGraphQLTypeHelper<TEntity, TKey>
{
//
// Validate ...
var isValid =
!source.IsNull() &&
!repositoryDescriptor.IsNull() &&
!repositoryDescriptor.GraphType.IsNull() &&
!repositoryDescriptor.GraphQuery.IsNull() &&
!repositoryDescriptor.GraphSchema.IsNull() &&
!repositoryDescriptor.GraphTypeKey.IsNull() &&
!repositoryDescriptor.GraphTypeHelperService.IsNull() &&
!repositoryDescriptor.GraphTypeHelperImplementation.IsNull();
if (!isValid)
{
return;
}
//
// Create an Scope for Services Acces ...
using (var scope = source.ApplicationServices.CreateScope())
{
//
// Inject GraphQL Type Helper ...
var helper = scope.ServiceProvider.GetService<TGraphTypeHelperService>();
//
source.UseGraphQL<TGraphSchema>(helper.GetGraphQLPath());
source.UseGraphQLWebSockets<TGraphSchema>();
}
}
#endregion
}
}
+14
View File
@@ -10,10 +10,24 @@ namespace xDataService.Interfaces
public interface IXBaseDbSeeder<TEntity, TKey>
where TEntity : XBaseEntity<TKey>
{
/// <summary>
/// Holds Entity Name ...
/// </summary>
string Entity { get; }
/// <summary>
/// Holds Database Name ...
/// </summary>
string Database { get; }
/// <summary>
/// Repository Service for Data Manipulation ...
/// </summary>
IXBaseRepository<TEntity, TKey> Repository { get; }
/// <summary>
/// DataServiceConfiguration ...
/// </summary>
XDataServiceConfiguration DataServiceConfiguration { get; }
/// <summary>
+1 -7
View File
@@ -3,13 +3,7 @@ using xModels.Base;
namespace xDataService.Interfaces
{
public interface IXBaseGraphQLQuery { }
public interface IXBaseGraphQLQuery<TEntity, TKey> : IXBaseGraphQLQuery
where TEntity : XBaseEntity<TKey>
{ }
public interface IXBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey> : IXBaseGraphQLQuery<TEntity, TKey>
public interface IXBaseGraphQLQuery<TEntity, TKey, TGraph, TGraphKey>
where TEntity : XBaseEntity<TKey>
where TGraph : IGraphType
where TGraphKey : IGraphType
+3 -6
View File
@@ -2,10 +2,11 @@ using xModels.Base;
namespace xDataService.Interfaces
{
public interface IXBaseGraphQLTypeHelper
public interface IXBaseGraphQLTypeHelper<TEntity, TKey>
where TEntity : XBaseEntity<TKey>
{
string GetInQuerySingleName();
string GetInQueryCollectionName();
string GetFindOneName();
@@ -20,8 +21,4 @@ namespace xDataService.Interfaces
string GetGraphQLPath(string baseGraphPath = null);
}
public interface IXBaseGraphQLTypeHelper<TEntity, TKey> : IXBaseGraphQLTypeHelper
where TEntity : XBaseEntity<TKey>
{ }
}
+32 -8
View File
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@@ -12,29 +13,48 @@ namespace xDataService.Providers
public abstract class XBaseDbSeeder<TEntity, TKey> : IXBaseDbSeeder<TEntity, TKey>
where TEntity : XBaseEntity<TKey>
{
//
#region Properties ...
/// <summary>
/// Holds Entity Name ...
/// </summary>
public string Entity { get; }
/// <summary>
/// Holds Database Name ...
/// </summary>
public string Database { get; }
/// <summary>
/// Repository Service for Data Manipulation ...
/// </summary>
public IXBaseRepository<TEntity, TKey> Repository { get; }
/// <summary>
/// DataServiceConfiguration ...
/// </summary>
public XDataServiceConfiguration DataServiceConfiguration { get; }
#endregion
//
#region Constructor ...
public XBaseDbSeeder(
string entity,
string database,
IXBaseRepository<TEntity, TKey> repository,
XDataServiceConfiguration dataServiceConfiguration
)
{
//
this.Entity = entity;
this.Database = database;
this.Repository = repository;
this.DataServiceConfiguration = dataServiceConfiguration;
}
#endregion
public async Task Seed()
{
//
var entityName = nameof(TEntity);
//
// Validate Seed ...
var isValid =
@@ -45,7 +65,7 @@ namespace xDataService.Providers
db.Key == Database &&
db.Value.SeedItems
.Any(si =>
si.Key == entityName &&
si.Key == Entity &&
si.Value.HasChild()));
if (!isValid)
{
@@ -56,7 +76,7 @@ namespace xDataService.Providers
// Extract Seeding Items ...
var seedItems = DataServiceConfiguration
.Databases[Database]
.SeedItems[entityName]
.SeedItems[Entity]
.ToList();
foreach (var item in seedItems)
{
@@ -64,8 +84,9 @@ namespace xDataService.Providers
try
{
//
// Try to convert Item to Entity ...
var entity = ((object)item).FromDynamicObject<TEntity>();
var entity = item
.ToJSON()
.FromJSON<TEntity>();
//
// Check Item Exists or not ...
@@ -100,7 +121,10 @@ namespace xDataService.Providers
if (!isExist)
{
//
exists = await Repository.AddAsync(entity);
exists = await Repository.AddAsync(
item: entity,
saveChanges: true
);
}
break;
+3 -2
View File
@@ -31,12 +31,12 @@
<!-- <PackageReference Include="xDashboard.xModels" Version="1.0.0" /> -->
</ItemGroup>
<!-- Dependencies -->
<!-- MongoDB -->
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.13.2" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
</ItemGroup>
<!-- GraphQL -->
<ItemGroup>
<PackageReference Include="GraphQL" Version="3.0.0.2026" />
@@ -52,6 +52,7 @@
<ItemGroup>
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="MySql.EntityFrameworkCore" Version="3.1.14" />
<PackageReference Include="Oracle.EntityFrameworkCore" Version="3.19.180" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.14">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>