How can I alter / mock IResolverContext in a unit test? #4711
-
I'm using hot chocolate for my GraphQL APIs and am wondering how I go about altering the I start by creating a service collection containing the GraphQL setup. services
.AddGraphQLServer()
.AddAuthorization()
.AddQueryType<Query>()
.AddMutationType<Mutation>()
.AddTypes(types)
.AddFiltering()
.AddSorting()
.AddMaxExecutionDepthRule(20)
.AddType(new UuidType('N')); I then get the request executor var requestExecutor = await ServiceProvider.GetRequiredService<IRequestExecutorResolver>().GetRequestExecutorAsync(); Followed by executing the test using a Graph QL file. var request = CreateQueryRequest("GetApplicationPermissionsAsync_Success.graphql");
var result = await requestExecutor.ExecuteAsync(request); What I'm trying to achieve is a way of altering / mocking the request context so I can have unit tests that verify my authorization policies, I'm using NUnit and Moq with Hot Chocolate 12.6.0. Thank you for taking the time to take a look, really appreciate it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
So in the case of auth, you can just pass in with your request a claims principal that is configured to your auth requirements. In order to do that you the QueryRequestBuilder and add a property with the key nameof(ClaimsPrincipal) and as the value the ClaimsPrincipal |
Beta Was this translation helpful? Give feedback.
So in the case of auth, you can just pass in with your request a claims principal that is configured to your auth requirements.
In order to do that you the QueryRequestBuilder and add a property with the key nameof(ClaimsPrincipal) and as the value the ClaimsPrincipal