[英]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
属性。
- 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.