# How to add desserts to your meal plan

## Overview

The Suggestic API usually generates a 7-day meal plan based on the following format:

`BREAKFAST, SNACK, LUNCH, DINNER`

Even though there is no *<mark style="background-color:purple;">**DESSERT**</mark>* mealtime category, you can replace a mealtime to include a dessert recipe. Usually, the `SNACK` mealtime can be replaced with a dessert recipe in an already generated meal plan.

In this example, you will learn how to add a dessert recipe to your meal plan.

### Requirements&#x20;

* To have a [meal plan generated](https://docs.suggestic.com/graphql/query/mutations/meal-plan)

### Considerations

* If it is required to set the [user's meal plan settings](https://docs.suggestic.com/graphql/query/mutations/user-profile/profile-meal-plan-settings) with a custom format such as `[BREAKFAST, LUNCH, SNACK, DINNER, SNACK],` use the [`generateMealPlan` mutation](https://docs.suggestic.com/graphql/query/mutations/meal-plan/generate-meal-plan). The `generateSimpleMealPlan`  plan does not consider the format.

### API endpoints to use

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

* The [`updateMealPlanSettings`](https://docs.suggestic.com/graphql/query/mutations/user-profile/update-meal-plan-settings)mutationto update your meal plan format to add a `SNACK` mealtime.
* The [`generateMealPlan`](https://docs.suggestic.com/graphql/query/mutations/meal-plan/generate-meal-plan)query, only if you update the meal plan settings.
* The [`mealPlan` ](https://docs.suggestic.com/graphql/query/queries/meal-plan/meal-plan-1)query to get the **recipe Id** to replace it with the dessert recipe.&#x20;
* [`recipeSearch`](https://docs.suggestic.com/graphql/query/search/recipe-search/recipes#available-fields),[`recipesByTag`](https://docs.suggestic.com/graphql/query/queries/recipes/recipes-by-tag) or [`recipesByMealTime`](https://docs.suggestic.com/graphql/query/queries/recipes/recipe-by-meal-time#available-arguments) queries to get the dessert recipe ID required
* The [`swapMealPlanRecipe`](https://docs.suggestic.com/graphql/query/mutations/meal-plan/swap-meals) mutation to swap the current recipe with the dessert recipe.
* The [`mealPlan` ](https://docs.suggestic.com/graphql/query/queries/meal-plan/meal-plan-1)query to verify that the recipes were swapped.

## Examples

### Code Example

Find all the steps detailed below in this [graphqlbin](https://graphqlbin.com/v2/r7zrhA). Modify the code accordingly.

### Step by Step Example

Follow the 6 steps below to include a dessert in your meal plan.

{% hint style="info" %}
The first two steps are optional. Follow then only if you don't have a `SNACK`defined in your meal plan.
{% endhint %}

<details>

<summary>STEP 1: Add a SNACK meal to your meal plan.</summary>

*Remember that the `SNACK` recipe will be replaced by the `DESSERT` recipe.*\
\
If your meal plan does not include the SNACK meal time, execute the following mutation by adding a `SNACK` meal after `LUNCH`.

```graphql
mutation updateMealPlanSettings {
  updateMealPlanSettings(
    overwrite: { format: [BREAKFAST, LUNCH, SNACK, DINNER] }
  ) {
    success
    message
  }
}
```

**Note:** Add a or move the SNACK meal time to any place. For example, if you need to have a SNACK (as a dessert) after the DINNER meal, you can setup the following format:

```graphql
format: [BREAKFAST, LUNCH, SNACK, DINNER, SNACK]
```

</details>

<details>

<summary>STEP 2: Regenerate your meal plan</summary>

If you updated the meal plan settings, [re-generate your meal plan ](https://docs.suggestic.com/graphql/query/mutations/meal-plan/generate-meal-plan)

</details>

<details>

<summary>STEP 3: Identify the <strong>mealtime</strong> to replace</summary>

Execute the [`mealPlan`](https://docs.suggestic.com/graphql/query/queries/meal-plan/meal-plan-1) query to identify the mealtime or mealtimes to replace.&#x20;

**Request:**

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

**Response:**

```graphql
{
  "data": {
    "mealPlan": [
      {
        "day": 7,
        "date": "2022-04-28",
        "calories": 2250.48579801368,
        "meals": [
          {
            "id": "TWVhbDo0OTg4Mzg2",
            "calories": 582.850409456654,
            "meal": "breakfast",
            "numOfServings": 1,
            "recipe": {
              "name": "Mexican-Spiced Tofu Scramble",
              "numberOfServings": 4,
              "nutrientsPerServing": {
                "calories": 582.85
              }
            }
          },
          {
            "id": "TWVhbDo0OTg4Mzg3",
            "calories": 830.597746296156,
            "meal": "lunch",
            "numOfServings": 2,
            "recipe": {
              "name": "Arugula Cannellini Beans Salad Recipes",
              "numberOfServings": 4,
              "nutrientsPerServing": {
                "calories": 415.3
              }
            }
          },
          {
            "id": "TWVhbDo0OTg4Mzg4",
            "calories": 154.027677840875,
            "meal": "snack",
            "numOfServings": 1,
            "recipe": {
              "name": "Kale Smoothie With Orange And Pear",
              "numberOfServings": 2,
              "nutrientsPerServing": {
                "calories": 154.03
              }
            }
          },
          {
            "id": "TWVhbDo0OTg4Mzg5",
            "calories": 683.00996442,
            "meal": "dinner",
            "numOfServings": 1,
            "recipe": {
              "name": "Braised Tofu",
              "numberOfServings": 1,
              "nutrientsPerServing": {
                "calories": 683.01
              }
            }
          }
        ]
      }
      ......
```

Copy the meal or meals `id` of the meal times and save them to use at the moment of swapping the recipes. In the case of the examples, the `SNACK` mealtime for day 7  is copied:

**DAY 7:** `"id": "`TWVhbDo0OTg4Mzg4`"`

</details>

<details>

<summary>STEP 4: Get the DESSERT recipe Id</summary>

As was mentioned above, there are different queries to get the dessert information. In the case of this example, the `recipesByMealTime` query is used.&#x20;

Request:

```graphql
{
  recipesByMealTime(mealTime: TREAT_DESSERT, dietaryTags: [VEGAN]) {
    edges {
      node {
        id
        name
        author
        tags
        mealTags
        ingredients {
          name
        }
        instructions
        ingredientLines
      }
    }
  }
}
```

**Response:**

```graphql
{
  "data": {
    "recipesByMealTime": {
      "edges": [
        {
          "node": {
            "id": "UmVjaXBlOmJlZGQ0MjAzLTljZWEtNDZiYS05ZmIwLTY4NGFjZGYxZjZkNg==",
            "name": "Pineapple Chia Ice Pops",
            "author": "I Heart Vegetables",
            "tags": [
              "VEGETARIAN",
              "PLANT_BASED",
              "Dessert",
              "DAIRY_FREE",
              "VEGAN",
              "GLUTEN_FREE"
            ],
            "mealTags": [
              "Snack"
            ],
            "ingredients": [
              {
                "name": "Pineapple"
              },
              {
                "name": "Protein powder optional"
              },
              {
                "name": "Bolthouse farms pineapple mango smoothie"
              },
              {
                "name": "Chia seeds"
              }
            ],
            "instructions": [],
            "ingredientLines": [
              "½ cup frozen pineapple",
              "1 scoop of protein powder Optional: For a protein boost",
              "16 oz Bolthouse Farms Pineapple Mango Smoothie",
              "2 tbsp chia seeds"
            ]
          }
        }
      ]
    }
  }
}
```

</details>

<details>

<summary>STEP 5: Swap the SNACK and DESSERT recipes in the meal plan</summary>

Execute the[`swapMealPlanRecipe`](https://docs.suggestic.com/graphql/query/mutations/meal-plan/swap-meals) and replace the `mealId` copied on **step 2** and the `recipeID` copied on **step 4:**

```graphql
mutation {
  swapMealPlanRecipe(
    recipeId: "UmVjaXBlOmI5NmMxMmExLWU1Y2EtNDI2MS1hZjUzLWY0MGMxY2ZhNDBiMg=="
    mealId: "TWVhbDo0ODk4OTY3"
    serving: 2
  ) {
    success
  }
}
```

</details>

<details>

<summary><strong>STEP 6: Verify that both recipes were swapped</strong></summary>

Execute the `mealPlan` query to verify that the recipe has been replaced:

​![](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LwqSnBDpAb6mFZYLsuB%2Fuploads%2FNpWlOEHq18fv3TfmjmvE%2Fimage.png?alt=media\&token=bf4664a4-e4f3-4dfa-83b9-4b983c633a66)

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.suggestic.com/graphql/knowledge-base/how-to-guides/how-to-add-desserts-to-your-meal-plan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
