diff --git a/Demo/Demo.csproj b/Demo/Demo.csproj
index b558cd1..7abba2b 100644
--- a/Demo/Demo.csproj
+++ b/Demo/Demo.csproj
@@ -6,6 +6,7 @@
+
@@ -17,6 +18,7 @@
+
diff --git a/Demo/Startup.cs b/Demo/Startup.cs
index 988a41a..ed21cbe 100644
--- a/Demo/Startup.cs
+++ b/Demo/Startup.cs
@@ -4,6 +4,7 @@ using Demo.DynamicQueries;
using Demo.Queries;
using FluentValidation;
using FluentValidation.AspNetCore;
+using HotChocolate.Types;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
@@ -18,6 +19,7 @@ using PoweredSoft.CQRS.AspNetCore.Mvc;
using PoweredSoft.CQRS.DynamicQuery;
using PoweredSoft.CQRS.DynamicQuery.Abstractions;
using PoweredSoft.CQRS.DynamicQuery.AspNetCore;
+using PoweredSoft.CQRS.GraphQL.HotChocolate;
using PoweredSoft.Data;
using PoweredSoft.Data.Core;
using PoweredSoft.DynamicQuery;
@@ -27,7 +29,7 @@ using System.Linq;
using System.Threading.Tasks;
namespace Demo
-{
+{
public class Startup
{
public Startup(IConfiguration configuration)
@@ -56,7 +58,15 @@ namespace Demo
.AddPoweredSoftDynamicQueries()
.AddFluentValidation();
- services.AddSwaggerGen();
+ services
+ .AddGraphQLServer()
+ .AddQueryType(d => d.Name("Query"))
+ .AddPoweredSoftQueries()
+ .AddMutationType(d => d.Name("Mutation"))
+ .AddPoweredSoftMutations();
+
+
+ //services.AddSwaggerGen();
}
private void AddDynamicQueries(IServiceCollection services)
@@ -100,18 +110,19 @@ namespace Demo
app.UseAuthorization();
- app.UseSwagger();
+ //app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
- app.UseSwaggerUI(c =>
- {
- c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
- });
+ //app.UseSwaggerUI(c =>
+ //{
+ // c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
+ //});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
+ endpoints.MapGraphQL();
});
}
}
diff --git a/PoweredSoft.CQRS.Abstractions/Discovery/CommandMeta.cs b/PoweredSoft.CQRS.Abstractions/Discovery/CommandMeta.cs
index f875d43..1645151 100644
--- a/PoweredSoft.CQRS.Abstractions/Discovery/CommandMeta.cs
+++ b/PoweredSoft.CQRS.Abstractions/Discovery/CommandMeta.cs
@@ -33,5 +33,19 @@ namespace PoweredSoft.CQRS.Abstractions.Discovery
public virtual Type CommandType { get; }
public virtual Type ServiceType { get; }
public virtual Type CommandResultType { get; }
+
+ public string LowerCamelCaseName
+ {
+ get
+ {
+ if (string.IsNullOrEmpty(Name))
+ return Name;
+
+ var name = Name;
+ var firstLetter = Char.ToLowerInvariant(name[0]);
+ var ret = $"{firstLetter}{name.Substring(1)}";
+ return ret;
+ }
+ }
}
}
diff --git a/PoweredSoft.CQRS.Abstractions/Discovery/ICommandMeta.cs b/PoweredSoft.CQRS.Abstractions/Discovery/ICommandMeta.cs
index 96720fc..cbfb257 100644
--- a/PoweredSoft.CQRS.Abstractions/Discovery/ICommandMeta.cs
+++ b/PoweredSoft.CQRS.Abstractions/Discovery/ICommandMeta.cs
@@ -8,5 +8,6 @@ namespace PoweredSoft.CQRS.Abstractions.Discovery
Type CommandType { get; }
Type ServiceType { get; }
Type CommandResultType { get; }
+ string LowerCamelCaseName { get; }
}
}
diff --git a/PoweredSoft.CQRS.Abstractions/Discovery/IQueryMeta.cs b/PoweredSoft.CQRS.Abstractions/Discovery/IQueryMeta.cs
index f200d55..cb10539 100644
--- a/PoweredSoft.CQRS.Abstractions/Discovery/IQueryMeta.cs
+++ b/PoweredSoft.CQRS.Abstractions/Discovery/IQueryMeta.cs
@@ -12,5 +12,6 @@ namespace PoweredSoft.CQRS.Abstractions.Discovery
Type ServiceType { get; }
Type QueryResultType { get; }
string Category { get; }
+ string LowerCamelCaseName { get; }
}
}
diff --git a/PoweredSoft.CQRS.Abstractions/Discovery/QueryMeta.cs b/PoweredSoft.CQRS.Abstractions/Discovery/QueryMeta.cs
index a8dd58f..d866adc 100644
--- a/PoweredSoft.CQRS.Abstractions/Discovery/QueryMeta.cs
+++ b/PoweredSoft.CQRS.Abstractions/Discovery/QueryMeta.cs
@@ -28,5 +28,19 @@ namespace PoweredSoft.CQRS.Abstractions.Discovery
public virtual Type ServiceType { get; }
public virtual Type QueryResultType { get; }
public virtual string Category => "BasicQuery";
+
+ public string LowerCamelCaseName
+ {
+ get
+ {
+ if (string.IsNullOrEmpty(Name))
+ return Name;
+
+ var name = Name;
+ var firstLetter = Char.ToLowerInvariant(name[0]);
+ var ret = $"{firstLetter}{name.Substring(1)}";
+ return ret;
+ }
+ }
}
}
diff --git a/PoweredSoft.CQRS.AspNetCore/Mvc/CommandControllerConvention.cs b/PoweredSoft.CQRS.AspNetCore/Mvc/CommandControllerConvention.cs
index 4962115..eb5c5e7 100644
--- a/PoweredSoft.CQRS.AspNetCore/Mvc/CommandControllerConvention.cs
+++ b/PoweredSoft.CQRS.AspNetCore/Mvc/CommandControllerConvention.cs
@@ -21,7 +21,7 @@ namespace PoweredSoft.CQRS.AspNetCore.Mvc
var genericType = controller.ControllerType.GenericTypeArguments[0];
var commandDiscovery = this.serviceProvider.GetRequiredService();
var command = commandDiscovery.FindCommand(genericType);
- controller.ControllerName = command.Name;
+ controller.ControllerName = command.LowerCamelCaseName;
}
}
}
diff --git a/PoweredSoft.CQRS.AspNetCore/Mvc/QueryControllerConvention.cs b/PoweredSoft.CQRS.AspNetCore/Mvc/QueryControllerConvention.cs
index b3b740c..ccbf0a1 100644
--- a/PoweredSoft.CQRS.AspNetCore/Mvc/QueryControllerConvention.cs
+++ b/PoweredSoft.CQRS.AspNetCore/Mvc/QueryControllerConvention.cs
@@ -21,7 +21,7 @@ namespace PoweredSoft.CQRS.AspNetCore.Mvc
var genericType = controller.ControllerType.GenericTypeArguments[0];
var queryDiscovery = this.serviceProvider.GetRequiredService();
var query = queryDiscovery.FindQuery(genericType);
- controller.ControllerName = query.Name;
+ controller.ControllerName = query.LowerCamelCaseName;
}
}
}
diff --git a/PoweredSoft.CQRS.DynamicQuery.AspNetCore/Mvc/DynamicQueryControllerConvention.cs b/PoweredSoft.CQRS.DynamicQuery.AspNetCore/Mvc/DynamicQueryControllerConvention.cs
index cd37b0a..2f90166 100644
--- a/PoweredSoft.CQRS.DynamicQuery.AspNetCore/Mvc/DynamicQueryControllerConvention.cs
+++ b/PoweredSoft.CQRS.DynamicQuery.AspNetCore/Mvc/DynamicQueryControllerConvention.cs
@@ -23,7 +23,7 @@ namespace PoweredSoft.CQRS.DynamicQuery.AspNetCore.Mvc
var genericType = controller.ControllerType.GenericTypeArguments[0];
var queryDiscovery = this.serviceProvider.GetRequiredService();
var query = queryDiscovery.FindQuery(genericType);
- controller.ControllerName = query.Name;
+ controller.ControllerName = query.LowerCamelCaseName;
}
}
}
diff --git a/PoweredSoft.CQRS.GraphQL.HotChocolate/MutationObjectType.cs b/PoweredSoft.CQRS.GraphQL.HotChocolate/MutationObjectType.cs
new file mode 100644
index 0000000..9452676
--- /dev/null
+++ b/PoweredSoft.CQRS.GraphQL.HotChocolate/MutationObjectType.cs
@@ -0,0 +1,84 @@
+using HotChocolate.Resolvers;
+using HotChocolate.Types;
+using PoweredSoft.CQRS.Abstractions;
+using PoweredSoft.CQRS.Abstractions.Discovery;
+using System;
+using System.Collections.Generic;
+
+namespace PoweredSoft.CQRS.GraphQL.HotChocolate
+{
+ public class MutationObjectType : ObjectTypeExtension
+ {
+ private readonly ICommandDiscovery commandDiscovery;
+
+ public MutationObjectType(ICommandDiscovery commandDiscovery) : base()
+ {
+ this.commandDiscovery = commandDiscovery;
+ }
+
+ protected override void Configure(IObjectTypeDescriptor desc)
+ {
+ desc.Name("Mutation");
+ foreach (var m in commandDiscovery.GetCommands())
+ {
+ var queryField = desc.Field(m.LowerCamelCaseName);
+
+ Type typeToGet;
+ if (m.CommandResultType == null)
+ typeToGet = typeof(ICommandHandler<>).MakeGenericType(m.CommandType);
+ else
+ typeToGet = typeof(ICommandHandler<,>).MakeGenericType(m.CommandType, m.CommandResultType);
+
+ if (m.CommandResultType == null)
+ queryField.Type(typeof(int?));
+ else
+ queryField.Type(m.CommandResultType);
+
+ //queryField.Use((sp, d) => new MutationAuthorizationMiddleware(m.CommandType, d));
+
+ if (m.CommandType.GetProperties().Length == 0)
+ {
+ queryField.Resolve(async ctx =>
+ {
+ var queryArgument = Activator.CreateInstance(m.CommandType);
+ return await HandleMutation(m.CommandResultType != null, ctx, typeToGet, queryArgument);
+ });
+
+ continue;
+ }
+
+ queryField.Argument("params", t => t.Type(m.CommandType));
+
+ queryField.Resolve(async ctx =>
+ {
+ var queryArgument = ctx.ArgumentValue