Skip to content

Commit

Permalink
Add compile time schema generation for default parameters (#1586)
Browse files Browse the repository at this point in the history
Co-authored-by: Thisaru Guruge <[email protected]>
  • Loading branch information
MohamedSabthar and ThisaruGuruge authored Oct 16, 2023
1 parent 503d327 commit 1d9b3c5
Show file tree
Hide file tree
Showing 49 changed files with 1,519 additions and 333 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build-with-bal-test-graalvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ jobs:
lang_version: ${{ inputs.lang_version }}
native_image_options: '-J-Xmx7G ${{ inputs.native_image_options }}'
additional_ubuntu_build_flags: '-x :graphql-compiler-plugin-tests:test'
additional_windows_build_flags: '-x :graphql-compiler-plugin-tests:test'
# TODO : Enable after fixing this issue : https://github.com/ballerina-platform/ballerina-lang/issues/38882
# additional_windows_build_flags: '-x :graphql-compiler-plugin-tests:test'
additional_windows_build_flags: '-x test'
14 changes: 7 additions & 7 deletions ballerina-tests/objects.bal
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public isolated distinct service class Starship {

public enum Sex {
MALE = "male",
FEMAELE = "female"
FEMALE = "female"
}

public type Animalia distinct service object {
Expand Down Expand Up @@ -244,17 +244,17 @@ public distinct service class Dog {
}

Animalia[] animals = [
new Horse(1, FEMAELE, "LUNA"),
new Horse(1, FEMALE, "LUNA"),
new Horse(2, MALE, "WALTER"),
new Donkey(3, MALE, "MAX"),
new Donkey(4, FEMAELE, "WINNIE"),
new Donkey(4, FEMALE, "WINNIE"),
new Donkey(5, MALE, "RUDY"),
new Horse(6, FEMAELE, "SKYE"),
new Horse(6, FEMALE, "SKYE"),
new Horse(7, MALE, "COOPER"),
new Dog(8, MALE, "REX"),
new Dog(9, FEMAELE, "COOKIE"),
new Dog(10, FEMAELE, "DAISY"),
new Mule(11, FEMAELE, "LARA")
new Dog(9, FEMALE, "COOKIE"),
new Dog(10, FEMALE, "DAISY"),
new Mule(11, FEMALE, "LARA")
];

public isolated service class ReviewData {
Expand Down
6 changes: 4 additions & 2 deletions ballerina-tests/tests/10_introspection_queries.bal
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function dataProviderIntrospection() returns map<[string, string, json]> {
string url7 = "http://localhost:9091/documentation";
string url8 = "http://localhost:9090/deprecation";
string url9 = "http://localhost:9091/id_annotation_1";
string url10 = "http://localhost:9090/defaultParam";

map<[string, string, json]> dataSet = {
"1": [url1, "complex_introspection_query"],
Expand All @@ -61,7 +62,7 @@ function dataProviderIntrospection() returns map<[string, string, json]> {
"20": [url2, "type_introspection_on_non_existing_type"],
"21": [url2, "type_introspection_without_fields"],
"22": [url2, "type_introspection"],
"23": [url6, "introspection_on_inputs_with_default_values"],
"23": [url10, "introspection_on_inputs_with_default_values"],
"24": [url2, "directive_locations"],
"25": [url7, "documentation"],
"26": [url8, "deprecated_fields_introspection"],
Expand All @@ -72,7 +73,8 @@ function dataProviderIntrospection() returns map<[string, string, json]> {
"31": [url2, "typename_introspection_on_type_record"],
"32": [url2, "typename_introspection_on_schema_introspection"],
"33": [url2, "typename_introspection_on_field"],
"34": [url9, "id_introspection_query"]
"34": [url9, "id_introspection_query"],
"35": [url10, "introspection_on_input_object_having_defaultable_fields"]
};
return dataSet;
}
17 changes: 17 additions & 0 deletions ballerina-tests/tests/object_types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,20 @@ public isolated distinct service class BookData {
return self.book.title;
}
}

distinct service class NestedField {
resource function get multipleParams(
int a = 1,
float b = 2.0,
decimal c = 1e-10,
string d = "value",
boolean e = true,
int? f = DEFAULT_INT_VALUE,
Sex g = MALE,
InputObject h = {name: "name2", bmiHistory: [30.0 , 29.0, 20.0d]},
InputObject[] i = [
{name: "name3", bmiHistory: [30.0 , 29.0]},
{name: "name4", bmiHistory: [2.9e1, 31.0]}
],
@graphql:ID string[] j = ["id1"]) returns string? => ();
}
15 changes: 15 additions & 0 deletions ballerina-tests/tests/records.bal
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,18 @@ type AuthorRow record {|
readonly int id;
string name;
|};

type InputObject record {|
string name = "name";
decimal[]? bmiHistory = [1.0, 3];
*InputObject2;
|};

type InputObject2 record {|
Sex sex = MALE;
*InputObject3;
|};

type InputObject3 record {|
int age = 30;
|};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
__type(name: "InputObject") {
name
inputFields {
name
defaultValue
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
query {
__schema {
queryType {
fields {
name
args {
defaultValue
type {
kind
name
ofType {
kind
name
}
}
}
}
}
{
query: __type(name: "Query") {
fields {
name
args {
name
defaultValue
}
}
}
mutation: __type(name: "Mutation") {
fields {
name
args {
name
defaultValue
}
}
}
subscription: __type(name: "Subscription") {
fields {
name
args {
name
defaultValue
}
}
}
nestedFieldsWithDefaultParam: __type(name: "NestedField") {
fields {
name
args {
name
defaultValue
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"data": {
"__type": {
"name": "InputObject",
"inputFields": [
{ "name": "name", "defaultValue": "\"name\"" },
{ "name": "bmiHistory", "defaultValue": "[1.0, 3]" },
{ "name": "sex", "defaultValue": "MALE" },
{ "name": "age", "defaultValue": "30" }
]
}
}
}
Loading

0 comments on commit 1d9b3c5

Please sign in to comment.