Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SetUser extension to IQueryRequestBuilder #6093

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task AuthorizeOnExtension()
QueryRequestBuilder
.New()
.SetQuery("{ bar }")
.AddGlobalState(nameof(ClaimsPrincipal), new ClaimsPrincipal())
.SetUser(new ClaimsPrincipal())
.Create());

result.MatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Security.Claims;

namespace HotChocolate.Execution;

Expand Down Expand Up @@ -84,6 +85,14 @@ public static IQueryRequestBuilder SetMaximumAllowedExecutionDepth(
int maximumAllowedDepth) =>
builder.SetGlobalState(WellKnownContextData.MaxAllowedExecutionDepth, maximumAllowedDepth);

/// <summary>
/// Sets the user for this request.
/// </summary>
public static IQueryRequestBuilder SetUser(
this IQueryRequestBuilder builder,
ClaimsPrincipal claimsPrincipal) =>
builder.SetGlobalState(nameof(ClaimsPrincipal), claimsPrincipal);

/// <summary>
/// Registers a cleanup task for execution resources with the <see cref="IQueryResultBuilder"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ public async Task Assert_UserState_Exists()
}
}
""")
.SetGlobalState(nameof(ClaimsPrincipal), new ClaimsPrincipal()));
.SetUser(new ClaimsPrincipal()));

// assert
Snapshot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task GetUserClaims()
.ExecuteRequestAsync(
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.SetGlobalState(nameof(ClaimsPrincipal), user)
.SetUser(user)
.Create())
.MatchSnapshotAsync();
}
Expand Down