diff --git a/src/HotChocolate/AspNetCore/test/AspNetCore.Authorization.Tests/AuthorizeSchemaTests.cs b/src/HotChocolate/AspNetCore/test/AspNetCore.Authorization.Tests/AuthorizeSchemaTests.cs index e9a0f9d28e9..a426c32234a 100644 --- a/src/HotChocolate/AspNetCore/test/AspNetCore.Authorization.Tests/AuthorizeSchemaTests.cs +++ b/src/HotChocolate/AspNetCore/test/AspNetCore.Authorization.Tests/AuthorizeSchemaTests.cs @@ -23,7 +23,7 @@ public async Task AuthorizeOnExtension() QueryRequestBuilder .New() .SetQuery("{ bar }") - .AddGlobalState(nameof(ClaimsPrincipal), new ClaimsPrincipal()) + .SetUser(new ClaimsPrincipal()) .Create()); result.MatchSnapshot(); diff --git a/src/HotChocolate/Core/src/Abstractions/Execution/QueryRequestBuilderExtensions.cs b/src/HotChocolate/Core/src/Abstractions/Execution/QueryRequestBuilderExtensions.cs index f284f18b749..789e50eeb38 100644 --- a/src/HotChocolate/Core/src/Abstractions/Execution/QueryRequestBuilderExtensions.cs +++ b/src/HotChocolate/Core/src/Abstractions/Execution/QueryRequestBuilderExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Security.Claims; namespace HotChocolate.Execution; @@ -84,6 +85,14 @@ public static IQueryRequestBuilder SetMaximumAllowedExecutionDepth( int maximumAllowedDepth) => builder.SetGlobalState(WellKnownContextData.MaxAllowedExecutionDepth, maximumAllowedDepth); + /// + /// Sets the user for this request. + /// + public static IQueryRequestBuilder SetUser( + this IQueryRequestBuilder builder, + ClaimsPrincipal claimsPrincipal) => + builder.SetGlobalState(nameof(ClaimsPrincipal), claimsPrincipal); + /// /// Registers a cleanup task for execution resources with the . /// diff --git a/src/HotChocolate/Core/test/Authorization.Tests/AnnotationBasedAuthorizationTests.cs b/src/HotChocolate/Core/test/Authorization.Tests/AnnotationBasedAuthorizationTests.cs index bbcaf0b4340..f1c494e0e25 100644 --- a/src/HotChocolate/Core/test/Authorization.Tests/AnnotationBasedAuthorizationTests.cs +++ b/src/HotChocolate/Core/test/Authorization.Tests/AnnotationBasedAuthorizationTests.cs @@ -650,7 +650,7 @@ public async Task Assert_UserState_Exists() } } """) - .SetGlobalState(nameof(ClaimsPrincipal), new ClaimsPrincipal())); + .SetUser(new ClaimsPrincipal())); // assert Snapshot diff --git a/src/HotChocolate/Core/test/Types.Tests/ResolverContextStateExtensionTests.cs b/src/HotChocolate/Core/test/Types.Tests/ResolverContextStateExtensionTests.cs index eed07788cb8..ef2e375f819 100644 --- a/src/HotChocolate/Core/test/Types.Tests/ResolverContextStateExtensionTests.cs +++ b/src/HotChocolate/Core/test/Types.Tests/ResolverContextStateExtensionTests.cs @@ -39,7 +39,7 @@ public async Task GetUserClaims() .ExecuteRequestAsync( QueryRequestBuilder.New() .SetQuery("{ foo }") - .SetGlobalState(nameof(ClaimsPrincipal), user) + .SetUser(user) .Create()) .MatchSnapshotAsync(); }