< Summary

Line coverage
92%
Covered lines: 108
Uncovered lines: 9
Coverable lines: 117
Total lines: 267
Line coverage: 92.3%
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_UpdateTagAsync_input()100%11100%
File 1: UpdateTagAsync()100%11100%
File 1: UpdateTagAsync()100%210%
File 2: UpdateTagAsync()100%11100%

File(s)

/home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/obj/Debug/net10.0/generated/HotChocolate.Types.Analyzers/HotChocolate.Types.Analyzers.GraphQLServerGenerator/UpdateTagMutations.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 UpdateTagMutations
 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.UpdateTagMutations);
 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.UpdateTagMutations),
 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("UpdateTag", 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.UpdateTagPayload), HotChocolate.Type
 146                        new global::HotChocolate.Language.NonNullTypeNode(new global::HotChocolate.Language.NamedTypeNod
 147                    configuration.ResultType = typeof(global::Api.Works.Mutations.UpdateTagPayload);
 148                    configuration.DeclaringType = context.ThisType;
 149
 150                    configuration.SetSourceGeneratorFlags();
 151
 152                    var bindingInfo = field.Context.ParameterBindingResolver;
 153                    var parameter = context.Resolvers.CreateParameterDescriptor_UpdateTagAsync_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.UpdateTagInput), HotChocolat
 163                                new global::HotChocolate.Language.NonNullTypeNode(new global::HotChocolate.Language.Name
 164                            RuntimeType = typeof(global::Api.Works.Mutations.UpdateTagInput)
 165                        };
 166
 167                        configuration.Arguments.Add(argumentConfiguration);
 168                    }
 169
 170                    configuration.Member = context.ThisType.GetMethod(
 171                        "UpdateTagAsync",
 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.UpdateTagInput>),
 178                            typeof(global::Api.Works.Mutations.UpdateTagInput),
 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_UpdateTagAsync_input(),
 192                        fieldDescriptor);
 193
 194                    configuration.ConfigurationsAreApplied = true;
 195                    fieldDescriptor.CreateConfiguration();
 196
 197                    configuration.Resolvers = context.Resolvers.UpdateTagAsync();
 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_UpdateTagAsync_input;
 109
 1110            public __Resolvers(global::HotChocolate.Resolvers.ParameterBindingResolver bindingResolver)
 1111            {
 1112                _binding_UpdateTagAsync_input = bindingResolver.GetBinding(CreateParameterDescriptor_UpdateTagAsync_inpu
 1113            }
 114
 115            public global::HotChocolate.Internal.ParameterDescriptor CreateParameterDescriptor_UpdateTagAsync_input()
 1116                => new HotChocolate.Internal.ParameterDescriptor(
 1117                    "input",
 1118                    typeof(global::Api.Works.Mutations.UpdateTagInput),
 1119                    isNullable: false,
 1120                    []);
 121
 122            public HotChocolate.Resolvers.FieldResolverDelegates UpdateTagAsync()
 1123                => new global::HotChocolate.Resolvers.FieldResolverDelegates(resolver: UpdateTagAsync);
 124
 125            private async global::System.Threading.Tasks.ValueTask<global::System.Object?> UpdateTagAsync(global::HotCho
 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.UpdateTagInp
 0130                var args3 = _binding_UpdateTagAsync_input.Execute<global::Api.Works.Mutations.UpdateTagInput>(context);
 0131                var args4 = context.RequestAborted;
 0132                var result = await global::Api.Works.Mutations.UpdateTagMutations.UpdateTagAsync(args0, args1, args2, ar
 0133                return result;
 0134            }
 135        }
 136    }
 137}
 138

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

#LineLine coverage
 1// SPDX-FileCopyrightText: 2026 Alper Çelik <[email protected]>
 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.Models;
 13using Api.Works.Queries;
 14using FluentValidation;
 15using Microsoft.EntityFrameworkCore;
 16using NodaTime;
 17using Npgsql;
 18
 19namespace Api.Works.Mutations;
 20
 21[MutationType]
 22public static partial class UpdateTagMutations
 23{
 24    [PermissionCheckAuthorize(UserPermissionBits.TagRead | UserPermissionBits.TagWrite)]
 25    [Error(typeof(DomainError))]
 26    public static async Task<UpdateTagPayload> UpdateTagAsync(
 27        [Service] PGContext db,
 28        [Service] IEFTransactionDIAccessorService txGetter,
 29        [Service] IValidator<UpdateTagInput> validator,
 30        UpdateTagInput input,
 31        CancellationToken ct
 32    )
 133    {
 134        await validator.ValidateOrThrowInputAsync(input, ct);
 35
 136        var tx = await txGetter.BeginOrGetTransactionAsync();
 137        var tag = await db.WorkTags.SingleAsync(
 138            t => t.Id == input.Id,
 139            cancellationToken: ct
 140        );
 41
 142        UpdateTagInput.ApplyToTag(tag, input);
 143        tag.RowVersion += 1;
 144        tag.MetadataUpdatedAt = Now();
 45
 146        await db.SaveChangesOrThrowAsync(
 147            PostgresErrorCodes.UniqueViolation,
 148            ErrorCodes.TAG_ALREADY_EXISTS,
 149            "A tag with the same namespace and name already exists",
 150            ct
 151        );
 52
 153        await tx.CommitAsync(ct);
 154        return new UpdateTagPayload(TagMapper.ToDto(tag));
 155    }
 56}
 57
 58public record UpdateTagPayload(Queries.Tag Tag);
 59
 60public record UpdateTagInput : IBasicEntityMetadata
 61{
 62    public static byte IdPostfix => Models.WorkTag.IdPostfix;
 63
 64    public Guid Id { get; init; }
 65    public int RowVersion { get; init; }
 66
 67    public required Optional<string[]> TagNamespace { get; init; }
 68    public required Optional<string> TagName { get; init; }
 69
 70    public class UpdateTagInputValidator : AbstractValidator<UpdateTagInput>
 71    {
 72        public UpdateTagInputValidator(
 73            PGContext db,
 74            ICurrentUserId userId,
 75            IEFTransactionDIAccessorService tx
 76        )
 77        {
 78            RuleFor(w => w).BeginTransaction(tx);
 79
 80            RuleFor(w => w.Id).IdMustExist(db.WorkTags, userId.Id);
 81
 82            RuleFor(w => w.RowVersion).RowVersionMustMatch(db.WorkTags);
 83
 84            RuleFor(w => w)
 85                .MustAsync(
 86                    async (input, ct) =>
 87                    {
 88                        var existing = await db
 89                            .WorkTags.Where(t =>
 90                                t.OwnerId == userId.Id && t.Id == input.Id
 91                            )
 92                            .Select(t => new { t.TagNamespace, t.TagName })
 93                            .FirstOrDefaultAsync(ct);
 94
 95                        if (existing is null)
 96                            return true;
 97
 98                        var tagNamespace = input.TagNamespace.HasValue
 99                            ? input.TagNamespace.Value ?? []
 100                            : existing.TagNamespace;
 101                        var tagName = input.TagName.HasValue
 102                            ? input.TagName.Value
 103                            : existing.TagName;
 104
 105                        return !await db.WorkTags.AnyAsync(
 106                            other =>
 107                                other.OwnerId == userId.Id
 108                                && other.Id != input.Id
 109                                && other.TagNamespace == tagNamespace
 110                                && other.TagName == tagName,
 111                            ct
 112                        );
 113                    }
 114                )
 115                .WithMessage("A tag with the same namespace and name already exists")
 116                .WithErrorCode(ErrorCodes.TAG_ALREADY_EXISTS);
 117        }
 118    }
 119
 120    public static void ApplyToTag(Models.WorkTag tag, UpdateTagInput input)
 121    {
 122        if (input.TagNamespace.HasValue)
 123            tag.TagNamespace = input.TagNamespace.Value ?? [];
 124
 125        if (input.TagName.HasValue)
 126            tag.TagName = input.TagName.Value;
 127    }
 128}
 129// Mostly Ai Generated - End