-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GitHub Actions] Commit generated GraphQL client
- Loading branch information
1 parent
6257be5
commit 2feeca7
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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<anydata> variables = {"name": name}; | ||
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables); | ||
return <DistrictAndCityByProvinceResponse> check performDataBinding(graphqlResponse, DistrictAndCityByProvinceResponse); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
public type DistrictAndCityByProvinceResponse record {| | ||
map<json?> __extensions?; | ||
record {| | ||
record {| | ||
record {| | ||
string name_en; | ||
|} name; | ||
record {| | ||
record {| | ||
string name_en; | ||
|} name; | ||
record {| | ||
record {| | ||
string name_en; | ||
|} name; | ||
|}[] cities; | ||
|}[] districts; | ||
|} province; | ||
|} geo; | ||
|}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import ballerina/graphql; | ||
|
||
type OperationResponse record {| anydata...; |}|record {| anydata...; |}[]|boolean|string|int|float|(); | ||
|
||
type DataResponse record {| | ||
map<json?> __extensions?; | ||
OperationResponse ...; | ||
|}; | ||
|
||
isolated function performDataBinding(json graphqlResponse, typedesc<DataResponse> targetType) | ||
returns DataResponse|graphql:RequestError { | ||
do { | ||
map<json> responseMap = <map<json>>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); | ||
} | ||
} |