Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed argument name with NamingConventions is not found on mutations #3088

Closed
nkovacic opened this issue Feb 20, 2021 · 4 comments
Closed
Labels
🌶️ hot chocolate 🔍 investigate Indicates that an issue or pull request needs more information. ⌛ stale Nothing happened with this issue in quite a while
Milestone

Comments

@nkovacic
Copy link

nkovacic commented Feb 20, 2021

Describe the bug
When argument name in pure code first is changed with extending DefaultNamingConventions and GetArgumentMethod, it is not found on subsequent mutation execution, it returns that the old argument name is not found on the field

To Reproduce
Steps to reproduce the behavior:

  1. Extend DefaultNamingConventions
public class ExtendedNamingConventions: DefaultNamingConventions
    {
        public override NameString GetTypeName(Type type, TypeKind kind)
        {
            if (kind == TypeKind.InputObject)
            {
                var name = CleanInputEnding(type.Name);

                return new NameString(name);
            }
            
            else if (kind == TypeKind.Object)
            {
                var name = CleanEnding(type.Name);

                return new NameString(name);
            }

            return base.GetTypeName(type, kind);
        }

        public override NameString GetArgumentName(ParameterInfo parameter)
        {
            var nameString = base.GetArgumentName(parameter);

            if (nameString == null)
            {
                return nameString;
            }

            var name = CleanInputEnding(nameString.ToString());

            return new NameString(name.ToCamelCase());
        }

        private string CleanInputEnding(string name)
        {
            name = CleanEnding(name);

            if (!name.EndsWith("input", StringComparison.OrdinalIgnoreCase))
            {
                name += "Input";
            }

            return name;
        }

        private string CleanEnding(string name)
        {
            if (name.EndsWith("command", StringComparison.OrdinalIgnoreCase))
            {
                name = name.Replace("command", "", StringComparison.OrdinalIgnoreCase);
            }

            if (name.EndsWith("viewModel", StringComparison.OrdinalIgnoreCase))
            {
                name = name.Replace("viewModel", "", StringComparison.OrdinalIgnoreCase);
            }

            return name;
        }
    }
  1. Create pure code first mutation extension
[ExtendObjectType(nameof(Mutation))]
    public class IdentityMutation
    {
        public async Task<TokenResponseViewModel> Login(
            PasswordRequestTokenCommand passwordRequestTokenCommand, [Service] IMediator mediator, CancellationToken cancellationToken)
        {
            return await mediator.Send(passwordRequestTokenCommand, cancellationToken);
        }
}
  1. Test in BCP
    image

Expected behavior
It should find the rewritten argument name which is passwordRequestTokenInput instead of passwordRequestTokenCommand

Desktop (please complete the following information):

  • OS: Windows 10
  • Version v11,0.9
@PascalSenn
Copy link
Member

Hi @nkovacic

I added a test for this in #3092
Could not reproduce this behaviour, could you provide a reproduction of this?

@PascalSenn PascalSenn added 🌶 hot chocolate 🔍 investigate Indicates that an issue or pull request needs more information. labels Feb 20, 2021
@nkovacic
Copy link
Author

@PascalSenn had a quick look at your tests, but they only test if the arguments, types are correctly renamed in the schema?
The issue arises when a mutation is called from bcp (or probably any graphql client). Schema is renamed correctly.

@tobias-tengler tobias-tengler added the ⌛ stale Nothing happened with this issue in quite a while label Nov 13, 2021
@michaelstaib michaelstaib added this to the Backlog milestone Nov 22, 2021
@stale stale bot closed this as completed May 4, 2022
@PHILLIPS71
Copy link
Contributor

PHILLIPS71 commented Nov 8, 2023

It looks as though this is still occurring in HotChocolate v13.7.0. I've setup a snake case naming convention and mutation conventions and running into it, @PascalSenn can this be re-opened?

image

image

@sergiu-enache
Copy link

sergiu-enache commented Dec 29, 2023

after upgrading to 13.8.1 only for one subgraph I get this System.NullReferenceException: 'Object reference not set to an instance of an object.' exception at startup.

I think is related to last fix for this issue, I will try to figure out what causes this only on this project (maybe some mutation input)

EDIT: weird issue with a mutation (with conventions) having a non-nullable enum as input but also with a default value (which doesn't even make sense). After removing the default value all works fine.

here is the StackTrace
at HotChocolate.Types.EnumType.ParseValue(Object runtimeValue) at HotChocolate.Types.InputFormatter.FormatValueLeaf(Object runtimeValue, ILeafType type, Path path) at HotChocolate.Types.MutationConventionTypeInterceptor.TryApplyInputConvention(IResolverCompiler resolverCompiler, ObjectFieldDefinition mutation, Options options) at HotChocolate.Types.MutationConventionTypeInterceptor.OnBeforeCompleteMutation(ITypeCompletionContext completionContext, ObjectTypeDefinition definition) at HotChocolate.Configuration.TypeInitializer.MergeTypeExtensions() at HotChocolate.Configuration.TypeInitializer.Initialize() at HotChocolate.SchemaBuilder.Setup.InitializeTypes(SchemaBuilder builder, IDescriptorContext context, IReadOnlyList1 types)
at HotChocolate.SchemaBuilder.Setup.Create(SchemaBuilder builder, LazySchema lazySchema, IDescriptorContext context)
at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaAsync(ConfigurationContext context, RequestExecutorSetup setup, RequestExecutorOptions executorOptions, IServiceProvider schemaServices, TypeModuleChangeMonitor typeModuleChangeMonitor, CancellationToken cancellationToken)
at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaServicesAsync(ConfigurationContext context, RequestExecutorSetup setup, CancellationToken cancellationToken)
at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorNoLockAsync(String schemaName, CancellationToken cancellationToken)
at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorAsync(String schemaName, CancellationToken cancellationToken)
at HotChocolate.AspNetCore.Warmup.ExecutorWarmupService.ExecuteAsync(CancellationToken stoppingToken)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at RFERL.Modules.CMSModule.API.Program.Main(String[] args) in C:\Repos\rferl.modules.cms\src\RFERL.Modules.CMSModule.API\Program.cs:line 33`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌶️ hot chocolate 🔍 investigate Indicates that an issue or pull request needs more information. ⌛ stale Nothing happened with this issue in quite a while
Projects
None yet
Development

No branches or pull requests

6 participants