import ballerina/graphql;
service class Profile {
private final string name;
private final int age;
function init(string name, int age) {
self.name = name;
self.age = age;
}
resource function get name() returns string {
return self.name;
}
resource function get age() returns int {
return self.age;
}
resource function get isAdult() returns boolean {
return self.age > 21;
}
resource function get reviews() returns Review[] {
return [
new (1, "review 1"),
new (2, "review 2")
];
}
}
annotation MyAnnot on parameter, return, class;
@MyAnnot
service class Review {
int id;
string content;
function init(
@MyAnnot
int id, string content) {
self.id = id;
self.content = content;
}
resource function get id() returns @MyAnnot int {
return self.id;
}
resource function get content() returns string {
return self.content;
}
}
service /graphql on new graphql:Listener(9090) {
resource function get profile() returns Profile {
return new ("John Doe", 51);
}
}
Tests
import ballerina/graphql;
import ballerina/test;
final graphql:Client cl = check new ("http://localhost:9090/graphql");
@test:Config
function testCallOriginal() returns error? {
json j = check cl->execute(string `{ profile { name isAdult } }`);
test:assertEquals(j, {"data":{"profile":{"name":"John Doe", "isAdult":true}}});
}
Description
$title. May be related to annotation closures.
Steps to Reproduce
Tests
Affected Version(s)
2201.9.0-rc1