ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 64 forks source link

graphql tryit is not working when there is package level clients #6037

Open anupama-pathirage opened 9 months ago

anupama-pathirage commented 9 months ago

Description: See the sample code below.

Not working :

import ballerina/graphql;
import ballerinax/mysql;
import ballerinax/mysql.driver as _;

final mysql:Client db =  check new("localhost", "root", "password", "gq_bank_test");

service /foo on new graphql:Listener(9090) {

    resource function get hello() returns string|error {
        //mysql:Client db =  check new("localhost", "root", "password", "gq_bank_test");
        return "Hello, World!";
    }
}

The above will the following error in tryit tool.
image

Working :

When we move the client init to the resource function it is working.

import ballerina/graphql;
import ballerinax/mysql;
import ballerinax/mysql.driver as _;

//final mysql:Client db =  check new("localhost", "root", "password", "gq_bank_test");

service /foo on new graphql:Listener(9090) {

    resource function get hello() returns string|error {
        mysql:Client db =  check new("localhost", "root", "password", "gq_bank_test");
        return "Hello, World!";
    }
}
gigara commented 9 months ago

The try-it view directly connects to the GraphQL server to initiate the session. It will fail if the server is not running correctly. Please check the server side by sending a request via Postman or any other way. Or else please provide the exact Ballerina, extension and MySQL versions you are using to reproduce the issue.

anupama-pathirage commented 9 months ago

@gigara server is running and it responds to curl commands too by fetching data from MySQL. So this connection error is not to the DB, but between graphql client and server.

You can reproduce using https://github.com/anupama-pathirage/ballerina-training-content/tree/graphql-level4

Ballerina 2201.8.4 (Swan Lake Update 8) Language specification 2023R1 Update Tool 1.4.2

@niveathika knows the context. IINM she mentioned that should be an issue with compiler plugin level and may be reproducable without MySQL (with some other client ) too