/federated-quran

POC microservice-based federated GrapghQL API for Quran metadata with user Authentication and Authorisation

Primary LanguageJavaScript

federated-quran

POC microservice-based federated GrapghQL API for Quran metadata with user Authentication and Authorisation. (all the buzz words in one sentence, but it's actually true ¯\(ツ)/¯)

Architecture

This is a POC, it exposes a GQL api to retrive quran metadata like "Juz'" and "Surah". We can also use the users service to create and auth users. image

API

Here I'll discuss the overall api specs. For details regarding other services, you can read their docs here:

Juz

type Juz {
  number: Int!
  surahIndex: Int!
  ayah: Int!
}

Surah

type Surah {
  index: Int!
  name: String!
  numberOfAyahs: Int!
  revelationType: String!
}

Federation

In Juz, we can fetch the entire surah instead of its index. This is one benifit of federation

  extend type Surah @key(fields: "index") {
    index: Int!
  }

  type Juz {
    number: Int!
    surahIndex: Int!
    surah: Surah!
    ayah: Int!
  }

This allows us to write such query normally to get a "Juz'" and the full "Surah" details of it

query getJuzStartSurah {
  getJuz (index: 3){
    number
    ayah
    surah {
      name
      revelationType
    }
  }
}

Output:

{
  "number": 3,
  "ayah": 253,
  "surah": {
    "name": "Al-Baqara",
    "revelationType": "Medinan"
  }
}

Installation

git clone https://github.com/mhashim6/federated-quran.git && cd federated-quran

Run

docker compose up -d

Then head to http://localhost and go to the Apollo Sandbox to play with the API