mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-22 04:27:19 +01:00
Fix build warnings
This commit is contained in:
@@ -85,6 +85,23 @@ namespace Tgstation.Server.Host.Authority.Core
|
||||
return CreateSuccessfulActionResult(controller, result, authorityResponse);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask<TApiModel?> InvokeTransformable<TResult, TApiModel, TTransformer>(Func<TAuthority, ValueTask<AuthorityResponse<TResult>>> authorityInvoker)
|
||||
where TResult : notnull, IApiTransformable<TResult, TApiModel, TTransformer>
|
||||
where TApiModel : notnull
|
||||
where TTransformer : ITransformer<TResult, TApiModel>, new()
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(authorityInvoker);
|
||||
|
||||
var authorityResponse = await authorityInvoker(authority);
|
||||
ThrowGraphQLErrorIfNecessary(authorityResponse);
|
||||
var result = authorityResponse.Result;
|
||||
if (result == null)
|
||||
return default;
|
||||
|
||||
return result.ToApi();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
async ValueTask IGraphQLAuthorityInvoker<TAuthority>.Invoke(Func<TAuthority, ValueTask<AuthorityResponse>> authorityInvoker)
|
||||
{
|
||||
@@ -95,7 +112,7 @@ namespace Tgstation.Server.Host.Authority.Core
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask<TApiModel> Invoke<TResult, TApiModel>(Func<TAuthority, ValueTask<AuthorityResponse<TResult>>> authorityInvoker)
|
||||
public async ValueTask<TApiModel?> Invoke<TResult, TApiModel>(Func<TAuthority, ValueTask<AuthorityResponse<TResult>>> authorityInvoker)
|
||||
where TResult : TApiModel
|
||||
where TApiModel : notnull
|
||||
{
|
||||
@@ -103,17 +120,7 @@ namespace Tgstation.Server.Host.Authority.Core
|
||||
|
||||
var authorityResponse = await authorityInvoker(authority);
|
||||
ThrowGraphQLErrorIfNecessary(authorityResponse);
|
||||
return authorityResponse.Result!;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
async ValueTask<TApiModel> IGraphQLAuthorityInvoker<TAuthority>.InvokeTransformable<TResult, TApiModel, TTransformer>(Func<TAuthority, ValueTask<AuthorityResponse<TResult>>> authorityInvoker)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(authorityInvoker);
|
||||
|
||||
var authorityResponse = await authorityInvoker(authority);
|
||||
ThrowGraphQLErrorIfNecessary(authorityResponse);
|
||||
return authorityResponse.Result!.ToApi();
|
||||
return authorityResponse.Result;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Tgstation.Server.Host.Authority.Core
|
||||
/// <typeparam name="TApiModel">The resulting <see cref="Type"/> of the return value.</typeparam>
|
||||
/// <param name="authorityInvoker">The <typeparamref name="TAuthority"/> <see cref="Func{T, TResult}"/> returning a <see cref="ValueTask{TResult}"/> resulting in the <see cref="AuthorityResponse{TResult}"/>.</param>
|
||||
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <typeparamref name="TApiModel"/> generated for the resulting <see cref="AuthorityResponse{TResult}"/>.</returns>
|
||||
ValueTask<TApiModel> Invoke<TResult, TApiModel>(Func<TAuthority, ValueTask<AuthorityResponse<TResult>>> authorityInvoker)
|
||||
ValueTask<TApiModel?> Invoke<TResult, TApiModel>(Func<TAuthority, ValueTask<AuthorityResponse<TResult>>> authorityInvoker)
|
||||
where TResult : TApiModel
|
||||
where TApiModel : notnull;
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Tgstation.Server.Host.Authority.Core
|
||||
/// <typeparam name="TTransformer">The <see cref="ITransformer{TInput, TOutput}"/> for converting <typeparamref name="TResult"/>s to <typeparamref name="TApiModel"/>s.</typeparam>
|
||||
/// <param name="authorityInvoker">The <typeparamref name="TAuthority"/> <see cref="Func{T, TResult}"/> returning a <see cref="ValueTask{TResult}"/> resulting in the <see cref="AuthorityResponse{TResult}"/>.</param>
|
||||
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <typeparamref name="TApiModel"/> generated for the resulting <see cref="AuthorityResponse{TResult}"/>.</returns>
|
||||
ValueTask<TApiModel> InvokeTransformable<TResult, TApiModel, TTransformer>(Func<TAuthority, ValueTask<AuthorityResponse<TResult>>> authorityInvoker)
|
||||
ValueTask<TApiModel?> InvokeTransformable<TResult, TApiModel, TTransformer>(Func<TAuthority, ValueTask<AuthorityResponse<TResult>>> authorityInvoker)
|
||||
where TResult : notnull, IApiTransformable<TResult, TApiModel, TTransformer>
|
||||
where TApiModel : notnull
|
||||
where TTransformer : ITransformer<TResult, TApiModel>, new();
|
||||
|
||||
@@ -14,6 +14,12 @@ namespace Tgstation.Server.Host.GraphQL.Types
|
||||
[Node]
|
||||
public sealed class NodeInformation
|
||||
{
|
||||
/// <summary>
|
||||
/// Node resolver for <see cref="NodeInformation"/>s.
|
||||
/// </summary>
|
||||
/// <param name="identifier">The <see cref="Identifier"/> to lookup.</param>
|
||||
/// <param name="swarmService">The <see cref="ISwarmService"/> to use.</param>
|
||||
/// <returns>The queried <see cref="NodeInformation"/>, if present.</returns>
|
||||
public NodeInformation? GetNodeInformation(
|
||||
string identifier,
|
||||
[Service] ISwarmService swarmService)
|
||||
|
||||
@@ -51,13 +51,20 @@ namespace Tgstation.Server.Host.GraphQL.Types
|
||||
[GraphQLIgnore]
|
||||
public required long? GroupId { get; init; }
|
||||
|
||||
public static ValueTask<User> GetUser(
|
||||
/// <summary>
|
||||
/// Node resolver for <see cref="User"/>s.
|
||||
/// </summary>
|
||||
/// <param name="id">The <see cref="Entity.Id"/> to lookup.</param>
|
||||
/// <param name="userAuthority">The <see cref="IGraphQLAuthorityInvoker{TAuthority}"/> <see cref="IUserAuthority"/>.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="ValueTask"/> resulting in the queried <see cref="User"/>, if present.</returns>
|
||||
public static ValueTask<User?> GetUser(
|
||||
long id,
|
||||
[Service] IGraphQLAuthorityInvoker<IUserAuthority> authorityInvoker,
|
||||
[Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(authorityInvoker);
|
||||
return authorityInvoker.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
|
||||
ArgumentNullException.ThrowIfNull(userAuthority);
|
||||
return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
|
||||
authority => authority.GetId(id, false, false, cancellationToken));
|
||||
}
|
||||
|
||||
@@ -76,6 +83,9 @@ namespace Tgstation.Server.Host.GraphQL.Types
|
||||
return null;
|
||||
|
||||
var user = await userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(authority => authority.GetId(CreatedById.Value, false, true, cancellationToken));
|
||||
if (user == null)
|
||||
return null;
|
||||
|
||||
if (user.CanonicalName == Models.User.CanonicalizeName(Models.User.TgsSystemUserName))
|
||||
return new UserName(user);
|
||||
|
||||
|
||||
@@ -19,15 +19,25 @@ namespace Tgstation.Server.Host.GraphQL.Types
|
||||
[Node]
|
||||
public sealed class UserName : NamedEntity, IUserName
|
||||
{
|
||||
public static async ValueTask<UserName> GetUserName(
|
||||
/// <summary>
|
||||
/// Node resolver for <see cref="UserName"/>s.
|
||||
/// </summary>
|
||||
/// <param name="id">The <see cref="Entity.Id"/> to lookup.</param>
|
||||
/// <param name="userAuthority">The <see cref="IGraphQLAuthorityInvoker{TAuthority}"/> <see cref="IUserAuthority"/>.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="ValueTask"/> resulting in the queried <see cref="UserName"/>, if present.</returns>
|
||||
public static async ValueTask<UserName?> GetUserName(
|
||||
long id,
|
||||
[Service] IGraphQLAuthorityInvoker<IUserAuthority> authorityInvoker,
|
||||
[Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(authorityInvoker);
|
||||
var user = await authorityInvoker.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
|
||||
ArgumentNullException.ThrowIfNull(userAuthority);
|
||||
var user = await userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
|
||||
authority => authority.GetId(id, false, true, cancellationToken));
|
||||
|
||||
if (user == null)
|
||||
return null;
|
||||
|
||||
return new UserName(user);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Tgstation.Server.Host.GraphQL.Types
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(userAuthority);
|
||||
return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(authority => authority.Read(cancellationToken));
|
||||
return userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(authority => authority.Read(cancellationToken))!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Tgstation.Server.Host.Models
|
||||
/// <typeparam name="TApiModel">The API model <see cref="Type"/>.</typeparam>
|
||||
/// <typeparam name="TTransformer">The <see cref="ITransformer{TModel, TApiModel}"/> <see cref="Type"/>.</typeparam>
|
||||
public interface IApiTransformable<TModel, TApiModel, TTransformer>
|
||||
where TApiModel : notnull
|
||||
where TModel : IApiTransformable<TModel, TApiModel, TTransformer>
|
||||
where TTransformer : ITransformer<TModel, TApiModel>, new()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user