简体   繁体   English

名称“Foo”已被另一种类型注册,GraphQL

[英]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.StudentDomain.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.csStudentQuery.cs

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

and AddStudentMutation.csAddStudentMutation.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.

相关问题 在 HotChocolate 中拼接远程 GraphQL 模式时,`StringOperationFilterInput` 已被另一种类型注册 - `StringOperationFilterInput` was already registered by another type, when stitching a remote GraphQL schema in HotChocolate <Dependency>财产已被注册<type> - <Dependency> Property was already registered by <type> Autofac:在将类型A注册为类型之后,注册类型A的实例 - Autofac: register an instance of type A, after type A is already registered as type 得到“ <Property Name> 已经注册“ <Control Name> “WPF中的错误 - Getting “<Property Name> was already registered by ”<Control Name>" error in WPF 有没有办法通过引用另一种类型来解决 GraphQl 类型? - Is there a way to resolve a GraphQl type by referencing another type? 导航到视图但发生了具有给定名称的异常区域,已经注册 - Navigation to a view but occurred Exception Region with the given name is already registered HttpClient 工厂已经有一个类型为 c# 的注册客户端 - The HttpClient factory already has a registered client with the type c# 类型&#39;foo.Phyl.DSpeed&#39;已经定义了一个名为&#39;DSpeed&#39;的成员,它具有相同的参数类型 - Type 'foo.Phyl.DSpeed' already defines a member called 'DSpeed' with the same parameter types 属性已由“ FrameworkElement”注册 - property was already registered by 'FrameworkElement' 频道'tcp'已经注册 - The channel 'tcp' is already registered
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM