Skip to content

Commit

Permalink
Add client for GraphQL API
Browse files Browse the repository at this point in the history
  • Loading branch information
rukmal committed Sep 20, 2022
1 parent 720f288 commit 355d221
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
8 changes: 8 additions & 0 deletions client/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
org = "avinyafoundation"
name = "global_data_client"
version = "1.0.0"
distribution = "2201.1.1"

[build-options]
observabilityIncluded = true
328 changes: 328 additions & 0 deletions client/Dependencies.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
# AUTO-GENERATED FILE. DO NOT MODIFY.

# This file is auto-generated by Ballerina for managing dependency versions.
# It should not be modified by hand.

[ballerina]
dependencies-toml-version = "2"

[[package]]
org = "avinyafoundation"
name = "global_data_client"
version = "1.0.0"
dependencies = [
{org = "ballerina", name = "graphql"},
{org = "ballerina", name = "http"},
{org = "ballerinai", name = "observe"}
]
modules = [
{org = "avinyafoundation", packageName = "global_data_client", moduleName = "global_data_client"}
]

[[package]]
org = "ballerina"
name = "auth"
version = "2.3.1"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "regex"}
]

[[package]]
org = "ballerina"
name = "cache"
version = "3.2.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "task"},
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerina"
name = "crypto"
version = "2.2.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerina"
name = "file"
version = "1.3.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "os"},
{org = "ballerina", name = "regex"},
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerina"
name = "graphql"
version = "1.3.3"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "file"},
{org = "ballerina", name = "http"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "jwt"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.value"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "oauth2"},
{org = "ballerina", name = "regex"},
{org = "ballerina", name = "websocket"}
]
modules = [
{org = "ballerina", packageName = "graphql", moduleName = "graphql"},
{org = "ballerina", packageName = "graphql", moduleName = "graphql.parser"}
]

[[package]]
org = "ballerina"
name = "http"
version = "2.3.0"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "file"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "jwt"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.decimal"},
{org = "ballerina", name = "lang.int"},
{org = "ballerina", name = "lang.runtime"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "lang.value"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "oauth2"},
{org = "ballerina", name = "observe"},
{org = "ballerina", name = "regex"},
{org = "ballerina", name = "time"},
{org = "ballerina", name = "url"}
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"}
]

[[package]]
org = "ballerina"
name = "io"
version = "1.2.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
]

[[package]]
org = "ballerina"
name = "jballerina.java"
version = "0.0.0"

[[package]]
org = "ballerina"
name = "jwt"
version = "2.3.1"
dependencies = [
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.int"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "regex"},
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerina"
name = "lang.__internal"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "lang.array"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.__internal"}
]

[[package]]
org = "ballerina"
name = "lang.decimal"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.int"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.object"
version = "0.0.0"

[[package]]
org = "ballerina"
name = "lang.runtime"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.string"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.value"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "log"
version = "2.3.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"},
{org = "ballerina", name = "observe"}
]

[[package]]
org = "ballerina"
name = "mime"
version = "2.3.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.int"}
]

[[package]]
org = "ballerina"
name = "oauth2"
version = "2.3.1"
dependencies = [
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerina"
name = "observe"
version = "1.0.5"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "os"
version = "1.3.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "regex"
version = "1.3.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.string"}
]

[[package]]
org = "ballerina"
name = "task"
version = "2.2.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerina"
name = "time"
version = "2.2.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "url"
version = "2.2.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "websocket"
version = "2.3.0"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "http"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "jwt"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.runtime"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "lang.value"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "oauth2"},
{org = "ballerina", name = "regex"},
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerinai"
name = "observe"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "observe"}
]
modules = [
{org = "ballerinai", packageName = "observe", moduleName = "observe"}
]


17 changes: 17 additions & 0 deletions client/geo_data_client.bal
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);
}
}
20 changes: 20 additions & 0 deletions client/types.bal
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;
|};
Loading

0 comments on commit 355d221

Please sign in to comment.