Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

746
Visualizações
The name `Foo` was already registered by another type, GraphQL

I am using GraphQL as a part of my CQRS application. I have separated Command and Query domain model into two different projects (Query and Command). each of there projects has some models for instance Student model. I use two different model in Domain.Query.Students.Student and Domain.Command.Students.Student, but both have the same entity name (Student and Address) I simplified my entity as below:

public class Student:Entity
{
    public  string FirstName { get; set; }
    public string LastName { get; set; }
    public Address Address { get; set; }
    public DateTimeOffset CreatedOn { get; set; }
    public DateTimeOffset ModifiedOn { get; set; }
 }

Student is being used in Query and Command projects. in Startup.cs I have configured GraphQL like this:

 services
 .AddGraphQLServer()
 .AddQueryType<StudentQuery>() 
 .AddMutationType<AddStudentMutation>();

In StudentQuery.cs

namespace GraphQL.Query.Students
{
    public class StudentQuery
    {
        
         
         public List<Student> AllStudents([ScopedService] StudentRepository studentRepository)
         {
             var query = studentRepository.GetEmployees();
             return query;
         }
    }
 }

and AddStudentMutation.cs

namespace GraphQL.Command.Students
{
    public class AddStudentMutation
    {
        public async Task<Student> AddStudentAsync(AddStudentInputType student,[Service] IMediator mediator)
        {
            var result =await mediator.Send(new AddStudentCommand(student.FirstName,student.LastName,student.StreetAddress,
                student.City,student.State,student.ZipCode));
            return result;
        }
    }
    
    [GraphQLName("AddStudentInput")]
    public class AddStudentInputType
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string StreetAddress { get;  set; }
        public string City { get;  set; }
        public string State { get;  set; }
        public string ZipCode { get;  set; }
    }
}

When I run the application I get the following error:

The name `Student` was already registered by another type. (HotChocolate.Types.ObjectType<Domain.Query.Students.Student>)

If I change the Student entity in Domain.Query.Students.Student to ReadStudent or something else, it will run without any issue, but I don't want to change it.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda