debugginggraphqlballerina

Ballerina debugger starts only one server in my ballerina project


My Ballerina project contains multiple servers.

  1. HTTP server (runs on port 9095)
  2. GraphQL server (runs on port 9090)

The HTTP server acts as a proxy server for the GraphQL server.

When I start the Ballerina project with debug mode from the VS Code, only the HTTP server is getting started in debug mode (i.e. Supports debugger breakpoints). While the GraphQL server runs without issues, it doesn't support pausing on the debugger breakpoints.

I want to know how to start the GraphQL server with debugging mode. It's okay to have the debugging mode only for the GraphQL server and not for the HTTP server.

Edit: Ballerina version: 2201.8.3


Solution

  • When running a Ballerina project in debug mode, all program entry points (i.e., all main functions and services) are initialized in debug mode. Hence, there's no need to explicitly run your GraphQL service in debug mode.

    Please refer to the sample below (a simplified version of your project having both HTTP and GraphQL services within the same program) and follow the mentioned steps to verify that the GraphQL service is up and running, and that the breakpoints within the service are reachable. (Verified with the latest Ballerina version up-to-date, which is 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!";
        }
    }
    

    Steps to follow:

    1. Set breakpoints within the GraphQL resource function greeting, and run the project in debug mode. (Refer to Ballerina documentation on debugging)
    2. Navigate to the locally created GraphiQL endpoint (http://localhost:9090/graphiql) as suggested in the program logs.
    3. Run a sample query via the GraphiQL client UI, and you'll see the debug hit inside the GraphQL resource function.