diff --git a/src/Presentation/Detection/Common/Types/TDetection.cs b/src/Presentation/Detection/Common/Types/TDetection.cs new file mode 100644 index 0000000..af7cc4e --- /dev/null +++ b/src/Presentation/Detection/Common/Types/TDetection.cs @@ -0,0 +1,19 @@ +namespace Presentation.Detection.Common.Types +{ + using System.Diagnostics.CodeAnalysis; + using Business.Detection.Common.Models; + using global::GraphQL.Types; + using Style; + + [SuppressMessage(Category.Default, Check.CA1724, Justification = Reason.Readability)] + public sealed class TDetection : ObjectGraphType + { + public TDetection() + { + Field(detection => detection.Id).Description("This is the ID"); + Field(detection => detection.Score).Description("This is the Score"); + Field(detection => detection.Timestamp).Description("This is the Timestamp"); + Field(detection => detection.Class).Description("This is the Class"); + } + } +} diff --git a/src/Presentation/Detection/Creating/IResolver.cs b/src/Presentation/Detection/Creating/IResolver.cs new file mode 100644 index 0000000..77913b1 --- /dev/null +++ b/src/Presentation/Detection/Creating/IResolver.cs @@ -0,0 +1,12 @@ +namespace Presentation.Detection.Creating +{ + using System.Collections.Generic; + using Business; + using Business.Detection.Common.Models; + using Business.Detection.Fetching.Commands; + using global::GraphQL; + + public interface IResolver : ICommand, IEnumerable> + { + } +} diff --git a/src/Presentation/Detection/Creating/Resolver.cs b/src/Presentation/Detection/Creating/Resolver.cs new file mode 100644 index 0000000..b3a3b48 --- /dev/null +++ b/src/Presentation/Detection/Creating/Resolver.cs @@ -0,0 +1,16 @@ +namespace Presentation.Detection.Creating +{ + using System; + using System.Collections.Generic; + using Business.Detection.Common.Models; + using global::GraphQL; + + public class Resolver : IResolver + { + public IEnumerable Execute(IResolveFieldContext input) => + new[] + { + new MDetection { Id = 1, Class = "Pet", Score = 60, Timestamp = DateTime.UtcNow }, + }; + } +} diff --git a/src/Presentation/Detection/Fetching/IResolver.cs b/src/Presentation/Detection/Fetching/IResolver.cs new file mode 100644 index 0000000..ed61a5d --- /dev/null +++ b/src/Presentation/Detection/Fetching/IResolver.cs @@ -0,0 +1,12 @@ +namespace Presentation.Detection.Fetching +{ + using System.Collections.Generic; + using Business; + using Business.Detection.Common.Models; + using Business.Detection.Fetching.Commands; + using global::GraphQL; + + public interface IResolver : ICommand, IEnumerable> + { + } +} diff --git a/src/Presentation/Detection/Fetching/Resolver.cs b/src/Presentation/Detection/Fetching/Resolver.cs new file mode 100644 index 0000000..d5ee3d5 --- /dev/null +++ b/src/Presentation/Detection/Fetching/Resolver.cs @@ -0,0 +1,16 @@ +namespace Presentation.Detection.Fetching +{ + using System; + using System.Collections.Generic; + using Business.Detection.Common.Models; + using global::GraphQL; + + public class Resolver : IResolver + { + public IEnumerable Execute(IResolveFieldContext input) => + new[] + { + new MDetection { Id = 2, Class = "Cardboard", Score = 80, Timestamp = DateTime.UtcNow }, + }; + } +} diff --git a/src/Presentation/GraphQL/Base/Query.cs b/src/Presentation/GraphQL/Base/Query.cs index 344cacf..07e704d 100644 --- a/src/Presentation/GraphQL/Base/Query.cs +++ b/src/Presentation/GraphQL/Base/Query.cs @@ -1,16 +1,23 @@ namespace Presentation.GraphQL.Base { + using System; using System.Diagnostics.CodeAnalysis; using global::GraphQL.Types; + using Microsoft.Extensions.DependencyInjection; + using Presentation.Detection.Common.Types; using Style; [SuppressMessage(Category.Default, Check.CA1724, Justification = Reason.Readability)] + public class Query : ObjectGraphType - { - public Query() - { - Name = "Query"; - Field(typeof(StringGraphType), "BasicQuery", "Query description", null, _ => "Query"); - } - } + { + public Query(IServiceProvider provider) + { + Name = "query"; + Field(typeof(NonNullGraphType>>), + "detections", + "Fetch all the existing detections", + resolve: provider.GetService().Execute); + } + } } diff --git a/src/Presentation/GraphQL/Base/Schema.cs b/src/Presentation/GraphQL/Base/Schema.cs index 6709d66..b181b52 100644 --- a/src/Presentation/GraphQL/Base/Schema.cs +++ b/src/Presentation/GraphQL/Base/Schema.cs @@ -1,16 +1,17 @@ namespace Presentation.GraphQL.Base { + using System; using System.Diagnostics.CodeAnalysis; using Style; [SuppressMessage(Category.Default, Check.CA1724, Justification = Reason.Readability)] public class Schema : global::GraphQL.Types.Schema { - public Schema() + public Schema(IServiceProvider provider) { Mutation = new Mutation(); - Query = new Query(); + Query = new Query(provider); } } } diff --git a/src/Presentation/Startup.cs b/src/Presentation/Startup.cs index 3f342ae..aa202d2 100644 --- a/src/Presentation/Startup.cs +++ b/src/Presentation/Startup.cs @@ -1,9 +1,5 @@ namespace Presentation { - using System.Collections; - using System.Collections.Generic; - using Business.Detection.Common.Models; - using Business.Detection.Fetching.Commands; using Data; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; @@ -26,7 +22,8 @@ public void ConfigureServices(IServiceCollection services) services.AddControllers(); services.AddScoped(); - services.AddTransient(); + services.AddScoped(); + services.AddScoped(); } public void Configure(IApplicationBuilder app, Context context)