Ballerina 调试器仅启动我的 Ballerina 项目中的一台服务器

问题描述 投票:0回答:1

我的 Ballerina 项目包含多个服务器。

  1. HTTP 服务器(在端口 9095 上运行)
  2. GraphQL 服务器(在端口 9090 上运行)

HTTP 服务器充当 GraphQL 服务器的代理服务器。

当我从 VS Code 中以调试模式启动 Ballerina 项目时,只有 HTTP 服务器以调试模式启动(即支持调试器断点)。虽然 GraphQL 服务器运行没有问题,但它不支持在调试器断点处暂停。

我想知道如何以调试模式启动 GraphQL 服务器。只为 GraphQL 服务器设置调试模式,而不为 HTTP 服务器设置调试模式是可以的。

编辑:芭蕾舞版本:2201.8.3

debugging graphql ballerina
1个回答
1
投票

在调试模式下运行 Ballerina 项目时,所有程序入口点(即所有主要功能和服务)都在调试模式下初始化。因此,无需在调试模式下显式运行 GraphQL 服务。

请参考下面的示例(您的项目的简化版本,在同一程序中同时具有 HTTP 和 GraphQL 服务)并按照上述步骤验证 GraphQL 服务是否已启动并正在运行,以及服务中的断点是否可达。 (已验证最新的 Ballerina 版本为 2201.9.2)

import ballerina/graphql;
import ballerina/http;

service / on new http:Listener(9095) {
    resource function get greeting() returns string {
        return "Hello, World!";
    }
}

@graphql:ServiceConfig {
    graphiql: {
        enabled: true
    }
}
service /graphql on new graphql:Listener(9090) {
    resource function get greeting() returns string {
        return "Hello, World!";
    }
}

遵循的步骤:

  1. 在 GraphQL 资源函数
    greeting
    中设置断点,并在调试模式下运行项目。 (请参阅Ballerina 调试文档
  2. 按照程序日志中的建议导航到本地创建的 GraphiQL 端点 (http://localhost:9090/graphiql)。
  3. 通过 GraphQL 客户端 UI 运行示例查询,您将在 GraphQL 资源函数内看到调试命中。
© www.soinside.com 2019 - 2024. All rights reserved.