Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Invalid coverage report generated for GraphQL service #42640

Closed
MaryamZi opened this issue Apr 25, 2024 · 2 comments
Closed

[Bug]: Invalid coverage report generated for GraphQL service #42640

MaryamZi opened this issue Apr 25, 2024 · 2 comments
Assignees
Labels
Area/TestFramework Reason/Invalid Issue is invalid. Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) Type/Bug

Comments

@MaryamZi
Copy link
Member

Description

$title.

Steps to Reproduce

Source

import ballerina/graphql;

type Person record {|
    readonly int id;
    string firstName;
    string lastName;
    int age;
|};

table<Person> key(id) data = table [
    {id: 101, firstName: "John", lastName: "Doe", age: 20},
    {id: 102, firstName: "Mary", lastName: "Anne", age: 30}
];

@graphql:ServiceConfig {
    graphiql: {
        enabled: true
    }
}
service /graphql on new graphql:Listener(9090) {
    resource function get profiles() returns Profile[] {
        return from int id in data.keys() select new (id);
    }
    resource function get profile(@graphql:ID int id) returns Profile {
        return new (id);
    }
}

service class Profile {
    private final int id;
    private final string firstName;
    private final string lastName;
    private final int age;

    function init(int id) {
        Person {firstName, lastName, age} = data.get(id);
        self.id = id;
        self.firstName = firstName;
        self.lastName = lastName;
        self.age = age;
    }

    resource function get id() returns @graphql:ID int {
        return self.id;
    }

    resource function get fullName() returns string {
        return self.firstName + " " + self.lastName;
    }

    resource function get firstName() returns string {
        return self.firstName;
    }

    resource function get lastName() returns string {
        return self.lastName;
    }

    resource function get age() returns int {
        return self.age;
    }

    resource function get isAdult() returns boolean {
        return self.age > 21;
    }
}

Tests

import ballerina/graphql;
import ballerina/test;

final graphql:Client cl = check new ("http://localhost:9090/graphql");

@test:Config
function testRetrievingProfile() returns error? {
    json payload = check cl->execute(string `query QueryProfile($id: ID!) {
        profile(id: $id) {
            fullName
            age
        }
    }`, {id: 101});
    test:assertEquals(payload, {
        "data": {
            "profile": {
                "fullName": "John Doe",
                "age": 20
            }
        }
    });
}

Screenshot from 2024-04-25 17-42-48

Affected Version(s)

2201.9.0-rc1

OS, DB, other environment details and versions

No response

Related area

-> Test Framework

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@MaryamZi MaryamZi added Type/Bug Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) Area/TestFramework labels Apr 25, 2024
@gayaldassanayake
Copy link
Contributor

The code modifier within the graphql package adds a new field to the annotation @graphql:ServiceConfig. However, during this process, the line breaks of the annotation were lost.

- @graphql:ServiceConfig {
-   graphiql: {
-       enabled: true
-   }
- }
- service /reviewed on new graphql:Listener(9000) {
+ @graphql:ServiceConfig {         graphiql: {
+       enabled: true
+   },
+, schemaString: "rO0A...." ,fieldCacheConfig:{enabled:false,maxSize:0}}service /reviewed on new graphql:Listener(9000) {

From the code coverage POV, this causes a multi-line diff of the CHANGE type. This results in offsetting up coverage of the lines following the annotation.

As per the offline discussions with @azinneera @MaryamZi @SasinduDilshara @lochana-chathura , this needs to be fixed in the GraphQL compiler plugin. More details on this are documented in the library issue to track this ballerina-platform/ballerina-library#6418.

Closing this issue for now.

Copy link

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

@gayaldassanayake gayaldassanayake added the Reason/Complex Issue occurred due to complex scenario. label Apr 26, 2024
@azinneera azinneera added Reason/Invalid Issue is invalid. and removed Reason/Complex Issue occurred due to complex scenario. labels Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/TestFramework Reason/Invalid Issue is invalid. Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) Type/Bug
Projects
Archived in project
Development

No branches or pull requests

3 participants