Skip to content

Commit

Permalink
Allow Returning Error Reference Types and Intersection Types in Input…
Browse files Browse the repository at this point in the history
… Objects

* Fix not allowing to return error reference types from resolvers

* Fix service crashing when intersection types are used as Input Objects

* Add test for returning graphql:Error
  • Loading branch information
ThisaruGuruge authored Mar 22, 2024
1 parent 1f1410b commit d659afb
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ballerina-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.10.7"
version = "2.10.12"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand Down
17 changes: 16 additions & 1 deletion ballerina-tests/tests/31_intersection_types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ function dataProviderIntersectionType() returns map<[string, string, json]> {
}
};

json variableGetOwnerName = {
pet: {
name: "Dingi",
ownerName: "Ruwangi",
animal: {
commonName: "Common House Cat",
species: {
genus: "Felis",
specificName: "catus"
}
}
}
};

map<[string, string, json]> dataSet = {
"1": ["input_with_intersection_parameter", "getName", ()],
"2": ["input_with_intersection_parameter_reference", "getCity", ()],
Expand All @@ -49,7 +63,8 @@ function dataProviderIntersectionType() returns map<[string, string, json]> {
"7": ["output_with_intersection_parameter_array", "getProfiles", ()],
"8": ["output_with_intersection_parameter_reference_array", "getBooks", ()],
"9": ["input_with_intersection_referring_non_intersection_type", "getCommonName", variableGetCommonName],
"10": ["input_with_non_intersection_type_referring_intersection_type", "getOwnerName", ()]
"10": ["input_with_non_intersection_type_referring_intersection_type", "getOwnerName", ()],
"11": ["input_with_non_intersection_type_referring_intersection_type_as_a_variable", "getOwnerNameWithVariable", variableGetOwnerName]
};
return dataSet;
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ query getOwnerName {
}
)
}

query getOwnerNameWithVariable($pet: Pet!) {
ownerName(pet: $pet)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"data": {
"ownerName": "Ruwangi"
}
}
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.10.7"
version = "2.10.12"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed
- [[#4848] Fix Resolvers not Able to Return Error Reference Types](https://github.com/ballerina-platform/ballerina-library/issues/4848)
- [[#4859] Fix Service Crashing when Intersection Types are Used as Input Objects](https://github.com/ballerina-platform/ballerina-library/issues/4859)

## [1.11.0] - 2023-02-21

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Person record {
string name;
};

type Error distinct error;

service graphql:Service on new graphql:Listener(4000) {
resource function get greeting() returns string {
return "Hello";
Expand Down Expand Up @@ -74,6 +76,18 @@ service graphql:Service on new graphql:Listener(4000) {
}
}

service graphql:Service on new graphql:Listener(4000) {
resource function get profile() returns Person|Error {
return {name: "John"};
}
}

service graphql:Service on new graphql:Listener(4000) {
resource function get profile() returns Person|graphql:Error {
return {name: "John"};
}
}

service graphql:Service on new graphql:Listener(4000) {
resource function get greet() returns GeneralGreeting {
return new;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ public static boolean isGraphqlListener(Symbol listenerSymbol) {
}

public static boolean isIgnoreType(TypeSymbol typeSymbol) {
return typeSymbol.typeKind() == TypeDescKind.NIL || typeSymbol.typeKind() == TypeDescKind.ERROR;
if (typeSymbol.typeKind() == TypeDescKind.NIL || typeSymbol.typeKind() == TypeDescKind.ERROR) {
return true;
}
if (typeSymbol.typeKind() == TypeDescKind.TYPE_REFERENCE) {
return isIgnoreType(((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor());
}
return false;
}

public static List<TypeSymbol> getEffectiveTypes(UnionTypeSymbol unionTypeSymbol) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ stdlibJwtVersion=2.10.0
stdlibOAuth2Version=2.10.0

# Level 05
stdlibHttpVersion=2.10.0
stdlibHttpVersion=2.10.12

# Level 06
stdlibWebsocketVersion=2.10.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private BMap<BString, Object> getInputObjectArgument(BObject argumentNode, Recor
BMap<BString, Object> recordValue = recordType.getZeroValue();
if (argumentNode.getBooleanValue(VARIABLE_DEFINITION)) {
BMap<BString, Object> variablesMap = argumentNode.getMapValue(VARIABLE_VALUE_FIELD);
return JsonUtils.convertJSONToRecord(variablesMap, recordType);
return ValueCreator.createRecordValue(recordType.getPackage(), recordType.getName(), variablesMap);
}
BArray inputObjectFields = argumentNode.getArrayValue(VALUE_FIELD);
for (int i = 0; i < inputObjectFields.size(); i++) {
Expand Down

0 comments on commit d659afb

Please sign in to comment.