Skip to content

Commit

Permalink
[HER-49] Create detections query (#24)
Browse files Browse the repository at this point in the history
* [HER-49]Add Resolver and IResolver to Creating

* [HER-49]Add Resolver and IResolver to Fetching

* [HER-49]Add services to Startup

* [HER-49]Add field to query

* [HER-49]Add provider variable to Schema

* [HER-49]Add TDetection

* [HER-49]Add missing reference
  • Loading branch information
Urzica-Platon-Casian authored Jul 9, 2021
1 parent 221c01e commit 17f43cc
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 14 deletions.
19 changes: 19 additions & 0 deletions src/Presentation/Detection/Common/Types/TDetection.cs
Original file line number Diff line number Diff line change
@@ -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<MDetection>
{
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");
}
}
}
12 changes: 12 additions & 0 deletions src/Presentation/Detection/Creating/IResolver.cs
Original file line number Diff line number Diff line change
@@ -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<IResolveFieldContext<object>, IEnumerable<MDetection>>
{
}
}
16 changes: 16 additions & 0 deletions src/Presentation/Detection/Creating/Resolver.cs
Original file line number Diff line number Diff line change
@@ -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<MDetection> Execute(IResolveFieldContext<object> input) =>
new[]
{
new MDetection { Id = 1, Class = "Pet", Score = 60, Timestamp = DateTime.UtcNow },
};
}
}
12 changes: 12 additions & 0 deletions src/Presentation/Detection/Fetching/IResolver.cs
Original file line number Diff line number Diff line change
@@ -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<IResolveFieldContext<object>, IEnumerable<MDetection>>
{
}
}
16 changes: 16 additions & 0 deletions src/Presentation/Detection/Fetching/Resolver.cs
Original file line number Diff line number Diff line change
@@ -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<MDetection> Execute(IResolveFieldContext<object> input) =>
new[]
{
new MDetection { Id = 2, Class = "Cardboard", Score = 80, Timestamp = DateTime.UtcNow },
};
}
}
21 changes: 14 additions & 7 deletions src/Presentation/GraphQL/Base/Query.cs
Original file line number Diff line number Diff line change
@@ -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<ListGraphType<NonNullGraphType<TDetection>>>),
"detections",
"Fetch all the existing detections",
resolve: provider.GetService<Detection.Fetching.IResolver>().Execute);
}
}
}
5 changes: 3 additions & 2 deletions src/Presentation/GraphQL/Base/Schema.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
7 changes: 2 additions & 5 deletions src/Presentation/Startup.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -26,7 +22,8 @@ public void ConfigureServices(IServiceCollection services)
services.AddControllers();

services.AddScoped<Schema>();
services.AddTransient<IGetDetection>();
services.AddScoped<Detection.Creating.IResolver, Detection.Creating.Resolver>();
services.AddScoped<Detection.Fetching.IResolver, Detection.Fetching.Resolver>();
}

public void Configure(IApplicationBuilder app, Context context)
Expand Down

0 comments on commit 17f43cc

Please sign in to comment.