简体   繁体   English

使用HotChocolate拼接时,如何重命名远程模式的类型?

[英]When Stitching using HotChocolate, How Can A Remote Schema's Type Be Renamed?

Here's my scenario.这是我的场景。 I have a GraphQL gateway that stitches a dozen or so remote schemas together, using the following code:我有一个 GraphQL 网关,它使用以下代码将十几个远程模式拼接在一起:

services.AddHttpClient(schema.TypeName, c => c.BaseAddress = new Uri(schema.Url));
public virtual void Add(IRequestExecutorBuilder builder, bool ignoreRootTypes = true)
{
    var type = this.GetType();
    builder.AddRemoteSchema(type.Name, ignoreRootTypes);
}

Assume that the remote schemas are immutable.假设远程模式是不可变的。 One of the remote schemas has a type called Name .其中一个远程模式有一个名为Name的类型。 This appears to be a reserved keyword, because during stitching, I get the exception:这似乎是一个保留关键字,因为在拼接过程中,我得到了异常:

For more details look at the Errors property.有关更多详细信息,请查看Errors属性。

  1. An item with the same key has already been added.已添加具有相同键的项目。 Key: Name键:名称

I can correct this error by modifying the Name type of the remote service to be something like PersonName , however, as I mentioned above, these external schemas should be immutable.我可以通过将远程服务的Name类型修改为类似PersonName的类型来更正此错误,但是,正如我上面提到的,这些外部模式应该是不可变的。

Is there a way to rename a restricted type before this exception is thrown at the Gateway level?有没有办法在网关级别抛出此异常之前重命名受限类型?

Add a call to RenameType :添加对RenameType的调用:

public virtual void Add(IRequestExecutorBuilder builder, bool ignoreRootTypes = true)
{
    var type = this.GetType();
    builder.AddRemoteSchema(type.Name, ignoreRootTypes);
    builder.RenameType("Name", "PersonName", type.Name);
}

This will rename the incoming type from your remote schema to something else.这会将来自远程模式的传入类型重命名为其他名称。

声明:本站的技术帖子网页,遵循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 使用 HotChocolate 动态选择模式 - GraphQL - Dynamically choosing the schema using HotChocolate - GraphQL 如何使用 HotChocolate 在 GraphQL 架构中定义具有不可空项目的可空列表? - How to define a nullable list with non-nullable items in a GraphQL schema using HotChocolate? 如何处理 HotChocolate 中的输入错误? - How can I handle input errors in HotChocolate? 当 HotChocolate GraphQL 服务器中引发异常时,如何获取更多错误详细信息或日志记录? - How can I get more error details or logging, when an exception is thrown in a HotChocolate GraphQL server? 如何确定文件最近何时重命名? - How can I determine when a file was most recently renamed? 使用 HotChocolate 按 ObjectId 类型过滤 - Filtering by ObjectId type with HotChocolate 如何访问架构远程Powershell? - how can access to schema remote powershell? 如何使用 HotChocolate 和 EFCore 创建 GraphQL 部分更新 - How can I create a GraphQL partial update with HotChocolate and EFCore 如何在适用于 EFCore 的 Hotchocolate 中打开和关闭包含 - How can you switch includes on and off in Hotchocolate for EFCore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM