Guide to build Meal Delivery App using Hypi’s low code API

Hypi’s low code platform offers wide features to implement various kinds of data driven applications. It paved the way for creating an online presence by building software with ease.

In this post, let’s explore how to build a meal delivery app using Hypi’s low code APIs. Ultimately, you will have your own clone version of UberEats, JustEat, Olo, Zomato…(and the list goes on!)

In this guide, we will implement the following key features of the Meal delivery app.

  • Store meal options with different categories
  • Store restaurant details serving various meal options
  • Create user login and save user details
  • Create orders and calculate the bill amount
  • Store delivery information

***Please note that these are only the back-end functions. Watch this space for front end functionality in the future!

An important step to build any data driven application is to implement a data model or write a schema. Here is your sample schema for the meal delivery app.

  1. User type stores the user information and the order information placed by him.
  2. Meal type stores various types of Meal details and Restaurant data type stores information about various restaurants serving different meals.
  3. PurchaseOrder type stores meal information and quantity selected by the user
  4. Order type stores the Meal Order information
type User {
    user : Account
    address: Address
    orders: [Order!]
}
type Restaurant {
    name: String
    address: Address
    meals: [Meal]
    rating: Float
} 
type Meal {
    name: String
    description: String
    price: Float
    images: [Image!]
    category: String
    delivryTime: Float
}
type PurchaseOrder {
  meal: Meal!
  quantity: Int!
  orderAmount: Float
  username: String
}
type Order {
    amount : Float
    deliveryFee: Float
    tax : Float
    total: Float
    user: User
    meal: [PurchaseOrder!]
    purchaseDate: DateTime
    deliveredBy : String
    deliveryTime: DateTime
    delivered: Boolean
}    

Create a Meal Delivery App on Hypi’s low code platform. Create a release and an instance. Enter the above schema in the release.

Now, let’s implement the following use cases in the Meal Delivery App.


  • Store meal options with different categories
  • Store restaurant details serving various meal options

To populate the front end, insert data in the Restaurant and Meals data types. Check this guide on how to insert data in an instance.

Alternatively, you may use Zapier and Hypi’s webhooks to insert the data stored in a Google Sheet.

  1. Create Meal objects
mutation {
  upsert(
    values: {
      Meal: [
        {
          name: "Pasta"
          description: "With white sauce"
          price: 10.99
          category: "Italian"
          delivryTime: 45
        }
        {
          name: "Pizza"
          description: "Margherita Pizza"
          price: 7.99
          category: "Italian"
          delivryTime: 45
        }
        {
          name: "Dosa"
          description: "Masala Dosa"
          price: 2.99
          category: "Indian"
          delivryTime: 20
        }
        {
          name: "French Fries"
          description: "Potato Fries"
          price: 1.99
          category: "Belgian"
          delivryTime: 15
        }
      ]
    }
  ) {
    id
  }
}
#result
{
  "data": {
    "upsert": [
      {
        "id": "01FMHSWZTV6PXCGA2Y0XAR9SVX"
      },
      {
        "id": "01FMHSWZTY219VF0K553WY3DBB"
      },
      {
        "id": "01FMHSWZV0JKQZG1792VWQEAHK"
      },
      {
        "id": "01FMHSWZV4XJZZPF6X39EBR9A5"
      }
    ]
  }
}
  1. Create Restaurant objects
mutation {
  upsert(
    values: {
      Restaurant: [
        {
          name: "Yummy Italian"
          address: {
            door: "1"
            street: "17"
            town: "Weikfield"
            city: "Rome"
            country: { name: "Italy" }
            postCode: "123456"
          }
          meals: [
            { hypi: { id: "01FMHSWZTV6PXCGA2Y0XAR9SVX" } }
            { hypi: { id: "01FMHSWZTY219VF0K553WY3DBB" } }
          ]
          rating: 5.0
        }
        {
          name: "Soft Dosas"
          address: {
            door: "2"
            street: "12"
            city: "Chennai"
            country: { name: "India" }
            postCode: "666666"
          }
          meals: [{ hypi: { id: "01FMHSWZV0JKQZG1792VWQEAHK" } }]
          rating: 5.0
        }
        {
          name: "Crunchy Fries"
          address: {
            door: "3"
            street: "23"
            city: "Brussels"
            country: { name: "Belgium" }
            postCode: "888888"
          }
          meals: [{ hypi: { id: "01FMHSWZV4XJZZPF6X39EBR9A5" } }]
          rating: 5.0
        }
      ]
    }
  ) {
    id
  }
}
#result
{
  "data": {
    "upsert": [
      {
        "id": "01FMHTQK7Q90M7HXXRJS01M6H9"
      },
      {
        "id": "01FMHTQK8BJEKB6FEC1G8HDQ56"
      },
      {
        "id": "01FMHTQK8TA2NV3Y36QKKBN6Q1"
      }
    ]
  }
}
  1. Create user login and save user details

When a user creates a login, authenticate user accounts using this guide.

Insert the user profile in the User Data type. Use the hypi.id of the created Account objects to store in the user field of the User data type. You may write your own User Defined function to create User objects.

mutation {
  upsert(
    values: {
      User: {
        user: {hypi:{id:"01FMHVCPWX2YCP355P3TA87B7R"}}
      }
    }
  ) {
    id
  }
}
#result
{
  "data": {
    "upsert": [
      {
        "id": "01FMHVKB94TAM11RTV69XSQHGR"
      }
    ]
  }
}
  1. Create order and calculate bill amount

When the user selects a meal and quantity of the meal, create the PurchaseOrder object of that meal. You may write your own User Defined function to create PurchaseOrder objects.

i) Create PurchaseOrder objects using the hypi.id of the selected Meal objects.

mutation {
  upsert(
    values: {
      PurchaseOrder: [
        { meal: { hypi: { id: "01FMHSWZTV6PXCGA2Y0XAR9SVX" } }, quantity: 3 }
        { meal: { hypi: { id: "01FMHSWZV4XJZZPF6X39EBR9A5" } }, quantity: 2 }
      ]
    }
  ) {
    id
  }
}

{
  "data": {
    "upsert": [
      {
        "id": "01FMJBKK2T03XTQD2VEGNTRV6D"
      },
      {
        "id": "01FMHW1GMH19NEXCYA1FV5EGV3"
      }
    ]
  }
}

ii) To calculate the total amount for the individual Purchase Orders, edit schema to enter below User Defined Function in the Mutation data type. It multiplies the meal price by the quantity and saves the purchase order amount in the respective PurchaseOrder Object. It also stores the user name in the PurchaseOrder object.

calculateAmount(a: ID, b:ID):Json @tan(type:Groovy, inline: """
def price = gql(\"""{get(type:PurchaseOrder,id:"$a"){...on PurchaseOrder{meal{price}}}}\""").data.get.meal.price
def quantity = gql(\"""{get(type: PurchaseOrder,id:"$a"){...on PurchaseOrder {quantity}}}\""").data.get.quantity
float amount = (float)price * (float)quantity
def user = gql(\"""{get(type: User,id:"$b"){...on User{user{username}}}}\""").data.get.user.username
return upsert([
          PurchaseOrder: [
             orderAmount: amount,
             username: user,
             hypi:
                [
                 id: a
                ]         
            
          ]
        ]
    )       
""")

Sample Query:
mutation{
calculateAmount(a:"01FMMF00J4WH8RYAZX2C3EWSQX",b:"01FMHVKB94TAM11RTV69XSQHGR")
}

iii) Now is the time to create an Order object and calculate total Bill Amount. Use the hypi.id s of the PurchaseOrder objects to store Meal information in the order.

mutation {
  upsert(
    values: {
      Order: {
        deliveryFee: 0.99
        tax: 0.99
        user: { hypi: { id: "01FMHVKB94TAM11RTV69XSQHGR" } }
        meal: [
          { hypi: { id: "01FMMF00J4WH8RYAZX2C3EWSQX" } }
          { hypi: { id: "01FMMF00J7XYGJP6Y03V69KP9Z" } }
        ]
        purchaseDate: "2021-12-16"
      }
    }
  ) {
    id
  }
}
#
{
  "data": {
    "upsert": [
      {
        "id": "01FMMPKQ2X5CJRB7AQBD4F1RB7"
      }
    ]
  }
}

iv) To calculate the total amount for the Order, edit schema to enter below User Defined Function in the Mutation data type. It aggregates the amount of the purchase orders to calculate sum and then adds delivery fee and tax to calculate the total bill amount of the order. It stores the calculated amount in the Order object.

calculateTotal(a:ID, b:ID):Json @tan(type:Groovy, inline: """   
def user = gql(\"""{get(type:User,id:"$b"){...on User{user{username}}}}\""").data.get.user.username
def sumAmount = gql(\"""{
aggregate {
        purchaseOrder(where: "username='$user'") {
        orderAmount {
                    sum
                }
            }
        }
}\""").data.aggregate.purchaseOrder.orderAmount.sum
def tax = gql(\"""{get(type: Order,id:"$a"){...on Order {tax}}}\""").data.get.tax
def deliveryFee = gql(\"""{get(type: Order,id:"$a"){...on Order {deliveryFee}}}\""").data.get.deliveryFee
def total = sumAmount + tax + deliveryFee
return upsert([
          Order: [
             amount: sumAmount,
             total: total,
             hypi:
                [
                 id: a
                ]       
            ]
        ]
    )       
""")

Sample Query
mutation{
calculateTotal(a:"01FMMPKQ2X5CJRB7AQBD4F1RB7",b:"01FMHVKB94TAM11RTV69XS
QHGR")
}
  1. Store delivery information

Save the delivery information in the Order object and save the Order object in the User object to complete the Order delivery.

mutation {
  upsert(
    values: {
      Order: {
        hypi: { id: "01FMMPKQ2X5CJRB7AQBD4F1RB7" }
        deliveredBy: "HYPI"
        deliveryTime: "2021-11-19T11:39:06Z"
        delivered: true
      }
    }
  ) {
    id
  }
}
mutation {
  upsert(
    values: {
      User: {
        hypi: { id: "01FMHVKB94TAM11RTV69XSQHGR" }
        orders: { hypi: { id: "01FMMPKQ2X5CJRB7AQBD4F1RB7" } }
      }
    }
  ) {
    id
  }
}

This completes some of the basic steps to implement a Meal Delivery App using Hypi’s low code API! There may be many other nitty-gritty details needed to implement backend functions of the Meal Delivery App. Our documentation pages will guide you throughout the process.

At last, Hypi is happy to help you with implementation of your own Meal Delivery App clone!

1 Like