Skip to content

Commit

Permalink
Fix listener error when passing configurables as init parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisaruGuruge committed Jan 29, 2025
1 parent 04cfa43 commit 8fc171a
Show file tree
Hide file tree
Showing 24 changed files with 152 additions and 151 deletions.
5 changes: 0 additions & 5 deletions ballerina-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,6 @@ task ballerinaTest {

doLast {
testSuites.each { testPackage ->
// TODO: Disable the graphql-subscription-test-suite on Linux
// Check issue: https://github.com/ballerina-platform/ballerina-library/issues/7529
if (Os.isFamily(Os.FAMILY_UNIX) && testPackage == "graphql-subscription-test-suite") {
return
}
if (!skipTests) {
exec {
workingDir "${project.projectDir}/${testPackage}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ dependencies = [
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.default"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ dependencies = [
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.default"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ isolated function testDataLoaderWithDifferentAliasForSameField() returns error?

@test:Config {
groups: ["subscriptions", "dataloader"],
after: resetDispatchCounters,
enable: false
after: resetDispatchCounters
}
isolated function testDataLoaderWithSubscription() returns error? {
string document = check common:getGraphqlDocumentFromFile("dataloader_with_subscription");
Expand All @@ -71,8 +70,7 @@ isolated function testDataLoaderWithSubscription() returns error? {
dependsOn: [
testDataLoaderWithQuery, testDataLoaderWithSubscription
],
after: resetDispatchCounters,
enable: false
after: resetDispatchCounters
}
isolated function testDataLoaderWithMutation() returns error? {
graphql:Client graphqlClient = check new ("localhost:9090/dataloader");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ dependencies = [
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.default"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@
import ballerina/graphql;

listener graphql:Listener basicListener = new (9090);
listener graphql:Listener subscriptionListener = new (9091);
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ dependencies = [
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.default"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ dependencies = [
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.default"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function testGraphiqlWithSamePathAsGraphQLService() returns error? {
graphql:Error? result = basicListener.attach(graphiqlConfigService, "ballerina/graphiql");
test:assertTrue(result is graphql:Error);
graphql:Error err = <graphql:Error>result;
test:assertEquals(err.message(), "Error occurred while attaching the GraphiQL endpoint");
test:assertEquals(err.message(), "Error occurred while attaching the HTTP service");
}

@test:Config {
Expand Down
2 changes: 1 addition & 1 deletion ballerina-tests/graphql-subgraph-test-suite/subgraphs.bal
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ service /subgraph on new graphql:Listener(9088) {
resource function get greet() returns string => "welcome";
}

public graphql:Service subgraphServivce = @subgraph:Subgraph service object {
public graphql:Service subgraphService = @subgraph:Subgraph service object {
resource function get greeting() returns string => "welcome";
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ isolated function testQueringSdlOnSubgraph() returns error? {
groups: ["federation", "subgraph"]
}
function testAttachingSubgraphServiceToDynamicListener() returns error? {
check subgraphListener.attach(subgraphServivce, "subgraph");
graphql:Listener subgraphListener = check new (9095);
check subgraphListener.attach(subgraphService, "subgraph");
check subgraphListener.start();
string url = "http://localhost:9095/subgraph";
graphql:Client graphqlClient = check new (url);
string document = check common:getGraphqlDocumentFromFile("querying_entities_field_on_subgraph");
json response = check graphqlClient->execute(document);
json expectedPayload = check common:getJsonContentFromFile("querying_entities_field_on_subgraph");
check subgraphListener.detach(subgraphServivce);
check subgraphListener.detach(subgraphService);
common:assertJsonValuesWithOrder(response, expectedPayload);
}

Expand Down
19 changes: 0 additions & 19 deletions ballerina-tests/graphql-subgraph-test-suite/tests/listeners.bal

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ dependencies = [
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.default"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@

import ballerina/graphql;
import ballerina/graphql_test_common as common;
import ballerina/http;
import ballerina/test;
import ballerina/websocket;

@test:Config {
groups: ["listener", "subscriptions"]
}
function testAttachServiceWithSubscriptionToHttp2BasedListener() returns error? {
http:Listener http2Listener = check new http:Listener(9090);
graphql:Listener http2BasedListener = check new (http2Listener);
graphql:Error? result = http2BasedListener.attach(subscriptionService);
test:assertTrue(result is graphql:Error);
graphql:Error err = <graphql:Error>result;
string expectedMessage = string `Websocket listener initialization failed due to the incompatibility of ` +
string `provided HTTP(version 2.0) listener`;
string expectedMessage = "GraphQL subscriptions are only supported over HTTP/1.1 or HTTP/1.0. Found 2.0";
test:assertEquals(err.message(), expectedMessage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
// under the License.

import ballerina/graphql;
import ballerina/http;

listener http:Listener http2Listener = new http:Listener(9090);
listener graphql:Listener http2BasedListener = new (http2Listener);
configurable int port = 9091;
configurable graphql:ListenerConfiguration listenerConfig = {};

listener graphql:Listener subscriptionListener = new (9091);
listener graphql:Listener subscriptionListener = new (port, listenerConfig);
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@

import ballerina/graphql;

listener graphql:Listener basicListener = new (9090);
listener graphql:Listener subscriptionListener = new (9091);
1 change: 0 additions & 1 deletion ballerina-tests/graphql-test-common/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ dependencies = [
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.default"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

Expand Down
1 change: 0 additions & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ dependencies = [
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.default"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

Expand Down
30 changes: 0 additions & 30 deletions ballerina/annotation_processor.bal
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,6 @@ isolated function getServiceInterceptors(GraphqlServiceConfig? serviceConfig) re
return [];
}

isolated function getIntrospection(GraphqlServiceConfig? serviceConfig) returns boolean {
if serviceConfig is GraphqlServiceConfig {
return serviceConfig.introspection;
}
return true;
}

isolated function getValidation(GraphqlServiceConfig? serviceConfig) returns boolean {
if serviceConfig is GraphqlServiceConfig {
return serviceConfig.validation;
}
return true;
}

isolated function getFieldInterceptors(service object {} serviceObj, parser:RootOperationType operationType,
string fieldName, string[] resourcePath) returns readonly & (readonly & Interceptor)[] {
GraphqlResourceConfig? resourceConfig = getResourceAnnotation(serviceObj, operationType, resourcePath, fieldName);
Expand Down Expand Up @@ -109,22 +95,6 @@ isolated function getInterceptorConfig(readonly & Interceptor interceptor) retur
return classType.@InterceptorConfig;
}

isolated function getCacheConfig(GraphqlServiceConfig? serviceConfig) returns ServerCacheConfig? {
if serviceConfig is GraphqlServiceConfig {
if serviceConfig.cacheConfig is ServerCacheConfig {
return serviceConfig.cacheConfig;
}
}
return;
}

isolated function getFieldCacheConfigFromServiceConfig(GraphqlServiceConfig? serviceConfig) returns ServerCacheConfig? {
if serviceConfig is GraphqlServiceConfig {
return serviceConfig.fieldCacheConfig;
}
return;
}

isolated function getFieldCacheConfig(service object {} serviceObj, parser:RootOperationType operationType,
string fieldName, string[] resourcePath) returns ServerCacheConfig? {
GraphqlResourceConfig? resourceConfig = getResourceAnnotation(serviceObj, operationType, resourcePath, fieldName);
Expand Down
1 change: 1 addition & 0 deletions ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ ballerina {
module = packageName
langVersion = ballerinaLangVersion
testCoverageParam = "--code-coverage --coverage-format=xml --includes=io.ballerina.stdlib.graphql.*:ballerina.graphql*"
platform = 'java21'
}

task updateTomlFiles {
Expand Down
Loading

0 comments on commit 8fc171a

Please sign in to comment.