Skip to content

Many to Many Circular Dependency #5254

@vtrihos

Description

@vtrihos

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In a many-to-many scenario where I'm trying to add DefaultValue(new [] {}) to both InputTypes using code-first approach, I'm getting an error that seems to be a circular dependency issue.

Something like:

  1. Unable to resolve dependencies Input: AddClassAInputType for type ClassBInput. (AddClassBInputType)

  2. Unable to resolve dependencies Input: AddClassBInputType for type ClassAInput. (AddClassAInputType)

I was expecting to properly add the default values in the schema and not raise an error.

Steps to reproduce

https://github.com/glen-84/hc-5254 (.NET 8, HC 14.0.0-rc.1)

My Setup:

    public class ClassA
    {
        public int Id { get; set; }
        public string Name { get; set; } = default!;

        public virtual ICollection<ClassB> ClassBs { get; set; } = new HashSet<ClassB>();

    }
    public class ClassB
    {
        public int Id { get; set; }
        public string Name { get; set; } = default!;

        public virtual ICollection<ClassA> ClassAs { get; set; } = new HashSet<ClassA>();

    }
    public class AddClassAInputType : InputObjectType<ClassA>
    {
        protected override void Configure(IInputObjectTypeDescriptor<ClassA> descriptor)
        {
            descriptor
                .Field(f => f.ClassBs)
                .DefaultValue(new ListValueNode())
                ;
        }
    }
    public class AddClassBInputType : InputObjectType<ClassB>
    {
        protected override void Configure(IInputObjectTypeDescriptor<ClassB> descriptor)
        {
            descriptor
                .Field(f => f.ClassAs)
                .DefaultValue(new ListValueNode())
                ;
        }
    }
        services
            .AddGraphQLServer()
            .AddFiltering()
            .AddSorting()
            .AddProjections()

            .RegisterDbContext<DefaultDbContext>(DbContextKind.Pooled)
            .AddMutationConventions(applyToAllMutations: true)
            .AddDefaultTransactionScopeHandler()
            .AddQueryType<Query>()
            .AddMutationType<Mutation>()
            .AddType<AddClassAInputType>()
            .AddType<AddClassBInputType>()
    public class Mutation
    {
        public async Task<ClassA> AddClassAAsync(ClassA input, [Service] ClassARepository classARepository, CancellationToken token)
        {
            return await classARepository.AddAsync(input, token);
        }
    }

Relevant log output

api | 1. Unable to resolve dependencies Input: AddClassAInputType for type `ClassBInput`. (AddClassBInputType)
api |2. Unable to resolve dependencies Input: AddClassBInputType for type `ClassAInput`. (AddClassAInputType)     
api |          at HotChocolate.Configuration.TypeInitializer.EnsureNoErrors()
api |          at HotChocolate.Configuration.TypeInitializer.CompleteTypes()
api |          at HotChocolate.Configuration.TypeInitializer.Initialize()
api |          at HotChocolate.SchemaBuilder.Setup.InitializeTypes(SchemaBuilder builder, IDescriptorContext context, IReadOnlyList`1 types, LazySchema lazySchema)
api |          at HotChocolate.SchemaBuilder.Setup.Create(SchemaBuilder builder, LazySchema lazySchema, IDescriptorContext context)
api |          at HotChocolate.SchemaBuilder.Create(IDescriptorContext context)
api |          at HotChocolate.SchemaBuilder.HotChocolate.ISchemaBuilder.Create(IDescriptorContext context)
api |          at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaAsync(NameString schemaName, RequestExecutorSetup options, RequestExecutorOptions executorOptions, IServiceProvider serviceProvider, TypeModuleChangeMonitor typeModuleChangeMonitor, CancellationToken cancellationToken)
api |          at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaServicesAsync(NameString schemaName, RequestExecutorSetup options, CancellationToken cancellationToken)
api |          at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorNoLockAsync(NameString schemaName, CancellationToken cancellationToken)
api |          at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorAsync(NameString schemaName, CancellationToken cancellationToken)
api |          at HotChocolate.Execution.RequestExecutorProxy.GetRequestExecutorAsync(CancellationToken cancellationToken)
api |          at HotChocolate.AspNetCore.HttpPostMiddlewareBase.HandleRequestAsync(HttpContext context, AllowedContentType contentType)
api |          at HotChocolate.AspNetCore.HttpPostMiddlewareBase.InvokeAsync(HttpContext context)
api |          at Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions.<>c__DisplayClass13_0.<<UseCancellation>b__1>d.MoveNext()

Additional Context?

No response

Product

Hot Chocolate

Version

12.12.1

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions