# Meal Plan

The `MealPlan` query will return the current and previous 7-day meal plans for the user, so it will return a maximum of 14 days. Each `day` of the meal plan will contain a certain number of `meals` according to the user's profile.

Each `meal` contains a [recipe](https://docs.suggestic.com/graphql/objects/recipe) with all its expected properties along with the amount of recommended servings (`numOfServings`).

#### Meal Plan Settings

Macros, caloric ranges, meals per day, and other settings can be defined for each user using the [profileMealPlanSettings ](https://docs.suggestic.com/graphql/query/mutations/user-profile/legacy-user-mutations/profile-meal-plan-settings)mutation. If this object is null, the meal plan will be generated using the user's [goals](https://docs.suggestic.com/graphql/query/mutations/user-profile/update-users-goals).&#x20;

#### Meal Plan Generation

In order for a meal plan to exists it first needs to be created using the [generateMealPlan ](https://docs.suggestic.com/graphql/query/mutations/meal-plan/generate-meal-plan)mutation.

### Available Fields

| Field      | Type                                                                 | Note                                                                                                                                                          |
| ---------- | -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `day`      | Int                                                                  | Number of days in the returned meal plan                                                                                                                      |
| `date`     | String                                                               | Date assigned to the "day" of the meal plan                                                                                                                   |
| `calories` | Float                                                                | Total calories (in Kcal) for the day                                                                                                                          |
| `protein`  | Float                                                                | Total protein (g) for the day                                                                                                                                 |
| `carbs`    | Float                                                                | Total carbs (g) for the day                                                                                                                                   |
| `fat`      | Float                                                                | Total fat (g) for the day                                                                                                                                     |
| `meals`    | \[[meal](https://docs.suggestic.com/graphql/objects/meal-plan/meal)] | A [Recipe](https://docs.suggestic.com/graphql/objects/recipe) along with the total calories of the meal, name of the meal, and amount of recommended servings |

### Example

{% tabs %}
{% tab title="Request" %}

```graphql
{
  mealPlan {
    day
    date(useDatetime: false)
    calories
    meals {
      id
      calories
      meal
      numOfServings
      recipe {
        name
        numberOfServings
        nutrientsPerServing {
          calories
        }
      }
    }
  }
}

```

{% endtab %}

{% tab title="Response" %}

```javascript
{
  "data": {
    "mealPlan": [
      {
        "day": 1,
        "date": "2020-11-10",
        "calories": 2494.40432435512,
        "meals": [
          {
            "id": "TWVhbDo0NTIzOTU=",
            "calories": 1140.70631,
            "meal": "breakfast",
            "numOfServings": 4,
            "recipe": {
              "name": "Meyer Lemon Poppy Seed Pancakes",
              "numberOfServings": 8,
              "nutrientsPerServing": {
                "calories": 285.18
              }
            }
          },
          {
            "id": "TWVhbDo0NTIzOTY=",
            "calories": 55.979,
            "meal": "snack",
            "numOfServings": 1,
            "recipe": {
              "name": "Dried Cranberries",
              "numberOfServings": 1,
              "nutrientsPerServing": {
                "calories": 400
              }
            }
          },
          {
            "id": "TWVhbDo0NTIzOTc=",
            "calories": 274.496096881456,
            "meal": "lunch",
            "numOfServings": 1,
            "recipe": {
              "name": "Greek Salad",
              "numberOfServings": 2,
              "nutrientsPerServing": {
                "calories": 274.5
              }
            }
          },
          {
            "id": "TWVhbDo0NTIzOTg=",
            "calories": 88.0264,
            "meal": "snack",
            "numOfServings": 1,
            "recipe": {
              "name": "Apple Slices",
              "numberOfServings": 1,
              "nutrientsPerServing": {
                "calories": 88.03
              }
            }
          },
          {
            "id": "TWVhbDo0NTIzOTk=",
            "calories": 935.196517473667,
            "meal": "dinner",
            "numOfServings": 2,
            "recipe": {
              "name": "Coconut Lime Shrimp",
              "numberOfServings": 4,
              "nutrientsPerServing": {
                "calories": 467.6
              }
            }
          }
        ]
      },
      {
        "day": 7,
        "date": "2020-11-09",
        "calories": 2534.62785666846,
        "meals": [
          {
            "id": "TWVhbDo0NDM1MzQ=",
            "calories": 893.348881646525,
            "meal": "breakfast",
            "numOfServings": 2,
            "recipe": {
              "name": "Cherry Tomato Bites [Vegan, Gluten-Free]",
              "numberOfServings": 4,
              "nutrientsPerServing": {
                "calories": 446.67
              }
            }
          },
          {
            "id": "TWVhbDo0NDM1MzU=",
            "calories": 242.991933333333,
            "meal": "snack",
            "numOfServings": 1,
            "recipe": {
              "name": "Peanut Butter Milkshake",
              "numberOfServings": null,
              "nutrientsPerServing": {
                "calories": 242.99
              }
            }
          },
          {
            "id": "TWVhbDo0NDM1MzY=",
            "calories": 389.312940753041,
            "meal": "lunch",
            "numOfServings": 2,
            "recipe": {
              "name": "Confetti Quinoa",
              "numberOfServings": 2,
              "nutrientsPerServing": {
                "calories": 194.66
              }
            }
          },
          {
            "id": "TWVhbDo0NDM1Mzc=",
            "calories": 243.90417195952,
            "meal": "snack",
            "numOfServings": 1,
            "recipe": {
              "name": "Green Beans With Garlic And Lemon",
              "numberOfServings": 2,
              "nutrientsPerServing": {
                "calories": 243.9
              }
            }
          },
          {
            "id": "TWVhbDo0NDM1Mzg=",
            "calories": 765.069928976041,
            "meal": "dinner",
            "numOfServings": 4,
            "recipe": {
              "name": "Chicken Breast With Honey-Balsamic Glaze",
              "numberOfServings": 4,
              "nutrientsPerServing": {
                "calories": 191.27
              }
            }
          }
        ]
      }
    ]
  }
}
```

{% endtab %}
{% endtabs %}

### Example with total Macros

{% tabs %}
{% tab title="Request" %}

```graphql
query{
  mealPlan{
    date
    calories
    protein
    carbs
    fat
    day
    meals{
      recipe{
        name
      	id
        mealTags
        tags
      }
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```graphql
{
  "data": {
    "mealPlan": [
      {
        "date": "2024-07-16 02:00:00+00:00",
        "calories": 1062.0772445391667,
        "protein": 60.19781906916667,
        "carbs": 100.0011865825,
        "fat": 46.80902465916666,
        "day": 7,
        "meals": [
          {
            "recipe": {
              "name": "Bean And Cheese Quesadilla",
              "id": "UmVjaXBlOjQ5MGY3ZGZiLTBjNmMtNDU4Mi1iZTIxLThjNjJiYjEyOTdiNw==",
              "mealTags": null,
              "tags": [
                "Lunch",
                "main dish",
                "Breakfast",
                "UNDER 15 MINUTES",
                "main course",
                "Fast & Easy",
                "Dinner"
              ]
            }
          },
          {
            "recipe": {
              "name": "Double Chocolate Thickshake",
              "id": "UmVjaXBlOjZhMTAzY2NmLTkxYWEtNGMyZi1iMDQ3LThhYzkxNjIzMjBkYg==",
              "mealTags": null,
              "tags": [
                "VEGETARIAN",
                "GLUTEN_FREE",
                "DAIRY_FREE"
              ]
            }
          },
          {
            "recipe": {
              "name": "Israeli Cauliflower Salad With Superfood Dukkah",
              "id": "UmVjaXBlOmI1M2E2ZGM5LTA2ZmQtNDA5Ny04YWQ4LWI5MjJkZTZjNTgzMw==",
              "mealTags": null,
              "tags": [
                "VEGETARIAN",
                "GLUTEN_FREE",
                "DAIRY_FREE",
                "VEGAN"
              ]
            }
          },
          {
            "recipe": {
              "name": "Air Fryer Cajun Crab Cakes",
              "id": "UmVjaXBlOjRlZjU5NDVhLTM3MWQtNDQ3ZS1hNWI0LTkyMzMzYmFiYjQ0Ng==",
              "mealTags": null,
              "tags": [
                "Lunch",
                "Dinner",
                "main course",
                "main dish",
                "Fast & Easy",
                "Seafood"
              ]
            }
          }
        ]
      },
      {
        "date": "2024-07-15 02:00:00+00:00",
        "calories": 1223.7193252078278,
        "protein": 78.21256417252481,
        "carbs": 127.78186363617326,
        "fat": 44.415734885892846,
        "day": 6,
        "meals": [
          {
            "recipe": {
              "name": "Mince Pies",
              "id": "UmVjaXBlOjE3NWU5ZTIwLTQ4YzktNDQ5ZS05NmNhLWNlYTE2ZDY4YmIzYQ==",
              "mealTags": null,
              "tags": [
                "15 - 30 MINUTES",
                "STEAMED"
              ]
            }
          },
          {
            "recipe": {
              "name": "Walnut No-Meat Meatballs",
              "id": "UmVjaXBlOmQwYTE5NzZkLTY5NGYtNDU0MC04ZTVkLTg5MjgwZmQzNTUwOQ==",
              "mealTags": null,
              "tags": [
                "VEGETARIAN",
                "GLUTEN_FREE"
              ]
            }
          },
          {
            "recipe": {
              "name": "Naked Kitchari Burgers",
              "id": "UmVjaXBlOmMyNTJjMWJlLTExN2YtNGY4Yi1hMTVlLTBlZWQxNDc3OTEzMQ==",
              "mealTags": null,
              "tags": [
                "VEGETARIAN",
                "GLUTEN_FREE"
              ]
            }
          },
          {
            "recipe": {
              "name": "Bourbon Chicken",
              "id": "UmVjaXBlOjRmMzUxYjY2LTczZGUtNDJhZC1iNGJlLWY5ZTNjYzAwY2MyOA==",
              "mealTags": null,
              "tags": [
                "Low-Fat",
                "ABOVE 30 MINUTES",
                "Dinner",
                "ACIDIC FOODS/DRINKS",
                "LABOR INTENSIVE",
                "PROTEIN-DENSE",
                "DOES NOT DISSOLVE VIA SALIVA",
                "Lunch"
              ]
            }
          }
        ]
      },
      {
        "date": "2024-07-14 02:00:00+00:00",
        "calories": 1026.4874236915025,
        "protein": 55.22026352413019,
        "carbs": 102.84088183299365,
        "fat": 43.804760251445245,
        "day": 5,
        "meals": [
          {
            "recipe": {
              "name": "Savoury Cheese + Black Pepper Scones",
              "id": "UmVjaXBlOjA4YWJlNzkyLTdlMTAtNDgzYy1hYWEzLTA4ZmJiZGUzMTc2NQ==",
              "mealTags": null,
              "tags": [
                "VEGETARIAN",
                "Peanut-Free",
                "Sesame-Free",
                "Fish-Free",
                "Kids"
              ]
            }
          },
          {
            "recipe": {
              "name": "Veggie Chips",
              "id": "UmVjaXBlOjlhYThhNjNmLWU3YTAtNGE1Yy1hYzk1LTBmZDNkYmM2MjlhYg==",
              "mealTags": null,
              "tags": [
                "VEGETARIAN",
                "GLUTEN_FREE",
                "DAIRY_FREE",
                "VEGAN",
                "Peanut-Free",
                "Egg-Free",
                "Kids"
              ]
            }
          },
          {
            "recipe": {
              "name": "Brussels Sprout + Green Pea Slice",
              "id": "UmVjaXBlOjk4ZWJlY2ZiLTQ2N2QtNDY1MS1iOTZkLWMyMTM1YWNlOTEwNQ==",
              "mealTags": null,
              "tags": [
                "GLUTEN_FREE",
                "VEGETARIAN"
              ]
            }
          },
          {
            "recipe": {
              "name": "Coq Au Vin",
              "id": "UmVjaXBlOmY2OTg2OGFiLWQ2OGItNDY1YS04ZjQxLTY4ODllZDgwNWEwMg==",
              "mealTags": null,
              "tags": [
                "ABOVE 30 MINUTES",
                "main dish",
                "Dinner",
                "main course",
                "Lunch",
                "Fast & Easy"
              ]
            }
          }
        ]
      }
     ]
   }
}
```

{% endtab %}
{% endtabs %}

As follows find an example of how the `numOfServings`, `servingWeigth`, `numberOfServings`, and weightInGramms are used and calculated within this mutation:

![](https://920729701-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LwqSnBDpAb6mFZYLsuB%2F-MdTMgZ4TM9RyS0fD-GX%2F-MdTQZrp1rHdXHBAkICu%2Fimage.png?alt=media\&token=d8f960a6-1900-4b07-a571-4e8bc14c5ec8)

### About Dates

Associated to each `day` of the meal plan, the `date` value contains the date that corresponds to that particular `day` based on the last time a meal plan was generated. Read more about how dates are assigned [here](https://docs.suggestic.com/graphql/mutations/meal-plan/generate-meal-plan#about-dates).

Returned results are sorted by `date` in descending order.

In older versions of the API, dates were returned as datetimes in UTC, and you had to make sure to adjust for your user's timezone and convert the datetime to date in order to avoid issues with date assignment. For compatibility, this is still the default. To receive an already converted date, you have to send the `useDatetime: false` argument in the `date` field.

{% hint style="warning" %}
Unless you're working with an older version of the API, always send the `useDatetime: false` argument in the `date` field.
{% endhint %}

### Normal Flow

1. A new user is created, it doesn't have a meal plan yet
2. Use `generateMealPlan` for the first time. This returns success=true if the meal plan is generated successfully.
   1. Call `mealPlan` to obtain the first set of 7 days (or the first meal plan).&#x20;
   2. The first day (day 1) will have the date of the day in which you called `generateMealPlan`
3. If at any time during the 7 days while a meal plan is "running" you call `generateMealPlan`, nothing will happen, unless the user's settings have changed. Read more [here](https://docs.suggestic.com/graphql/mutations/meal-plan/generate-meal-plan#if-settings-havent-changed).
4. At any time, you should use `mealPlan` to obtain the currently running meal plan. This will return up to 14 days. These 14 days normally represent the current "running meal plan" and the previous week (if it exists).&#x20;
   1. Please note that in the cases where the user's profile has changed and `generateMealPlan` was used again (before the end of the running meal plan), then when looking at the data returned by `mealPlan` you may be looking at more than 2 meal plans in the same set of 14 days.
5. When you reach day 7 you have 2 options
   1. Generate a new set of 7 days using `generateMealPlan` with [addDays: true](https://docs.suggestic.com/graphql/mutations/meal-plan/generate-meal-plan#example) (the new day 1 will come after the "current" day 7)&#x20;
   2. Repeat the previous 7 days using `generateMealPlan` with [repeat: "date"](https://docs.suggestic.com/graphql/mutations/meal-plan/generate-meal-plan#example) (same behavior but with the same meals as before)
6. If day 7 of the last running meal plan has gone by and a new meal plan has not been requested, then you'll still be looking at the original 7 days when calling `mealPlan`. At this point, you'll need to call `generateMealPlan`  to request a new set of 7 days, as in point #2.&#x20;
   1. The options in point #6 will also be available
   2. IMPORTANT: A new meal plan will **not** be automatically generated when the previous one has ended
7. Any time you call `generateMealPlan`  make sure the success status is True. If the value returned is False then a new meal plan failed to generate and will be looking at "old" data if you call `mealPlan` at this point.

### **Other Considerations**

* A margin of error has been set for the resulting meal plan for both calories and macronutrients&#x20;
* No meal will repeat on the same day
* This query takes into account the user's goals, program, and preferences
* A number of quality-related filters have been set, by default, in order to ensure high-quality meal plans:
  * Excludes recipes with under 40 calories per serving
  * Excludes recipes for desserts, sauces, dips, bread, cocktails, and similar
  * Excludes snacks with over 5 ingredients
  * Excludes recipes with over 15 servings
  * Excludes recipes with more than 45-minute of cooking and preparation time
  * Excludes 0 calorie foods
  * Excludes packaged foods
* If a meal plan cannot be generated because of the user's restrictions, [a message](https://docs.suggestic.com/graphql/start-here/tutorials-and-walkthroughs/create-a-meal-plan#common-errors) will be displayed
