From ccf958a56acce9d69e556548f0273280d2705594 Mon Sep 17 00:00:00 2001 From: Rukmal Weerawarana Date: Tue, 27 Sep 2022 19:46:40 +0530 Subject: [PATCH] Add workflow to generate client --- .github/workflows/push.yml | 29 +++++++++++++++++++++++++++-- client/Ballerina.toml | 2 +- client/Dependencies.toml | 2 +- client/Package.md | 1 + client/geo_data_client.bal | 17 ----------------- client/types.bal | 20 -------------------- client/utils.bal | 23 ----------------------- 7 files changed, 30 insertions(+), 64 deletions(-) create mode 100644 client/Package.md delete mode 100644 client/geo_data_client.bal delete mode 100644 client/types.bal delete mode 100644 client/utils.bal diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 6018218..ae79d4e 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -1,4 +1,4 @@ -name: GraphQL API tests +name: Global data service push workflow env: REGISTRY: ghcr.io @@ -50,7 +50,7 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - bal-test: + api-test: name: GraphQL API Tests runs-on: ubuntu-22.04 needs: push-db-container @@ -85,3 +85,28 @@ jobs: args: test env: WORKING_DIR: api + generate-graphql-client-job: + name: Generate GraphQL Client + needs: api-test + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + if: ${{ !env.ACT }} # Only run on GitHub Actions + uses: actions/checkout@v3 + - name: Generate GraphQL Client + if: ${{ !env.ACT }} + uses: ballerina-platform/ballerina-action@394eb82cc07e020948fee8d1474143ae393147f4 + with: + args: graphql -i graphql.config.yaml -o ../../client/ + env: + WORKING_DIR: api/schema + - name: Display changes in generated client + run: | + git add . --force + git diff HEAD + - name: Commit sample artifacts to Pull Request + uses: EndBug/add-and-commit@v9 # See: https://github.com/marketplace/actions/add-commit + with: + add: "client --force" + default_author: github_actions + message: "[GitHub Actions] Commit generated GraphQL client" diff --git a/client/Ballerina.toml b/client/Ballerina.toml index a2a7c83..9d97817 100644 --- a/client/Ballerina.toml +++ b/client/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "avinyafoundation" name = "global_data_client" -version = "1.0.0" +version = "0.1.2" distribution = "2201.1.1" [build-options] diff --git a/client/Dependencies.toml b/client/Dependencies.toml index b90cd1e..3d0ca35 100644 --- a/client/Dependencies.toml +++ b/client/Dependencies.toml @@ -9,7 +9,7 @@ dependencies-toml-version = "2" [[package]] org = "avinyafoundation" name = "global_data_client" -version = "1.0.0" +version = "0.1.2" dependencies = [ {org = "ballerina", name = "graphql"}, {org = "ballerina", name = "http"}, diff --git a/client/Package.md b/client/Package.md new file mode 100644 index 0000000..5d3398d --- /dev/null +++ b/client/Package.md @@ -0,0 +1 @@ +# Avinya Foundation Global Data Service diff --git a/client/geo_data_client.bal b/client/geo_data_client.bal deleted file mode 100644 index f77f806..0000000 --- a/client/geo_data_client.bal +++ /dev/null @@ -1,17 +0,0 @@ -import ballerina/http; -import ballerina/graphql; - -public isolated client class Geo_dataClient { - final graphql:Client graphqlClient; - public isolated function init(string serviceUrl, http:ClientConfiguration clientConfig = {}) returns graphql:ClientError? { - graphql:Client clientEp = check new (serviceUrl, clientConfig); - self.graphqlClient = clientEp; - return; - } - remote isolated function DistrictAndCityByProvince(string name) returns DistrictAndCityByProvinceResponse|graphql:ClientError { - string query = string `query DistrictAndCityByProvince($name:String!) {geo {province(name:$name) {name {name_en} districts {name {name_en} cities {name {name_en}}}}}}`; - map variables = {"name": name}; - json graphqlResponse = check self.graphqlClient->executeWithType(query, variables); - return check performDataBinding(graphqlResponse, DistrictAndCityByProvinceResponse); - } -} diff --git a/client/types.bal b/client/types.bal deleted file mode 100644 index 964f2df..0000000 --- a/client/types.bal +++ /dev/null @@ -1,20 +0,0 @@ -public type DistrictAndCityByProvinceResponse record {| - map __extensions?; - record {| - record {| - record {| - string name_en; - |} name; - record {| - record {| - string name_en; - |} name; - record {| - record {| - string name_en; - |} name; - |}[] cities; - |}[] districts; - |} province; - |} geo; -|}; diff --git a/client/utils.bal b/client/utils.bal deleted file mode 100644 index 5b0c224..0000000 --- a/client/utils.bal +++ /dev/null @@ -1,23 +0,0 @@ -import ballerina/graphql; - -type OperationResponse record {| anydata...; |}|record {| anydata...; |}[]|boolean|string|int|float|(); - -type DataResponse record {| - map __extensions?; - OperationResponse ...; -|}; - -isolated function performDataBinding(json graphqlResponse, typedesc targetType) - returns DataResponse|graphql:RequestError { - do { - map responseMap = >graphqlResponse; - json responseData = responseMap.get("data"); - if (responseMap.hasKey("extensions")) { - responseData = check responseData.mergeJson({"__extensions": responseMap.get("extensions")}); - } - DataResponse response = check responseData.cloneWithType(targetType); - return response; - } on fail var e { - return error graphql:RequestError("GraphQL Client Error", e); - } -}