Skip to content

Commit

Permalink
fix(auth): authorize directive
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhck committed May 30, 2021
1 parent b87de29 commit ea35c49
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Micro.Auth.Api/GraphQL/Directives/AuthorizeDirective.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GraphQL;
using GraphQL.Resolvers;
using GraphQL.Types;
using GraphQL.Utilities;
using Micro.Auth.Api.GraphQL.Directives.Exceptions;
Expand All @@ -9,6 +10,8 @@ namespace Micro.Auth.Api.GraphQL.Directives
public class AuthorizeDirective : DirectiveGraphType
{
public const string DirectiveName = "authorize";
public override bool? Introspectable => true;

public AuthorizeDirective() : base(
DirectiveName,
DirectiveLocation.Field,
Expand Down Expand Up @@ -41,7 +44,10 @@ public override void VisitObjectFieldDefinition(FieldType field, IObjectGraphTyp
return;
}

throw new NotAuthorizedException();
field.Resolver = new AsyncFieldResolver<object>(async context =>
{
throw new NotAuthorizedException();
});
}
}
}

0 comments on commit ea35c49

Please sign in to comment.