Skip to content

Commit

Permalink
Merge pull request #2078 from DimuthuMadushan/fix-input-obj
Browse files Browse the repository at this point in the history
Fix Service Crashing when Input Object Type Variable Value Includes an Additional Field
  • Loading branch information
DimuthuMadushan authored Nov 1, 2024
2 parents 68201f9 + 5d99c5c commit 9020ffc
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 24 deletions.
4 changes: 2 additions & 2 deletions ballerina-tests/graphql-advanced-test-suite/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.1"
version = "2.12.2"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand Down Expand Up @@ -292,7 +292,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "mime"
version = "2.10.0"
version = "2.10.1"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down
4 changes: 2 additions & 2 deletions ballerina-tests/graphql-client-test-suite/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.1"
version = "2.12.2"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -294,7 +294,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "mime"
version = "2.10.0"
version = "2.10.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "io"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.1"
version = "2.12.2"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -300,7 +300,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "mime"
version = "2.10.0"
version = "2.10.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "io"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.1"
version = "2.12.2"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -303,7 +303,7 @@ modules = [
[[package]]
org = "ballerina"
name = "mime"
version = "2.10.0"
version = "2.10.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "io"},
Expand Down
4 changes: 2 additions & 2 deletions ballerina-tests/graphql-security-test-suite/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.1"
version = "2.12.2"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -299,7 +299,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "mime"
version = "2.10.0"
version = "2.10.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "io"},
Expand Down
4 changes: 2 additions & 2 deletions ballerina-tests/graphql-service-test-suite/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.1"
version = "2.12.2"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand Down Expand Up @@ -289,7 +289,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "mime"
version = "2.10.0"
version = "2.10.1"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ function dataProviderInputObject() returns map<[string, json]> {
dir: "Chris Columbus"
};

json var8 = {
bName: "Harry",
bAuthor: {name:"J.K Rowling", age:44, address: {street: "Baker Street", city: "London"}},
dir: "Chris Columbus"
};

json var9 = {
bInfo: {
bookName: "Harry",
author: {name:"J.K Rowling", age:44, address: {street: "Baker Street", city: "London"}},
dir: "Chris Columbus",
movie: {movieName: "End Game", director: "Russo", episodes: [{timeDuration: 120}]},
edition: 6
}
};

map<[string, json]> dataSet = {
"1": ["input_object"],
"2": ["input_object_with_missing_arguments"],
Expand All @@ -109,7 +125,9 @@ function dataProviderInputObject() returns map<[string, json]> {
"22": ["input_object_with_unexpected_variable_values", var7],
"23": ["input_object_variables_with_invalid_type_name", {profile: {name: "Arthur", age: 5}}],
"24": ["input_object_with_missing_nullable_variable_value"],
"25": ["default_values_in_input_object_fields"]
"25": ["default_values_in_input_object_fields"],
"26": ["input_object_with_unexpected_variable_fields1", var8],
"27": ["input_object_with_unexpected_variable_fields2", var9]
};
return dataSet;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
query getBook($bName:String!, $bAuthor:ProfileDetail!, $dir:String) {
...on Query {
book(info: {bookName: $bName, edition: 6, author: $bAuthor, movie:{movieName: "End Game", director: $dir}}) {
...on Book {
name
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
query getBook($bInfo:Info!) {
...on Query {
book(info: $bInfo) {
...on Book {
name
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"errors": [
{
"message":"Input type \"ProfileDetail\" does not have a field \"address\".",
"locations": [
{
"line": 3,
"column": 60
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"errors": [
{
"message": "Input type \"ProfileDetail\" does not have a field \"address\".",
"locations": [
{
"line": 3,
"column": 21
}
]
},
{
"message": "Input type \"Movie\" does not have a field \"episodes\".",
"locations": [
{
"line": 3,
"column": 21
}
]
},
{
"message": "Input type \"Info\" does not have a field \"dir\".",
"locations": [
{
"line": 3,
"column": 21
}
]
}
]
}
4 changes: 2 additions & 2 deletions ballerina-tests/graphql-subgraph-test-suite/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.1"
version = "2.12.2"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand Down Expand Up @@ -274,7 +274,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "mime"
version = "2.10.0"
version = "2.10.1"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.1"
version = "2.12.2"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -314,7 +314,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "mime"
version = "2.10.0"
version = "2.10.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "io"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/graphql-test-common/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.1"
version = "2.12.2"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand Down Expand Up @@ -269,7 +269,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "mime"
version = "2.10.0"
version = "2.10.1"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down Expand Up @@ -332,7 +332,7 @@ modules = [
[[package]]
org = "ballerina"
name = "time"
version = "2.4.0"
version = "2.4.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand Down
6 changes: 3 additions & 3 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.1"
version = "2.12.2"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand Down Expand Up @@ -282,7 +282,7 @@ modules = [
[[package]]
org = "ballerina"
name = "mime"
version = "2.10.0"
version = "2.10.1"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down Expand Up @@ -359,7 +359,7 @@ modules = [
[[package]]
org = "ballerina"
name = "time"
version = "2.4.0"
version = "2.4.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand Down
12 changes: 11 additions & 1 deletion ballerina/field_validator_visitor.bal
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,14 @@ class FieldValidatorVisitor {
__Type argType = getOfType(inputValue.'type);
__InputValue[]? inputFields = argType?.inputFields;
if inputFields is __InputValue[] {
string[] keys = variableValues.keys();
foreach __InputValue subInputValue in inputFields {
if getOfType(subInputValue.'type).name == UPLOAD {
return;
}
if variableValues.hasKey(subInputValue.name) {
int? index = keys.indexOf(subInputValue.name);
if index is int {
_ = keys.remove(index);
anydata fieldValue = variableValues.get(subInputValue.name);
if fieldValue is Scalar {
if getOfType(subInputValue.'type).kind == ENUM {
Expand Down Expand Up @@ -370,6 +373,13 @@ class FieldValidatorVisitor {
}
}
}
if keys.length() > 0 {
foreach string 'key in keys {
string expectedTypeName = getOfTypeName(argType);
string message = string `Input type "${expectedTypeName}" does not have a field "${'key}".`;
self.errors.push(getErrorDetailRecord(message, location));
}
}
} else {
string expectedTypeName = getOfTypeName(inputValue.'type);
string listError = getListElementError(self.argumentPath);
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed
- [[#7317] Fix Service Crashing when Input Object Type Variable Value Includes an Additional Field](https://github.com/ballerina-platform/ballerina-library/issues/7317)

## [1.14.0] - 2024-08-20

### Added
Expand Down

0 comments on commit 9020ffc

Please sign in to comment.