How to generate a Meal Plan based on a template

The document will guide you through the steps to generate a meal plan based on a meal plan template

Overview

Different dietary plans do not require following a 7-day meal plan or having a fixed list of recipes generated randomly based on some parameters. Instead, people, including coaches, want to get more control over what they choose in a dietary plan.

Managing meal plan templates gives people the freedom to control what to choose to generate a meal plan, from the number of days to the recipes according to a user's needs.

Requirements

  • None

Considerations

  • Meal Plan Template endpoints only require sending the token within the header.

API Endpoints to use

Through the example, use the following endpoints in the same order as they are listed below:

  • Use any of the recipe search queries to find the recipes that best suit your dietary requirements

  • The createMealPlanTemplate to create a meal plan template according to your requirements.

  • The mealPlanTemplates to list the recent meal plan template created.

  • The generateMealPlan to generate the meal plan including the meal plan template ID.

  • The mealPlan to verify that the meal plan was generated based on the meal plan template.

Examples

The following example describes how to create a 3-day vegan meal plan based on the information added in a meal plan template. Find the characteristics of the meal plan to create as follows:

  • Number of days: 3

  • Meal Plan Template type: From Scratch

  • Meal Type: BREAKFAST, LUNCH, DINNER

  • Number of Servings: 2, 3, 2 respectively

Code Example

Find all the steps detailed below in this graphqlbin. Modify the code accordingly.

Step by Step Example

Follow the 5 steps below to generate a meal plan based on a meal plan template.

STEP 1: Get the List of recipes

In the case of the example, use the recipeSearch query to find vegan recipes:

Request:

{
  recipeSearch(
    query: "bagels"
    dietaryTag: VEGAN
    first: 2
) {
    edges {
      node {
        name 
        id
        author
        tags
      }
    }
  }
}

Response:

{
  "data": {
    "recipeSearch": {
      "edges": [
        {
          "node": {
            "name": "Bagels",
            "id": "UmVjaXBlOmZjZDA0YTdmLWZjMTktNDljYi1iZDhjLTliNTFlM2ZmMDBjZA==",
            "author": "Brown Eyed Baker",
            "tags": [
              "VEGETARIAN",
              "PLANT_BASED",
              "DAIRY_FREE",
              "VEGAN",
              "Breakfast"
            ]
          }
        },
        {
          "node": {
            "name": "Bagels",
            "id": "UmVjaXBlOjMxYTVjZjk5LTE4NjctNDRiZS1iMmFmLWNkODIwMzg0YTI3OA==",
            "author": "Food.com",
            "tags": [
              "VEGETARIAN",
              "PLANT_BASED",
              "DAIRY_FREE",
              "VEGAN",
              "Breakfast"
            ]
          }
        }
      ]
    }
  }
}

From the response, copy the recipe id-> UmVjaXBlOmZjZDA0YTdmLWZjMTktNDljYi1iZDhjLTliNTFlM2ZmMDBjZA==. This will be later replace in the meal plan template creation.

Repeat the same action until you get all the recipes for the three days.

STEP 2: Create a meal plan template

The following example creates a 3-day meal plan. Copy and replace the IDs you got form the recipeSearch query into each one of the recipeId fields

mutation {
  createMealPlanTemplate(
    name: "Vegan Meal Plan"
    description: "A 3-day vegan meal plan"
    fromScratch: {
      days: [
        {
          meals: [
            {
              recipeId: "UmVjaXBlOmZjZDA0YTdmLWZjMTktNDljYi1iZDhjLTliNTFlM2ZmMDBjZA=="
              mealType: BREAKFAST
              servings: 2
            }
            {
              recipeId: "UmVjaXBlOjE1MDk0MDQxLTYyMWItNGM0Ni04OGViLTUzM2FlNmRlMTI4Zg=="
              mealType: LUNCH
              servings: 3
            }
            {
              recipeId: "UmVjaXBlOjE1MDk0MDQxLTYyMWItNGM0Ni04OGViLTUzM2FlNmRlMTI4Zg=="
              mealType: DINNER
              servings: 2
            }
          ]
        }
        {
          meals: [
            {
              recipeId: "UmVjaXBlOjE2OTBlMjU1LWFhZGUtNDA2Yy05MTJiLWZhYTI0MDVmYTk2Zg=="
              mealType: BREAKFAST
              servings: 2
            }
            {
              recipeId: "UmVjaXBlOjE1MDk0MDQxLTYyMWItNGM0Ni04OGViLTUzM2FlNmRlMTI4Zg=="
              mealType: LUNCH
              servings: 3
            }
            {
              recipeId: "UmVjaXBlOjE1MDk0MDQxLTYyMWItNGM0Ni04OGViLTUzM2FlNmRlMTI4Zg=="
              mealType: DINNER
              servings: 2
            }
          ]
        }
        {
          meals: [
            {
              recipeId: "UmVjaXBlOjMxYTVjZjk5LTE4NjctNDRiZS1iMmFmLWNkODIwMzg0YTI3OA=="
              mealType: BREAKFAST
              servings: 2
            }
            {
              recipeId: "UmVjaXBlOjE1MDk0MDQxLTYyMWItNGM0Ni04OGViLTUzM2FlNmRlMTI4Zg=="
              mealType: LUNCH
              servings: 3
            }
            {
              recipeId: "UmVjaXBlOjE1MDk0MDQxLTYyMWItNGM0Ni04OGViLTUzM2FlNmRlMTI4Zg=="
              mealType: DINNER
              servings: 2
            }
          ]
        }
      ]
    }
  ) {
    message
    success
  }
}
STEP 3: Get the ID of the recently created meal plan template

Use the mealPlanTemplates to find the created meal plan template.

Request:

query {
  mealPlanTemplates {
    edges {
      node {
        id
        description
        createdAt
        coachId
        isPublic
        days {
          day
          meals {
            recipe {
              name
            }
            calories
            numOfServings
          }
        }
      }
    }
  }
}

Response:

{
  "data": {
    "mealPlanTemplates": {
      "edges": [
        {
          "node": {
            "id": "TWVhbFBsYW5UZW1wbGF0ZTo3ODQyMDdkOC1lZjZmLTRlYmYtYTlmNC04YWVjNjQ3NjQ3MTA=",
            "description": "A 3-day vegan meal plan",
            "createdAt": "2022-05-16T20:46:11.146068+00:00",
            "coachId": null,
            "isPublic": false,
            "days": [
              {
                "day": 1,
                "meals": [
                  {
                    "recipe": {
                      "name": "Bagels"
                    },
                    "calories": 293.693491666667,
                    "numOfServings": 2
                  },
                  {
                    "recipe": {
                      "name": "Apple-Orange Smoothie With Yogurt"
                    },
                    "calories": 514.1761,
                    "numOfServings": 3
                  },
                  {
                    "recipe": {
                      "name": "Apple-Orange Smoothie With Yogurt"
                    },
                    "calories": 514.1761,
                    "numOfServings": 2
                  }
                ]
              }
            ]
        }
     }
}

From the response, copy the recipe id-> TWVhbFBsYW5UZW1wbGF0ZTo3ODQyMDdkOC1lZjZmLTRlYmYtYTlmNC04YWVjNjQ3NjQ3MTA=. This will be later replace in the meal plan creation .

STEP 4: Generate the meal plan

Use the GenerateMealPlan to create the meal plan based on the template created before. In the request, use the fromTemplate argument to include the meal templated ID:

Note: You can include either the mealPlan object within the generateMealPlan mutation to retrieve the information of the meal plan created or use the mealPlan query separately to get this information.

Request:

mutation {
  generateMealPlan(
    fromTemplate: "TWVhbFBsYW5UZW1wbGF0ZTo3ODQyMDdkOC1lZjZmLTRlYmYtYTlmNC04YWVjNjQ3NjQ3MTA="
  ) {
    success
    message
    mealPlan {
      day
      date
      meals {
        id
        meal
      }
    }
  }
}

Response:

{
  "data": {
    "generateMealPlan": {
      "success": true,
      "message": "Meal plan generated.",
      "mealPlan": [
        {
          "day": 3,
          "date": "2022-05-20 02:00:00+00:00",
          "meals": [
            {
              "id": "TWVhbDo3MjM5MTc2",
              "meal": "breakfast"
            },
            {
              "id": "TWVhbDo3MjM5MTc3",
              "meal": "lunch"
            },
            {
              "id": "TWVhbDo3MjM5MTc4",
              "meal": "dinner"
            }
          ]
        },
        {
          "day": 2,
          "date": "2022-05-19 02:00:00+00:00",
          "meals": [
            {
              "id": "TWVhbDo3MjM5MTcz",
              "meal": "breakfast"
            },
            {
              "id": "TWVhbDo3MjM5MTc0",
              "meal": "lunch"
            },
            {
              "id": "TWVhbDo3MjM5MTc1",
              "meal": "dinner"
            }
          ]
        },
        {
          "day": 1,
          "date": "2022-05-18 02:00:00+00:00",
          "meals": [
            {
              "id": "TWVhbDo3MjM5MTcw",
              "meal": "breakfast"
            },
            {
              "id": "TWVhbDo3MjM5MTcx",
              "meal": "lunch"
            },
            {
              "id": "TWVhbDo3MjM5MTcy",
              "meal": "dinner"
            }
          ]
        },
        {
          "day": 7,
          "date": "2022-02-08 02:00:00+00:00",
          "meals": [
            {
              "id": "TWVhbDoyNjAyNjg2",
              "meal": "breakfast"
            },
            {
              "id": "TWVhbDoyNjAyNjg3",
              "meal": "snack"
            },
            {
              "id": "TWVhbDoyNjAyNjg4",
              "meal": "lunch"
            },
            {
              "id": "TWVhbDoyNjAyNjg5",
              "meal": "dinner"
            }
          ]
        },
        {
          "day": 6,
          "date": "2022-02-07 02:00:00+00:00",
          "meals": [
            {
              "id": "TWVhbDoyNjAyNjgy",
              "meal": "breakfast"
            },
            {
              "id": "TWVhbDoyNjAyNjgz",
              "meal": "snack"
            },
            {
              "id": "TWVhbDoyNjAyNjg0",
              "meal": "lunch"
            },
            {
              "id": "TWVhbDoyNjAyNjg1",
              "meal": "dinner"
            }
          ]
        },
        {
          "day": 5,
          "date": "2022-02-06 02:00:00+00:00",
          "meals": [
            {
              "id": "TWVhbDoyNjAyNjc4",
              "meal": "breakfast"
            },
            {
              "id": "TWVhbDoyNjAyNjc5",
              "meal": "snack"
            },
            {
              "id": "TWVhbDoyNjAyNjgw",
              "meal": "lunch"
            },
            {
              "id": "TWVhbDoyNjAyNjgx",
              "meal": "dinner"
            }
          ]
        },
        {
          "day": 4,
          "date": "2022-02-05 02:00:00+00:00",
          "meals": [
            {
              "id": "TWVhbDoyNjAyNjc0",
              "meal": "breakfast"
            },
            {
              "id": "TWVhbDoyNjAyNjc1",
              "meal": "snack"
            },
            {
              "id": "TWVhbDoyNjAyNjc2",
              "meal": "lunch"
            },
            {
              "id": "TWVhbDoyNjAyNjc3",
              "meal": "dinner"
            }
          ]
        },
        {
          "day": 3,
          "date": "2022-02-04 02:00:00+00:00",
          "meals": [
            {
              "id": "TWVhbDoyNjAyNjcw",
              "meal": "breakfast"
            },
            {
              "id": "TWVhbDoyNjAyNjcx",
              "meal": "snack"
            },
            {
              "id": "TWVhbDoyNjAyNjcy",
              "meal": "lunch"
            },
            {
              "id": "TWVhbDoyNjAyNjcz",
              "meal": "dinner"
            }
          ]
        },
        {
          "day": 2,
          "date": "2022-02-03 02:00:00+00:00",
          "meals": [
            {
              "id": "TWVhbDoyNjAyNjY2",
              "meal": "breakfast"
            },
            {
              "id": "TWVhbDoyNjAyNjY3",
              "meal": "snack"
            },
            {
              "id": "TWVhbDoyNjAyNjY4",
              "meal": "lunch"
            },
            {
              "id": "TWVhbDoyNjAyNjY5",
              "meal": "dinner"
            }
          ]
        },
        {
          "day": 1,
          "date": "2022-02-02 02:00:00+00:00",
          "meals": [
            {
              "id": "TWVhbDoyNjAyNjYy",
              "meal": "breakfast"
            },
            {
              "id": "TWVhbDoyNjAyNjYz",
              "meal": "snack"
            },
            {
              "id": "TWVhbDoyNjAyNjY0",
              "meal": "lunch"
            },
            {
              "id": "TWVhbDoyNjAyNjY1",
              "meal": "dinner"
            }
          ]
        }
      ]
    }
  }
}
STEP 5: Get the information of the meal plan

Execute the mealPlan query to retrieve the information of the recent meal plan created. Check that the 3 days have been created along with the information sent in the meal plan template.

Note that calories, the number of servings, calories per serving, and other nutritional information, are calculated automatically based on the recipe information.

Request:

{
  mealPlan {
    day
    date(useDatetime: false)
    calories
    meals {
      id
      calories
      meal
      numOfServings
      recipe {
        name
        numberOfServings
        caloriesPerServing {
          carbs
          saturatedFat
        }
        nutrientsPerServing {
          calories
          carbs
        }
      }
    }
  }
}

Response:

{
  "darapta": {
    "mealPlan": [
      {
        "day": 3,
        "date": "2022-05-20",
        "calories": 1140.3418,
        "meals": [
          {
            "id": "TWVhbDo3MjM5MTc2",
            "calories": 111.9896,
            "meal": "breakfast",
            "numOfServings": 2,
            "recipe": {
              "name": "Bagels",
              "numberOfServings": 12,
              "caloriesPerServing": {
                "carbs": 75.73,
                "saturatedFat": 1.95
              },
              "nutrientsPerServing": {
                "calories": 111.99,
                "carbs": 18.93
              }
            }
          },
          {
            "id": "TWVhbDo3MjM5MTc3",
            "calories": 514.1761,
            "meal": "lunch",
            "numOfServings": 3,
            "recipe": {
              "name": "Apple-Orange Smoothie With Yogurt",
              "numberOfServings": 1,
              "caloriesPerServing": {
                "carbs": 292.81,
                "saturatedFat": 93.42
              },
              "nutrientsPerServing": {
                "calories": 514.18,
                "carbs": 73.2
              }
            }
          },
          {
            "id": "TWVhbDo3MjM5MTc4",
            "calories": 514.1761,
            "meal": "dinner",
            "numOfServings": 2,
            "recipe": {
              "name": "Apple-Orange Smoothie With Yogurt",
              "numberOfServings": 1,
              "caloriesPerServing": {
                "carbs": 292.81,
                "saturatedFat": 93.42
              },
              "nutrientsPerServing": {
                "calories": 514.18,
                "carbs": 73.2
              }
            }
          }
        ]
      },
      {
        "day": 2,
        "date": "2022-05-19",
        "calories": 2289.989575,
        "meals": [
          {
            "id": "TWVhbDo3MjM5MTcz",
            "calories": 1261.637375,
            "meal": "breakfast",
            "numOfServings": 2,
            "recipe": {
              "name": "Coconut Milk Yogurt With Fruit And Nuts",
              "numberOfServings": 1,
              "caloriesPerServing": {
                "carbs": 299.11,
                "saturatedFat": 410.32
              },
              "nutrientsPerServing": {
                "calories": 1261.64,
                "carbs": 74.78
              }
            }
          },
          {
            "id": "TWVhbDo3MjM5MTc0",
            "calories": 514.1761,
            "meal": "lunch",
            "numOfServings": 3,
            "recipe": {
              "name": "Apple-Orange Smoothie With Yogurt",
              "numberOfServings": 1,
              "caloriesPerServing": {
                "carbs": 292.81,
                "saturatedFat": 93.42
              },
              "nutrientsPerServing": {
                "calories": 514.18,
                "carbs": 73.2
              }
            }
          },
          {
            "id": "TWVhbDo3MjM5MTc1",
            "calories": 514.1761,
            "meal": "dinner",
            "numOfServings": 2,
            "recipe": {
              "name": "Apple-Orange Smoothie With Yogurt",
              "numberOfServings": 1,
              "caloriesPerServing": {
                "carbs": 292.81,
                "saturatedFat": 93.42
              },
              "nutrientsPerServing": {
                "calories": 514.18,
                "carbs": 73.2
              }
            }
          }
        ]
      },
      {
        "day": 1,
        "date": "2022-05-18",
        "calories": 1322.04569166667,
        "meals": [
          {
            "id": "TWVhbDo3MjM5MTcw",
            "calories": 293.693491666667,
            "meal": "breakfast",
            "numOfServings": 2,
            "recipe": {
              "name": "Bagels",
              "numberOfServings": 12,
              "caloriesPerServing": {
                "carbs": 170.57,
                "saturatedFat": 33.97
              },
              "nutrientsPerServing": {
                "calories": 293.69,
                "carbs": 42.64
              }
            }
          },
          {
            "id": "TWVhbDo3MjM5MTcx",
            "calories": 514.1761,
            "meal": "lunch",
            "numOfServings": 3,
            "recipe": {
              "name": "Apple-Orange Smoothie With Yogurt",
              "numberOfServings": 1,
              "caloriesPerServing": {
                "carbs": 292.81,
                "saturatedFat": 93.42
              },
              "nutrientsPerServing": {
                "calories": 514.18,
                "carbs": 73.2
              }
            }
          },
          {
            "id": "TWVhbDo3MjM5MTcy",
            "calories": 514.1761,
            "meal": "dinner",
            "numOfServings": 2,
            "recipe": {
              "name": "Apple-Orange Smoothie With Yogurt",
              "numberOfServings": 1,
              "caloriesPerServing": {
                "carbs": 292.81,
                "saturatedFat": 93.42
              },
              "nutrientsPerServing": {
                "calories": 514.18,
                "carbs": 73.2
              }
            }
          }
        ]
      },
      {
        "day": 7,
        "date": "2022-02-08",
        "calories": 1611.83026353901,
        "meals": [
          {
            "id": "TWVhbDoyNjAyNjg2",
            "calories": 201.260440660979,
            "meal": "breakfast",
            "numOfServings": 1,
            "recipe": {
              "name": "Chicken-Berry Salad",
              "numberOfServings": 2,
              "caloriesPerServing": {
                "carbs": 48.16,
                "saturatedFat": 31.05
              },
              "nutrientsPerServing": {
                "calories": 201.26,
                "carbs": 12.04
              }
            }
          },
          {
            "id": "TWVhbDoyNjAyNjg3",
            "calories": 202.468522486167,
            "meal": "snack",
            "numOfServings": 1,
            "recipe": {
              "name": "Garlic Soybean Sprouts",
              "numberOfServings": 4,
              "caloriesPerServing": {
                "carbs": 57.85,
                "saturatedFat": 11.05
              },
              "nutrientsPerServing": {
                "calories": 202.47,
                "carbs": 14.46
              }
            }
          },
          {
            "id": "TWVhbDoyNjAyNjg4",
            "calories": 442.45946009413,
            "meal": "lunch",
            "numOfServings": 1,
            "recipe": {
              "name": "Cajun Chickpea & Carrot Salad",
              "numberOfServings": 4,
              "caloriesPerServing": {
                "carbs": 294.05,
                "saturatedFat": 6.07
              },
              "nutrientsPerServing": {
                "calories": 442.46,
                "carbs": 73.51
              }
            }
          },
          {
            "id": "TWVhbDoyNjAyNjg5",
            "calories": 270.767687772459,
            "meal": "dinner",
            "numOfServings": 1,
            "recipe": {
              "name": "Crockpot Italian Chicken And Peppers Recipes",
              "numberOfServings": 4,
              "caloriesPerServing": {
                "carbs": 87.01,
                "saturatedFat": 23.66
              },
              "nutrientsPerServing": {
                "calories": 270.77,
                "carbs": 21.75
              }
            }
          }
        ]
      },
      {
        "day": 6,
        "date": "2022-02-07",
        "calories": 1555.30797310539,
        "meals": [
          {
            "id": "TWVhbDoyNjAyNjgy",
            "calories": 563.737203099,
            "meal": "breakfast",
            "numOfServings": 1,
            "recipe": {
              "name": "Apple Coconut Parfait",
              "numberOfServings": 1,
              "caloriesPerServing": {
                "carbs": 139.6,
                "saturatedFat": 177.87
              },
              "nutrientsPerServing": {
                "calories": 563.74,
                "carbs": 34.9
              }
            }
          },
          {
            "id": "TWVhbDoyNjAyNjgz",
            "calories": 122.1237,
            "meal": "snack",
            "numOfServings": 1,
            "recipe": {
              "name": "Plum Pomegranate Smoothie",
              "numberOfServings": 1,
              "caloriesPerServing": {
                "carbs": 102.76,
                "saturatedFat": 1.09
              },
              "nutrientsPerServing": {
                "calories": 122.12,
                "carbs": 25.69
              }
            }
          },
          {
            "id": "TWVhbDoyNjAyNjg0",
            "calories": 484.969860139719,
            "meal": "lunch",
            "numOfServings": 1,
            "recipe": {
              "name": "Air Fryer Beef Taco Bowls",
              "numberOfServings": 4,
              "caloriesPerServing": {
                "carbs": 198.36,
                "saturatedFat": 68
              },
              "nutrientsPerServing": {
                "calories": 487.03,
                "carbs": 49.59
              }
            }
          },
          {
            "id": "TWVhbDoyNjAyNjg1",
            "calories": 384.477209866667,
            "meal": "dinner",
            "numOfServings": 1,