[英]`StringOperationFilterInput` was already registered by another type, when stitching a remote GraphQL schema in HotChocolate
[英]The name `Foo` was already registered by another type, GraphQL
我正在使用 GraphQL 作为我的 CQRS 应用程序的一部分。 我已将命令和查询域 model 分成两个不同的项目(查询和命令)。 每个项目都有一些模型,例如 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 正在 Query 和 Command 项目中使用。 在Startup.cs
中,我已经像这样配置了 GraphQL:
services
.AddGraphQLServer()
.AddQueryType<StudentQuery>()
.AddMutationType<AddStudentMutation>();
在StudentQuery.cs
namespace GraphQL.Query.Students
{
public class StudentQuery
{
public List<Student> AllStudents([ScopedService] StudentRepository studentRepository)
{
var query = studentRepository.GetEmployees();
return query;
}
}
}
和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; }
}
}
当我运行应用程序时,出现以下错误:
The name `Student` was already registered by another type. (HotChocolate.Types.ObjectType<Domain.Query.Students.Student>)
如果我将 Domain.Query.Students.Student 中的 Student 实体更改为Domain.Query.Students.Student
或其他内容,它将正常运行,但我不想更改它。
您可以将 GraphQL 注释添加到Student
class 作为[GraphQLName("StudentQuery")]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.