< Summary

Line coverage
91%
Covered lines: 103
Uncovered lines: 9
Coverable lines: 112
Total lines: 235
Line coverage: 91.9%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
File 1: Initialize(...)100%22100%
File 1: .ctor(...)100%11100%
File 1: CreateParameterDescriptor_UpdateAuthorAsync_input()100%11100%
File 1: UpdateAuthorAsync()100%11100%
File 1: UpdateAuthorAsync()100%210%
File 2: UpdateAuthorAsync()100%11100%

File(s)

/home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/obj/Debug/net10.0/generated/HotChocolate.Types.Analyzers/HotChocolate.Types.Analyzers.GraphQLServerGenerator/UpdateAuthorMutations.5K_PEMQ_7wff-4-lE1HACg.hc.g.cs

#LineLine coverage
 1// <auto-generated/>
 2
 3#nullable enable
 4#pragma warning disable
 5
 6using System;
 7using System.Runtime.CompilerServices;
 8using HotChocolate;
 9using HotChocolate.Types;
 10using HotChocolate.Execution.Configuration;
 11using Microsoft.Extensions.DependencyInjection;
 12using HotChocolate.Internal;
 13
 14namespace Api.Works.Mutations
 15{
 16    public static partial class UpdateAuthorMutations
 17    {
 18        internal static void Initialize(global::HotChocolate.Types.IObjectTypeDescriptor descriptor)
 119        {
 120            var extension = descriptor.Extend();
 121            var configuration = extension.Configuration;
 122            var thisType = typeof(global::Api.Works.Mutations.UpdateAuthorMutations);
 123            var bindingResolver = extension.Context.ParameterBindingResolver;
 124            var resolvers = new __Resolvers(bindingResolver);
 25
 126            HotChocolate.Internal.ConfigurationHelper.ApplyConfiguration(
 127                extension.Context,
 128                descriptor,
 129                typeof(global::Api.Works.Mutations.UpdateAuthorMutations),
 130                new global::HotChocolate.Types.MutationTypeAttribute());
 131            configuration.ConfigurationsAreApplied = true;
 32
 133            var naming = descriptor.Extend().Context.Naming;
 34
 135            descriptor
 136                .Field(naming.GetMemberName("UpdateAuthor", global::HotChocolate.Types.MemberKind.ObjectField))
 137                .ExtendWith(static (field, context) =>
 138                {
 139                    var configuration = field.Configuration;
 140                    var typeInspector = field.Context.TypeInspector;
 141                    var bindingResolver = field.Context.ParameterBindingResolver;
 142                    var naming = field.Context.Naming;
 143
 144                    configuration.Type = global::HotChocolate.Types.Descriptors.TypeReference.Create(
 145                        typeInspector.GetTypeRef(typeof(global::Api.Works.Mutations.UpdateAuthorPayload), HotChocolate.T
 146                        new global::HotChocolate.Language.NonNullTypeNode(new global::HotChocolate.Language.NamedTypeNod
 147                    configuration.ResultType = typeof(global::Api.Works.Mutations.UpdateAuthorPayload);
 148                    configuration.DeclaringType = context.ThisType;
 149
 150                    configuration.SetSourceGeneratorFlags();
 151
 152                    var bindingInfo = field.Context.ParameterBindingResolver;
 153                    var parameter = context.Resolvers.CreateParameterDescriptor_UpdateAuthorAsync_input();
 154                    var parameterInfo = bindingInfo.GetBindingInfo(parameter);
 155
 156                    if(parameterInfo.Kind is global::HotChocolate.Internal.ArgumentKind.Argument)
 157                    {
 158                        var argumentConfiguration = new global::HotChocolate.Types.Descriptors.Configurations.ArgumentCo
 159                        {
 160                            Name = naming.GetMemberName("input", global::HotChocolate.Types.MemberKind.Argument),
 161                            Type = global::HotChocolate.Types.Descriptors.TypeReference.Create(
 162                                typeInspector.GetTypeRef(typeof(global::Api.Works.Mutations.UpdateAuthorInput), HotChoco
 163                                new global::HotChocolate.Language.NonNullTypeNode(new global::HotChocolate.Language.Name
 164                            RuntimeType = typeof(global::Api.Works.Mutations.UpdateAuthorInput)
 165                        };
 166
 167                        configuration.Arguments.Add(argumentConfiguration);
 168                    }
 169
 170                    configuration.Member = context.ThisType.GetMethod(
 171                        "UpdateAuthorAsync",
 172                        global::HotChocolate.Utilities.ReflectionUtils.StaticMemberFlags,
 173                        new global::System.Type[]
 174                        {
 175                            typeof(global::Api.Database.PGContext),
 176                            typeof(global::Api.Database.Utils.IEFTransactionDIAccessorService),
 177                            typeof(global::FluentValidation.IValidator<global::Api.Works.Mutations.UpdateAuthorInput>),
 178                            typeof(global::Api.Works.Mutations.UpdateAuthorInput),
 179                            typeof(global::System.Threading.CancellationToken)
 180                        })!;
 181
 182                    var fieldDescriptor = global::HotChocolate.Types.Descriptors.ObjectFieldDescriptor.From(field.Contex
 183                    HotChocolate.Internal.ConfigurationHelper.ApplyConfiguration(
 184                        field.Context,
 185                        fieldDescriptor,
 186                        configuration.Member,
 187                        new global::Api.Auth.Handlers.PermissionCheckAuthorizeAttribute((global::Api.Auth.Models.UserPer
 188                        new global::HotChocolate.Types.ErrorAttribute(typeof(global::Api.Utils.DomainError)));
 189
 190                    bindingResolver.ApplyConfiguration(
 191                        context.Resolvers.CreateParameterDescriptor_UpdateAuthorAsync_input(),
 192                        fieldDescriptor);
 193
 194                    configuration.ConfigurationsAreApplied = true;
 195                    fieldDescriptor.CreateConfiguration();
 196
 197                    configuration.Resolvers = context.Resolvers.UpdateAuthorAsync();
 198                },
 199                (Resolvers: resolvers, ThisType: thisType));
 100
 101            Configure(descriptor);
 1102        }
 103
 104        static partial void Configure(global::HotChocolate.Types.IObjectTypeDescriptor descriptor);
 105
 106        private sealed class __Resolvers
 107        {
 108            private readonly global::HotChocolate.Internal.IParameterBinding _binding_UpdateAuthorAsync_input;
 109
 1110            public __Resolvers(global::HotChocolate.Resolvers.ParameterBindingResolver bindingResolver)
 1111            {
 1112                _binding_UpdateAuthorAsync_input = bindingResolver.GetBinding(CreateParameterDescriptor_UpdateAuthorAsyn
 1113            }
 114
 115            public global::HotChocolate.Internal.ParameterDescriptor CreateParameterDescriptor_UpdateAuthorAsync_input()
 1116                => new HotChocolate.Internal.ParameterDescriptor(
 1117                    "input",
 1118                    typeof(global::Api.Works.Mutations.UpdateAuthorInput),
 1119                    isNullable: false,
 1120                    []);
 121
 122            public HotChocolate.Resolvers.FieldResolverDelegates UpdateAuthorAsync()
 1123                => new global::HotChocolate.Resolvers.FieldResolverDelegates(resolver: UpdateAuthorAsync);
 124
 125            private async global::System.Threading.Tasks.ValueTask<global::System.Object?> UpdateAuthorAsync(global::Hot
 0126            {
 0127                var args0 = context.Service<global::Api.Database.PGContext>();
 0128                var args1 = context.Service<global::Api.Database.Utils.IEFTransactionDIAccessorService>();
 0129                var args2 = context.Service<global::FluentValidation.IValidator<global::Api.Works.Mutations.UpdateAuthor
 0130                var args3 = _binding_UpdateAuthorAsync_input.Execute<global::Api.Works.Mutations.UpdateAuthorInput>(cont
 0131                var args4 = context.RequestAborted;
 0132                var result = await global::Api.Works.Mutations.UpdateAuthorMutations.UpdateAuthorAsync(args0, args1, arg
 0133                return result;
 0134            }
 135        }
 136    }
 137}
 138

/home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/Works/Mutations/UpdateAuthorMutation.cs

#LineLine coverage
 1// SPDX-FileCopyrightText: 2026 Alper Çelik <alper@alper-celik.dev>
 2//
 3// SPDX-License-Identifier: AGPL-3.0-or-later
 4
 5// Mostly Ai Generated - Start
 6using Api.Auth.Handlers;
 7using Api.Auth.Models;
 8using Api.Auth.Utils;
 9using Api.Database;
 10using Api.Database.Utils;
 11using Api.Utils;
 12using Api.Works.Queries;
 13using FluentValidation;
 14using Microsoft.EntityFrameworkCore;
 15
 16namespace Api.Works.Mutations;
 17
 18[MutationType]
 19public static partial class UpdateAuthorMutations
 20{
 21    [PermissionCheckAuthorize(
 22        UserPermissionBits.AuthorRead | UserPermissionBits.AuthorWrite
 23    )]
 24    [Error(typeof(DomainError))]
 25    public static async Task<UpdateAuthorPayload> UpdateAuthorAsync(
 26        [Service] PGContext db,
 27        [Service] IEFTransactionDIAccessorService txGetter,
 28        [Service] IValidator<UpdateAuthorInput> validator,
 29        UpdateAuthorInput input,
 30        CancellationToken ct
 31    )
 132    {
 133        await validator.ValidateOrThrowInputAsync(input, ct);
 34
 135        var tx = await txGetter.BeginOrGetTransactionAsync();
 136        var author = await db.Authors.SingleAsync(
 137            a => a.Id == input.Id,
 138            cancellationToken: ct
 139        );
 40
 141        UpdateAuthorInput.ApplyToAuthor(author, input);
 142        author.RowVersion += 1;
 143        author.MetadataUpdatedAt = Now();
 44
 145        await db.SaveChangesAsync(cancellationToken: ct);
 46
 147        await tx.CommitAsync(ct);
 148        return new UpdateAuthorPayload(AuthorMapper.ToDto(author));
 149    }
 50}
 51
 52public record UpdateAuthorPayload(Queries.Author Author);
 53
 54public record UpdateAuthorInput : IBasicEntityMetadata
 55{
 56    public static byte IdPostfix => Models.Author.IdPostfix;
 57
 58    public Guid Id { get; init; }
 59    public int RowVersion { get; init; }
 60
 61    public Optional<string?> FirstName { get; init; }
 62    public Optional<string?> LastName { get; init; }
 63    public required Optional<string> DisplayName { get; init; }
 64    public required Optional<List<string>?> PenNames { get; init; }
 65
 66    public class UpdateAuthorInputValidator : AbstractValidator<UpdateAuthorInput>
 67    {
 68        public UpdateAuthorInputValidator(
 69            PGContext db,
 70            ICurrentUserId userId,
 71            IEFTransactionDIAccessorService tx
 72        )
 73        {
 74            RuleFor(a => a).BeginTransaction(tx);
 75
 76            RuleFor(w => w.Id).IdMustExist(db.Authors, userId.Id);
 77
 78            RuleFor(w => w.RowVersion).RowVersionMustMatch(db.Authors);
 79        }
 80    }
 81
 82    public static void ApplyToAuthor(Models.Author author, UpdateAuthorInput input)
 83    {
 84        if (input.FirstName.HasValue)
 85            author.FirstName = input.FirstName.Value;
 86
 87        if (input.LastName.HasValue)
 88            author.LastName = input.LastName.Value;
 89
 90        if (input.DisplayName.HasValue)
 91            author.DisplayName = input.DisplayName.Value;
 92
 93        if (input.PenNames.HasValue)
 94            author.PenNames = input.PenNames.Value ?? [];
 95    }
 96}
 97// Mostly Ai Generated - End