[英]The name `Foo` was already registered by another type, GraphQL
I am using GraphQL as a part of my CQRS application.我正在使用 GraphQL 作为我的 CQRS 应用程序的一部分。 I have separated Command and Query domain model into two different projects (Query and Command).
我已将命令和查询域 model 分成两个不同的项目(查询和命令)。 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:每个项目都有一些模型,例如 Student model。我在
Domain.Query.Students.Student
和Domain.Command.Students.Student
,但它们具有相同的实体名称(学生和地址)我简化了我的实体如下:
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. Student 正在 Query 和 Command 项目中使用。 in
Startup.cs
I have configured GraphQL like this:在
Startup.cs
中,我已经像这样配置了 GraphQL:
services
.AddGraphQLServer()
.AddQueryType<StudentQuery>()
.AddMutationType<AddStudentMutation>();
In StudentQuery.cs
在
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
和
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.如果我将 Domain.Query.Students.Student 中的 Student 实体更改为
Domain.Query.Students.Student
或其他内容,它将正常运行,但我不想更改它。
You can add the GraphQL annotation onto the Student
class as [GraphQLName("StudentQuery")]
您可以将 GraphQL 注释添加到
Student
class 作为[GraphQLName("StudentQuery")]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.