如何在 Hotchocolate 10.4.3 中设置执行超时

PRA*_*HIT 2 executiontimeout graphql hotchocolate

我们将 Hotchocolate 10.4.3 用于我的 .net 核心服务。我们正在使用代码优先的方法。所有设置都在 startup.cs 中,与他们的 Star War 示例完全相似。Hotchocolate 网站说请求的默认超时为 30 秒,但我发现我的应用程序在 1 分钟后抛出事务错误。我想将其增加到 2 分钟。

这也是为什么即使在超时异常之后服务器仍然执行所有内容的原因。在我的所有代码正确执行后,我总是在最后看到事务错误。

如果一切都会正常运行,为什么还要抛出错误?

我还在学习graphql。如果任何听起来不正确,请纠正我。

ngp*_*ice 6

在 HotChocolate v10 中,您可以在 Startup 的 ConfigureServices() 方法中添加服务时设置执行超时:

services.AddGraphQL(
    SchemaBuilder.New()
        .AddQueryType<Query>()
        .Create(),
    new QueryExecutionOptions { ExecutionTimeout = TimeSpan.FromMinutes(2) });
Run Code Online (Sandbox Code Playgroud)

他们在这里有一个很好的例子仓库:https : //github.com/ChilliCream/hotchocolate-examples

有关执行选项的文档:https : //chillicream.com/docs/hotchocolate/v10/execution-engine/execution-options

编辑:在 v11 中,语法发生了变化:

services
    .AddGraphQLServer()
    .AddQueryType<Query>()
    .SetRequestOptions(_ => new HotChocolate.Execution.Options.RequestExecutorOptions { ExecutionTimeout = TimeSpan.FromMinutes(10) });
Run Code Online (Sandbox Code Playgroud)