Skip to content

Commit

Permalink
Add GraphQL schema (manual) and add client generation script
Browse files Browse the repository at this point in the history
  • Loading branch information
rukmal committed Sep 20, 2022
1 parent ec9e3c1 commit 720f288
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 16 deletions.
16 changes: 16 additions & 0 deletions api/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.DEFAULT_GOAL := help

# GraphQL
#######

.PHONY: generate_client
generate_client: ## Generate client for the GraphQL API, from the schema in `schema/`
cd schema && bal graphql -i ./graphql.config.yaml -o ../../client


# Util
#######

.PHONY: help
help: # See: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
19 changes: 19 additions & 0 deletions api/schema/documents/geo_data.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
query DistrictAndCityByProvince($name: String!) {
geo {
province(name: $name) {
name {
name_en
}
districts {
name {
name_en
}
cities {
name {
name_en
}
}
}
}
}
}
3 changes: 3 additions & 0 deletions api/schema/graphql.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
schema: "./schema.graphql"
documents:
- "./documents/geo_data.graphql"
45 changes: 45 additions & 0 deletions api/schema/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
type CityData {
name: LocalizedName!
district: DistrictData!
}

type DistrictData {
name: LocalizedName!
province: ProvinceData!
cities: [CityData!]!
}

type GeoData {
province(name: String!): ProvinceData!
district(name: String!): DistrictData!
city(name: String!): CityData!
}

"""
Localized names in English, Sinhala, and Tamil.
Names are stored with a `name_` prefix, followed
by the respective ISO 639-1 language code.
This record requires an English name, `name_en`.
"""
type LocalizedName {
"""Name in English"""
name_en: String!

"""Name in Tamil, தமிழ்"""
name_ta: String!

"""Name in Sinhala, සිංහල"""
name_si: String!
}

type ProvinceData {
name: LocalizedName!
districts: [DistrictData!]!
}

type Query {
geo: GeoData!
}

15 changes: 0 additions & 15 deletions api/tests/province.bal

This file was deleted.

1 change: 0 additions & 1 deletion db/Config.toml

This file was deleted.

0 comments on commit 720f288

Please sign in to comment.