< Summary

Line coverage
91%
Covered lines: 104
Uncovered lines: 10
Coverable lines: 114
Total lines: 256
Line coverage: 91.2%
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_AddTagAsync_input()100%11100%
File 1: AddTagAsync()100%11100%
File 1: AddTagAsync()100%210%
File 2: AddTagAsync()100%11100%

File(s)

/home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/obj/Debug/net10.0/generated/HotChocolate.Types.Analyzers/HotChocolate.Types.Analyzers.GraphQLServerGenerator/AddTagMutations.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 AddTagMutations
 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.AddTagMutations);
 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.AddTagMutations),
 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("AddTag", 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.AddTagPayload), HotChocolate.Types.T
 146                        new global::HotChocolate.Language.NonNullTypeNode(new global::HotChocolate.Language.NamedTypeNod
 147                    configuration.ResultType = typeof(global::Api.Works.Mutations.AddTagPayload);
 148                    configuration.DeclaringType = context.ThisType;
 149
 150                    configuration.SetSourceGeneratorFlags();
 151
 152                    var bindingInfo = field.Context.ParameterBindingResolver;
 153                    var parameter = context.Resolvers.CreateParameterDescriptor_AddTagAsync_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.AddTagInput), HotChocolate.T
 163                                new global::HotChocolate.Language.NonNullTypeNode(new global::HotChocolate.Language.Name
 164                            RuntimeType = typeof(global::Api.Works.Mutations.AddTagInput)
 165                        };
 166
 167                        configuration.Arguments.Add(argumentConfiguration);
 168                    }
 169
 170                    configuration.Member = context.ThisType.GetMethod(
 171                        "AddTagAsync",
 172                        global::HotChocolate.Utilities.ReflectionUtils.StaticMemberFlags,
 173                        new global::System.Type[]
 174                        {
 175                            typeof(global::Api.Database.PGContext),
 176                            typeof(global::Api.Auth.Utils.ICurrentUserId),
 177                            typeof(global::Api.Database.Utils.IEFTransactionDIAccessorService),
 178                            typeof(global::FluentValidation.IValidator<global::Api.Works.Mutations.AddTagInput>),
 179                            typeof(global::Api.Works.Mutations.AddTagInput),
 180                            typeof(global::System.Threading.CancellationToken)
 181                        })!;
 182
 183                    var fieldDescriptor = global::HotChocolate.Types.Descriptors.ObjectFieldDescriptor.From(field.Contex
 184                    HotChocolate.Internal.ConfigurationHelper.ApplyConfiguration(
 185                        field.Context,
 186                        fieldDescriptor,
 187                        configuration.Member,
 188                        new global::Api.Auth.Handlers.PermissionCheckAuthorizeAttribute(global::Api.Auth.Models.UserPerm
 189                        new global::HotChocolate.Types.ErrorAttribute(typeof(global::Api.Utils.DomainError)));
 190
 191                    bindingResolver.ApplyConfiguration(
 192                        context.Resolvers.CreateParameterDescriptor_AddTagAsync_input(),
 193                        fieldDescriptor);
 194
 195                    configuration.ConfigurationsAreApplied = true;
 196                    fieldDescriptor.CreateConfiguration();
 197
 198                    configuration.Resolvers = context.Resolvers.AddTagAsync();
 199                },
 1100                (Resolvers: resolvers, ThisType: thisType));
 101
 102            Configure(descriptor);
 1103        }
 104
 105        static partial void Configure(global::HotChocolate.Types.IObjectTypeDescriptor descriptor);
 106
 107        private sealed class __Resolvers
 108        {
 109            private readonly global::HotChocolate.Internal.IParameterBinding _binding_AddTagAsync_input;
 110
 1111            public __Resolvers(global::HotChocolate.Resolvers.ParameterBindingResolver bindingResolver)
 1112            {
 1113                _binding_AddTagAsync_input = bindingResolver.GetBinding(CreateParameterDescriptor_AddTagAsync_input());
 1114            }
 115
 116            public global::HotChocolate.Internal.ParameterDescriptor CreateParameterDescriptor_AddTagAsync_input()
 1117                => new HotChocolate.Internal.ParameterDescriptor(
 1118                    "input",
 1119                    typeof(global::Api.Works.Mutations.AddTagInput),
 1120                    isNullable: false,
 1121                    []);
 122
 123            public HotChocolate.Resolvers.FieldResolverDelegates AddTagAsync()
 1124                => new global::HotChocolate.Resolvers.FieldResolverDelegates(resolver: AddTagAsync);
 125
 126            private async global::System.Threading.Tasks.ValueTask<global::System.Object?> AddTagAsync(global::HotChocol
 0127            {
 0128                var args0 = context.Service<global::Api.Database.PGContext>();
 0129                var args1 = context.Service<global::Api.Auth.Utils.ICurrentUserId>();
 0130                var args2 = context.Service<global::Api.Database.Utils.IEFTransactionDIAccessorService>();
 0131                var args3 = context.Service<global::FluentValidation.IValidator<global::Api.Works.Mutations.AddTagInput>
 0132                var args4 = _binding_AddTagAsync_input.Execute<global::Api.Works.Mutations.AddTagInput>(context);
 0133                var args5 = context.RequestAborted;
 0134                var result = await global::Api.Works.Mutations.AddTagMutations.AddTagAsync(args0, args1, args2, args3, a
 0135                return result;
 0136            }
 137        }
 138    }
 139}
 140

/home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/Works/Mutations/AddTagMutation.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.Queries;
 13using FluentValidation;
 14using Microsoft.EntityFrameworkCore;
 15using NodaTime;
 16using Npgsql;
 17using Riok.Mapperly.Abstractions;
 18
 19namespace Api.Works.Mutations;
 20
 21[MutationType]
 22public static partial class AddTagMutations
 23{
 24    [PermissionCheckAuthorize(UserPermissionBits.TagWrite)]
 25    [Error(typeof(DomainError))]
 26    public static async Task<AddTagPayload> AddTagAsync(
 27        [Service] PGContext db,
 28        [Service] ICurrentUserId userId,
 29        [Service] IEFTransactionDIAccessorService txGetter,
 30        [Service] IValidator<AddTagInput> validator,
 31        AddTagInput input,
 32        CancellationToken ct
 33    )
 134    {
 135        await validator.ValidateOrThrowInputAsync(input, ct);
 36
 137        var tx = await txGetter.BeginOrGetTransactionAsync();
 38
 139        var tag = AddTagInputMapper.CreateFromDto(input, userId.Id!.Value, Now());
 40
 141        await db.AddAsync(tag, cancellationToken: ct);
 142        await db.SaveChangesOrThrowAsync(
 143            PostgresErrorCodes.UniqueViolation,
 144            ErrorCodes.TAG_ALREADY_EXISTS,
 145            "A tag with the same namespace and name already exists",
 146            ct
 147        );
 48
 149        await tx.CommitAsync(ct);
 150        return new AddTagPayload(TagMapper.ToDto(tag));
 151    }
 52}
 53
 54public record AddTagPayload(Queries.Tag Tag);
 55
 56public record AddTagInput
 57{
 58    public required string[] TagNamespace { get; init; }
 59
 60    public required string TagName { get; init; }
 61
 62    public class AddTagInputValidator : AbstractValidator<AddTagInput>
 63    {
 64        public AddTagInputValidator(
 65            PGContext db,
 66            ICurrentUserId userId,
 67            IEFTransactionDIAccessorService tx
 68        )
 69        {
 70            RuleFor(t => t).BeginTransaction(tx);
 71
 72            RuleFor(t => t)
 73                .MustAsync(
 74                    async (input, ct) =>
 75                        !await db.WorkTags.AnyAsync(
 76                            existing =>
 77                                existing.OwnerId == userId.Id
 78                                && existing.TagNamespace == input.TagNamespace
 79                                && existing.TagName == input.TagName,
 80                            ct
 81                        )
 82                )
 83                .WithMessage("A tag with the same namespace and name already exists")
 84                .WithErrorCode(ErrorCodes.TAG_ALREADY_EXISTS);
 85        }
 86    }
 87}
 88
 89[Mapper]
 90public static partial class AddTagInputMapper
 91{
 92    [MapperIgnoreTarget(nameof(Models.WorkTag.RowVersion))]
 93    [MapperIgnoreTarget(nameof(Models.WorkTag.WorkTagWorks))]
 94    [MapperIgnoreTarget(nameof(Models.WorkTag.Works))]
 95    [MapperIgnoreTarget(nameof(Models.WorkTag.Owner))]
 96    private static partial Models.WorkTag CreateFromDtoInternal(
 97        AddTagInput w,
 98        Guid id,
 99        Instant metadataAddedAt,
 100        Instant metadataUpdatedAt
 101    );
 102
 103    public static Models.WorkTag CreateFromDto(AddTagInput w, Guid ownerId, Instant now)
 104    {
 105        var id = Guid.CreateVersion7().WithPostfix(Models.WorkTag.IdPostfix);
 106        var tag = CreateFromDtoInternal(w, id, now, now);
 107        tag.OwnerId = ownerId;
 108
 109        return tag;
 110    }
 111
 112    [UserMapping(Default = true)]
 113    public static ZonedDateTime FromInstantToZonedDateTime(Instant i) =>
 114        MapperUtils.FromInstantToZonedDateTime(i);
 115}
 116// Mostly Ai Generated - End