使用 HotChocolate 进行拼接时,如何重命名远程架构的类型?
这是我的场景。我有一个 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);
}
假设远程模式是不可变的。其中一个远程架构具有名为 Name
的类型。这似乎是一个保留关键字,因为在拼接过程中,我得到了异常:
有关更多详细信息,请查看
Errors
属性。
- 已添加具有相同键的项目。键:姓名
我可以通过将远程服务的 Name
类型修改为类似 PersonName
来纠正此错误,但是,正如我上面提到的,这些外部模式应该是不可变的。
有没有办法在网关级别抛出此异常之前重命名受限类型?
Here's my scenario. I have a GraphQL gateway that stitches a dozen or so remote schemas together, using the following code:
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
. This appears to be a reserved keyword, because during stitching, I get the exception:
For more details look at the
Errors
property.
- 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.
Is there a way to rename a restricted type before this exception is thrown at the Gateway level?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
continue
Add a call to
RenameType
:This will rename the incoming type from your remote schema to something else.