Fix UpdatedUserTransformer not using projections

This commit is contained in:
Jordan Dominion
2025-08-16 13:43:42 -04:00
parent a5c3d64fe3
commit 43455a123e
2 changed files with 11 additions and 30 deletions
@@ -11,9 +11,14 @@ namespace Tgstation.Server.Host.GraphQL.Transformers
/// Initializes a new instance of the <see cref="UpdatedUserTransformer"/> class.
/// </summary>
public UpdatedUserTransformer()
: base(model => model.User != null
? new UpdatedUser(model.User)
: new UpdatedUser(model.Id))
: base(
BuildSubProjection<Models.User, User, UserTransformer>(
(model, user) => new UpdatedUser
{
Id = model.Id,
User = user,
},
model => model.User))
{
}
}
@@ -1,9 +1,4 @@
using System;
using HotChocolate.Types.Relay;
using Tgstation.Server.Host.GraphQL.Transformers;
using Tgstation.Server.Host.Models;
using HotChocolate.Types.Relay;
namespace Tgstation.Server.Host.GraphQL.Types
{
@@ -16,30 +11,11 @@ namespace Tgstation.Server.Host.GraphQL.Types
/// The <see cref="User"/>'s <see cref="Entity.Id"/>.
/// </summary>
[ID(nameof(Types.User))]
public long Id { get; }
public required long Id { get; init; }
/// <summary>
/// The <see cref="Types.User"/>, if was authorized to be read.
/// </summary>
public User? User { get; }
/// <summary>
/// Initializes a new instance of the <see cref="UpdatedUser"/> class.
/// </summary>
/// <param name="user">The value of <see cref="User"/> containing the <see cref="Id"/>.</param>
public UpdatedUser(Models.User user)
: this((user ?? throw new ArgumentNullException(nameof(user))).Require(u => u.Id))
{
User = ((IApiTransformable<Models.User, User, UserTransformer>)user).ToApi();
}
/// <summary>
/// Initializes a new instance of the <see cref="UpdatedUser"/> class.
/// </summary>
/// <param name="id">The value of <see cref="Id"/>.</param>
public UpdatedUser(long id)
{
Id = id;
}
public required User? User { get; set; }
}
}