< Summary

Line coverage
92%
Covered lines: 144
Uncovered lines: 11
Coverable lines: 155
Total lines: 239
Line coverage: 92.9%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/Files/Mutations/AddFileRecordWithFileMutation.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.Utils;
 10using Api.Files.FileProviders;
 11using Api.Files.Queries;
 12using Api.Utils;
 13using FluentValidation;
 14using HotChocolate.Types;
 15
 16namespace Api.Files.Mutations;
 17
 18[MutationType]
 19public static partial class AddFileRecordWithFileMutations
 20{
 21    [PermissionCheckAuthorize(UserPermissionBits.FileWrite)]
 22    [Error(typeof(DomainError))]
 23    // The input type is shared with `addFileRecord`, so it cannot follow the derived name.
 24    [UseMutationConvention(InputTypeName = "AddFileRecordInput")]
 25    public static async Task<AddFileRecordWithFilePayload> AddFileRecordWithFileAsync(
 26        [Service] ICurrentUserId userId,
 27        [Service] IEFTransactionDIAccessorService txGetter,
 28        [Service] UserFileRouter router,
 29        [Service] IValidator<AddFileRecordInput> validator,
 30        AddFileRecordInput input,
 31        IFile file,
 32        CancellationToken ct
 33    )
 134    {
 135        await validator.ValidateOrThrowInputAsync(input, ct);
 36
 137        var tx = await txGetter.BeginOrGetTransactionAsync(ct);
 138        var ownerId = userId.Id!.Value;
 39
 140        var fileRecord = await router.CreateFileAsync(
 141            ownerId,
 142            input.FileKind,
 143            input.ContentType,
 144            input.OriginalFileName,
 145            input.SizeBytes,
 146            Convert.FromHexString(input.Sha256),
 147            ct
 148        );
 49
 150        if (
 151            await router.SetFileAsync(ownerId, fileRecord.Id, file.OpenReadStream(), ct)
 152            is null
 153        )
 154        {
 155            throw new DomainException(
 156                ErrorCodes.FILE_UPLOAD_FAILED,
 157                "File content did not match the declared size or SHA256"
 158            );
 59        }
 60
 161        await tx.CommitAsync(ct);
 162        return new AddFileRecordWithFilePayload(FileRecordMapper.ToDto(fileRecord));
 163    }
 64}
 65
 66public record AddFileRecordWithFilePayload(Queries.FileRecord FileRecord);
 67// Mostly Ai Generated - End

/home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/obj/Debug/net10.0/generated/HotChocolate.Types.Analyzers/HotChocolate.Types.Analyzers.GraphQLServerGenerator/AddFileRecordWithFileMutations.MuAeZK5uwlVFtMhs568cXw.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.Files.Mutations
 15{
 16    public static partial class AddFileRecordWithFileMutations
 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.Files.Mutations.AddFileRecordWithFileMutations);
 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.Files.Mutations.AddFileRecordWithFileMutations),
 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("AddFileRecordWithFile", 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.Files.Mutations.AddFileRecordWithFilePayload), HotCh
 146                        new global::HotChocolate.Language.NonNullTypeNode(new global::HotChocolate.Language.NamedTypeNod
 147                    configuration.ResultType = typeof(global::Api.Files.Mutations.AddFileRecordWithFilePayload);
 148                    configuration.DeclaringType = context.ThisType;
 149
 150                    configuration.SetSourceGeneratorFlags();
 151
 152                    var bindingInfo = field.Context.ParameterBindingResolver;
 153                    var parameter = context.Resolvers.CreateParameterDescriptor_AddFileRecordWithFileAsync_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.Files.Mutations.AddFileRecordInput), HotChoc
 163                                new global::HotChocolate.Language.NonNullTypeNode(new global::HotChocolate.Language.Name
 164                            RuntimeType = typeof(global::Api.Files.Mutations.AddFileRecordInput)
 165                        };
 166
 167                        configuration.Arguments.Add(argumentConfiguration);
 168                    }
 169
 170                    parameter = context.Resolvers.CreateParameterDescriptor_AddFileRecordWithFileAsync_file();
 171                    parameterInfo = bindingInfo.GetBindingInfo(parameter);
 172
 173                    if(parameterInfo.Kind is global::HotChocolate.Internal.ArgumentKind.Argument)
 174                    {
 175                        var argumentConfiguration = new global::HotChocolate.Types.Descriptors.Configurations.ArgumentCo
 176                        {
 177                            Name = naming.GetMemberName("file", global::HotChocolate.Types.MemberKind.Argument),
 178                            Type = global::HotChocolate.Types.Descriptors.TypeReference.Create(
 179                                typeInspector.GetTypeRef(typeof(global::HotChocolate.Types.IFile), HotChocolate.Types.Ty
 180                                new global::HotChocolate.Language.NonNullTypeNode(new global::HotChocolate.Language.Name
 181                            RuntimeType = typeof(global::HotChocolate.Types.IFile)
 182                        };
 183
 184                        configuration.Arguments.Add(argumentConfiguration);
 185                    }
 186
 187                    configuration.Member = context.ThisType.GetMethod(
 188                        "AddFileRecordWithFileAsync",
 189                        global::HotChocolate.Utilities.ReflectionUtils.StaticMemberFlags,
 190                        new global::System.Type[]
 191                        {
 192                            typeof(global::Api.Auth.Utils.ICurrentUserId),
 193                            typeof(global::Api.Database.Utils.IEFTransactionDIAccessorService),
 194                            typeof(global::Api.Files.FileProviders.UserFileRouter),
 195                            typeof(global::FluentValidation.IValidator<global::Api.Files.Mutations.AddFileRecordInput>),
 196                            typeof(global::Api.Files.Mutations.AddFileRecordInput),
 197                            typeof(global::HotChocolate.Types.IFile),
 198                            typeof(global::System.Threading.CancellationToken)
 199                        })!;
 1100
 1101                    var fieldDescriptor = global::HotChocolate.Types.Descriptors.ObjectFieldDescriptor.From(field.Contex
 1102                    HotChocolate.Internal.ConfigurationHelper.ApplyConfiguration(
 1103                        field.Context,
 1104                        fieldDescriptor,
 1105                        configuration.Member,
 1106                        new global::Api.Auth.Handlers.PermissionCheckAuthorizeAttribute(global::Api.Auth.Models.UserPerm
 1107                        new global::HotChocolate.Types.ErrorAttribute(typeof(global::Api.Utils.DomainError)),
 1108                        new global::HotChocolate.Types.UseMutationConventionAttribute() { InputTypeName = "AddFileRecord
 1109
 1110                    bindingResolver.ApplyConfiguration(
 1111                        context.Resolvers.CreateParameterDescriptor_AddFileRecordWithFileAsync_input(),
 1112                        fieldDescriptor);
 1113
 1114                    bindingResolver.ApplyConfiguration(
 1115                        context.Resolvers.CreateParameterDescriptor_AddFileRecordWithFileAsync_file(),
 1116                        fieldDescriptor);
 1117
 1118                    configuration.ConfigurationsAreApplied = true;
 1119                    fieldDescriptor.CreateConfiguration();
 1120
 1121                    configuration.Resolvers = context.Resolvers.AddFileRecordWithFileAsync();
 1122                },
 1123                (Resolvers: resolvers, ThisType: thisType));
 124
 125            Configure(descriptor);
 1126        }
 127
 128        static partial void Configure(global::HotChocolate.Types.IObjectTypeDescriptor descriptor);
 129
 130        private sealed class __Resolvers
 131        {
 132            private readonly global::HotChocolate.Internal.IParameterBinding _binding_AddFileRecordWithFileAsync_input;
 133            private readonly global::HotChocolate.Internal.IParameterBinding _binding_AddFileRecordWithFileAsync_file;
 134
 1135            public __Resolvers(global::HotChocolate.Resolvers.ParameterBindingResolver bindingResolver)
 1136            {
 1137                _binding_AddFileRecordWithFileAsync_input = bindingResolver.GetBinding(CreateParameterDescriptor_AddFile
 1138                _binding_AddFileRecordWithFileAsync_file = bindingResolver.GetBinding(CreateParameterDescriptor_AddFileR
 1139            }
 140
 141            public global::HotChocolate.Internal.ParameterDescriptor CreateParameterDescriptor_AddFileRecordWithFileAsyn
 1142                => new HotChocolate.Internal.ParameterDescriptor(
 1143                    "input",
 1144                    typeof(global::Api.Files.Mutations.AddFileRecordInput),
 1145                    isNullable: false,
 1146                    []);
 147            public global::HotChocolate.Internal.ParameterDescriptor CreateParameterDescriptor_AddFileRecordWithFileAsyn
 1148                => new HotChocolate.Internal.ParameterDescriptor(
 1149                    "file",
 1150                    typeof(global::HotChocolate.Types.IFile),
 1151                    isNullable: false,
 1152                    []);
 153
 154            public HotChocolate.Resolvers.FieldResolverDelegates AddFileRecordWithFileAsync()
 1155                => new global::HotChocolate.Resolvers.FieldResolverDelegates(resolver: AddFileRecordWithFileAsync);
 156
 157            private async global::System.Threading.Tasks.ValueTask<global::System.Object?> AddFileRecordWithFileAsync(gl
 0158            {
 0159                var args0 = context.Service<global::Api.Auth.Utils.ICurrentUserId>();
 0160                var args1 = context.Service<global::Api.Database.Utils.IEFTransactionDIAccessorService>();
 0161                var args2 = context.Service<global::Api.Files.FileProviders.UserFileRouter>();
 0162                var args3 = context.Service<global::FluentValidation.IValidator<global::Api.Files.Mutations.AddFileRecor
 0163                var args4 = _binding_AddFileRecordWithFileAsync_input.Execute<global::Api.Files.Mutations.AddFileRecordI
 0164                var args5 = _binding_AddFileRecordWithFileAsync_file.Execute<global::HotChocolate.Types.IFile>(context);
 0165                var args6 = context.RequestAborted;
 0166                var result = await global::Api.Files.Mutations.AddFileRecordWithFileMutations.AddFileRecordWithFileAsync
 0167                return result;
 0168            }
 169        }
 170    }
 171}
 172