How RapidQL Works?

In this section, we will explain a bit about how RapidQL works under the hood. The current implementation of RapidQL can be parsed and queried using NodeJS. Expect more languages to roll out soon.

Structure

RapidQL is essentially structured like a tree. Every query is made up of function nodes or leaf nodes. Function nodes are what query APIs or databases and every RapidQL query begins with a root function node. Take a look at the diagram below:

961

This is a model of a RapidQL query that gets all the users from a MySQL database then runs their email through an email validation API called Mailbox Layer. When this query is parsed and run, the RapidQL engine assesses this query in a breadth-first manor starting at the root function.

Once the root function returns all the data it was asked for (in this case, username, email, and profile_image) the child function nodes are then assessed (the user's email is passed to the Mailbox Layer API to return a validation confidence score). This is the same query written in RapidQL syntax:

{
  MySQL.Demo.users.find() {
    username,
    email,
    profile_image,
    Http.post(
      url: 'https://Mailboxlayervolodimir.kudriachenkoV1.p.rapidapi.com/checkEmail',
      params: {
        email: 'email',
        apiKey: '*****************'
      }
    ){
      score 
    }
  }
}

In the above query, once the MySQL database returns all users, the subsequent child nodes are assessed in parallel for every user. This ensures the query is as fast as possible.

Context Variables

Every RapidQL query can also take a context object as a second argument. This context object allows one to define commonly used variables as constants. Take a look at this query below:

rql.query(
`{
    RapidAPI.YelpAPI.getAccessToken(appId: appId, appSecret: appSecret) {
        RapidAPI.YelpAPI.getBusinesses(accessToken: yelpAccessToken, location: "san francisco") {
            businesses {
                name,
                display_phone,
                coordinates {
                    RapidAPI.UberRide.getProductsPrices(accessToken: uberAccessToken, startLatitude: currentLatitude, startLongitude: currentLongitude, endLatitude: latitude, endLongitude: longitude) {
                        prices {
                            display_name,
                            estimate,
                            duration
                        }
                    }
                }
            }
        }
    }
}`,
{
  "currentLatitude": "37.792955",
  "currentLongitude": "-122.404794",
  "appId": "****",
  "appSecret": "****",
  "userAccessToken": "****",
  "yelpAccessToken": "****"
})

rql.query() has been passed two different arguments: a query and a context. The context object has defined latitude, longitude, and any authentication credentials as constants. Now, throughout the query, we can easily use those constants as variables. Also, if we want to alter the parameters of the query in any way, we only have to change the context object itself.