Skip to content

Commit

Permalink
Change authorize bewit from directive to middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
glucaci committed Mar 3, 2021
1 parent 4529eae commit 184a565
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace Bewit.Extensions.HotChocolate.Validation
namespace Bewit.Extensions.HotChocolate
{
public class BewitContext : IBewitContext
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Threading.Tasks;

namespace Bewit.Extensions.HotChocolate.Validation
namespace Bewit.Extensions.HotChocolate
{
public interface IBewitContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public BewitAuthorizationMiddleware(
}

public async Task InvokeAsync(
IDirectiveContext context)
IMiddlewareContext context)
{
try
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static IObjectFieldDescriptor AuthorizeBewit<T>(
this IObjectFieldDescriptor descriptor)
{
return descriptor
.Directive<BewitAuthorizeDirectiveType<T>>();
.Use<BewitAuthorizationMiddleware<T>>();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using Bewit.Core;
using Bewit.Validation;
using HotChocolate;
using HotChocolate.Execution.Configuration;
using HotChocolate.Resolvers;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

Expand Down Expand Up @@ -49,10 +49,11 @@ public static IRequestExecutorBuilder UseBewitAuthorization(

foreach (BewitPayloadContext context in registrationBuilder.Payloads)
{
Type implementation = typeof(BewitAuthorizeDirectiveType<>);
Type implementation = typeof(BewitAuthorizationMiddleware<>);
Type typedImplementation = implementation.MakeGenericType(context.Type);

builder.ConfigureSchema(b => b.AddDirectiveType(typedImplementation));
builder.ConfigureSchema(b =>
b.Use(FieldClassMiddlewareFactory.Create(typedImplementation)));
}
});

Expand Down

0 comments on commit 184a565

Please sign in to comment.