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 8fbcfac
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@

import ballerina/graphql;

listener graphql:Listener graphqlListener = new (9090);
configurable int port = 9090;
configurable graphql:ListenerConfiguration graphqlListenerConfigs = {};

listener graphql:Listener graphqlListener = new (port, graphqlListenerConfigs);
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 @@ -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 @@ -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,5 @@
// under the License.

import ballerina/graphql;
import ballerina/http;

listener http:Listener http2Listener = new http:Listener(9090);
listener graphql:Listener http2BasedListener = new (http2Listener);

listener graphql:Listener subscriptionListener = new (9091);
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);
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 8fbcfac

Please sign in to comment.