简体   繁体   English

使用 HotChocolate 动态选择模式 - GraphQL

[英]Dynamically choosing the schema using HotChocolate - GraphQL

I'm struggling trying to dynamically choose the schema which I want to use based on information sent on the request.我正在努力尝试根据请求发送的信息动态选择要使用的架构。

Example:例子:

If I send a request to an specific URL -.../graphql/schema/{id} - I can get the id from the slug.如果我向特定的 URL -.../graphql/schema/{id} 发送请求 - 我可以从 slug 中获取 id。 With that ID, I want to get the schema (stored on a database where it can be updated as many time the user wants) and execute the query against it.使用该 ID,我想获取架构(存储在数据库中,用户可以在其中多次更新)并针对它执行查询。

I can already do this using graphql-dotnet, but I want to use HotChocolate in order to take advantage of all the features that it provides.我已经可以使用 graphql-dotnet 做到这一点,但我想使用 HotChocolate 以利用它提供的所有功能。 I've wasted many hours so far and I'm not being successful.到目前为止,我已经浪费了很多时间,但我没有成功。

I've looked into the implementation of the IRequestExecutorResolver and I realized that the RequestExecutor is chosen according to the schemaName.我研究了 IRequestExecutorResolver 的实现,我意识到 RequestExecutor 是根据 schemaName 选择的。 Is there any way to, at runtime, add and edit the current list of executors?有没有办法在运行时添加和编辑当前的执行者列表? Or is there any easier way to resolve my problem?或者有没有更简单的方法来解决我的问题?

At the moment we do not allow dynamic routes.目前我们不允许动态路由。 Meaning you at the moment can have multiple schemas but they are fixed to a specific route.这意味着您目前可以有多个模式,但它们固定在特定的路线上。

https://github.com/ChilliCream/hotchocolate/blob/07e1f33cef90ca41624fc94f168ade82d4cc6e73/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/EndpointRouteBuilderExtensions.cs#L132 https://github.com/ChilliCream/hotchocolate/blob/07e1f33cef90ca41624fc94f168ade82d4cc6e73/src/HotChocolate/AspNetCore/src/AspNetCore/Extensions/EndpointRouteBuilderExtensions.cs#L132

This could be changed.这可以改变。 File an issue on our repo and we will put it on the backlog.在我们的 repo 上提交问题,我们会将其放在 backlog 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM