Common Scenarios

Common Scenarios

Create

One of the key uses for the Genesis API is to create foods. Depending on what type of food you are creating there are a couple workflows you may follow. Many of the requests below are part of the FoodMutation field in the GraphQL API.

Ingredient

  1. Create Ingredient

    # Create Food Mutation mutation ($input: CreateFoodInput!) { foods { create (input: $input){ food { id name } } } }
    # GraphQL Variables { "input": { "name":"My Ingredient", "foodType": "Ingredient" } }
  2. Set Weight

    # Set Food Weight mutation ($input : SetFoodAmountInput!) { foods { setAmount (input : $input) { food { id name ... on Ingredient { definingAmount { quantity { value } unit { id name } } } } } } }
    # GraphQL Variables. UnitId is for Grams { "input": { "foodId": "{Id of the Ingredient you want to modify}", "amount": { "quantity": "100", "unitId": "a7df0af5-0008-0000-7484-751e8eaf05c6" } } }
  3. Set Nutrient Values

    # Set Nutrient Values mutation ($input : SetNutrientValuesInput!) { foods { setNutrientValues (input : $input) { food { id name } } } }
    # GraphQL Variables { "input": { "foodId": "{Id of the Ingredient you want to set nutrient values on}", "nutrientValues": [ { "nutrientId": "84a8709a-0000-0000-ebf9-90cea7d9d44f", "value": "397.53"}, { "nutrientId": "84a8709a-0011-0000-ebf9-90cea7d9d44f", "value": "10.18"}, { "nutrientId": "84a8709a-0012-0000-ebf9-90cea7d9d44f", "value": "1.06"}, { "nutrientId": "84a8709a-0015-0000-ebf9-90cea7d9d44f", "value": "0.00"}, { "nutrientId": "84a8709a-0016-0000-ebf9-90cea7d9d44f", "value": "0.04"}, { "nutrientId": "84a8709a-0002-0000-ebf9-90cea7d9d44f", "value": "58.49"}, { "nutrientId": "84a8709a-00d0-0000-ebf9-90cea7d9d44f", "value": "7.14"}, { "nutrientId": "84a8709a-0006-0000-ebf9-90cea7d9d44f", "value": "17.47"}, { "nutrientId": "84a8709a-0094-0000-ebf9-90cea7d9d44f", "value": "15.83"}, { "nutrientId": "84a8709a-0001-0000-ebf9-90cea7d9d44f", "value": "15.86"}, { "nutrientId": "84a8709a-003c-0000-ebf9-90cea7d9d44f", "value": "255.66"}, { "nutrientId": "84a8709a-002f-0000-ebf9-90cea7d9d44f", "value": "83.32"}, { "nutrientId": "84a8709a-0035-0000-ebf9-90cea7d9d44f", "value": "2.97"}, { "nutrientId": "84a8709a-003a-0000-ebf9-90cea7d9d44f", "value": "267.34"}, { "nutrientId": "84a8709a-0027-0000-ebf9-90cea7d9d44f", "value": "0.28"}, { "nutrientId": "84a8709a-0017-0000-ebf9-90cea7d9d44f", "value": "11.50"} ] } }

Recipe

  1. Create Recipe

    # Create Food Mutation mutation ($input : CreateFoodInput!) { foods { create ( input : $input) { food { name id } } } }
    # GraphQL Variables { "input": { "name": "My Recipe", "foodType": "Recipe" } }
  2. Set Serving Size

    # Set Serving Size on Recipe mutation ($input : SetServingSizeInput!){ foods { setServingSize(input: $input){ recipe { id name } } } }
    # GraphQL Variables { "input": { "foodId": "{Id of a Recipe you want to modify}", "servingSize": { "quantity": "68", "unitId": "a7df0af5-0008-0000-7484-751e8eaf05c6" } } }
  3. Add Food Items

    # Set Food Items on Recipe mutation ($input : SetFoodItemsInput!){ foods { setFoodItems(input: $input){ food { id name } } } }
    # GraphQL Variables { "input": { "foodId": "{Id of a Recipe you want to modify}", "foodItems": [ { "foodId": "{Id of some ingredient or recipe}", "amount": {"quantity":"100","unitId":"a7df0af5-0008-0000-7484-751e8eaf05c6"},"isActiveIngredient":"true" }, { "foodId": "{Id of some ingredient or recipe}", "amount": {"quantity":"100","unitId":"a7df0af5-0008-0000-7484-751e8eaf05c6"},"isActiveIngredient":"true" }, { "foodId": "{Id of some ingredient or recipe}", "amount": {"quantity":"100","unitId":"a7df0af5-0008-0000-7484-751e8eaf05c6"},"isActiveIngredient":"true" } ] } }

Search

Another key use case for the API is to search for foods. This is important when trying to create recipes as you will need to find the food ids to add to the recipe. There are several optional inputs for the FoodSearch.

# Search Query query ($input: FoodSearchInput!) { foods { search(input: $input) { totalCount foodSearchResults { ... on FoodSearchResult { id name versionName foodType isApproved } } } } }
# GraphQL Variables { "input": { "foodTypes": ["Recipe","Ingredient"], "versionFilter": "All", "documentStatusFilter": "All", "itemSourceFilter": "Customer", "archiveFilter": "Unarchived", "first": 25, "after": 0, "searchText": "" } }

Analysis

There are a few types of analysis but the most common is the Net analysis. Whether you have an ingredient or recipe, retrieving the analysis looks the same.

# Analysis Query query ($input : GetAnalysisInput!){ analysis { getAnalysis (input : $input){ analysis { analysisType amountAnalyzed { quantity { value } unit { id name } } nutrientInfos { nutrient { id name unit { id name } } value } } } } }
# GraphQL Variables { "input": { "foodId": "{Id of food you want analyzed}", "analysisInput": { "analysisType": "Net", "amount": { "quantity": "100", "unitId": "a7df0af5-0008-0000-7484-751e8eaf05c6" }, "weightUnitId":"a7df0af5-0008-0000-7484-751e8eaf05c6" } } }

 

 

Clicking links may navigate you away from the Trustwell site.