Food Search

The foodSearch is a powerful search query that allows users to search for food that can be logged such as recipes, USDA, branded food, products with barcodes, restaurants, etc. that matches the desired search criteria.

The FoodSearch query allows users to nest their search queries. Results are the same as the queries will be used separately. The advantage is that all the information is gathered in one response.

To use the FoodSearch query, place the query before the query name

query FoodSearch { search queries }

The following searched can be nested within the foodSearch, these can be combined or used separately.

Characteristics

  • Use one, two, or more query searches within the FoodSearch query

  • Allow users to select the data type to be searched. For instance, a user wants to search for recipes, common, branded, and packaged foods at the same time.

  • Use filters to introduce nutrient ranges for macros and macronutrients.

  • Retrieve which group each food belongs to.

  • Define query variables to be sent as arguments in the FoodSearch query

  • Allow users to search for products introducing a specific barcode

How to use query variables

Use the QUERY VARIABLES tab to add variables, pass them as a parameter to the GraphQL query, and use them to fetch data.

Structure

In the FoodSearch query, define the variables which are sent as arguments, then, define the query variables in the TAB which is located at the bottom left side of the navigator.

Within the QUERY VARIABLES tab, write the variables in a JSON format, and then execute the query.

Example

Common and Branded foods

The following example searches common and branded foods criteria by adding the commonFoods and brandedFoods within the FoodSearch query.

 
query FoodSearch {
  commonFoods: commonFoods(query: "cookie", first: 2) {
    edges {
      node {
        id
        name
        description
        portions {
          amount
          modifier
          gramWeight
        }
        nutrients {
          id
          amount
          name
          unit
        }
      }
    }
  }
  brandedFoods: brandedFoods(query: "oreo", first: 2) {
    edges {
      node {
        id
        name
        gtinUpc
        brandOwner
        servingSize
        servingSizeUnit
        nutrients {
          id
          amount
          name
          unit
        }
      }
    }
  }
}

Common Foods and Recipes

The following example searches common foods and recipes criteria within the FoodSearch query.

 
  query FoodSearch {
  commonFoods: commonFoods(query: "bread", first: 2) {
    edges {
      node {
        id
        name
        description
        portions {
          amount
          modifier
          gramWeight
        }
        nutrients {
          id
          amount
          name
          unit
        }
      }
    }
  }

     recipes: recipeSearch(query: "oreos") {
    edges {
      node {
        id
        name
      }
    }
  }
}

Common Foods using query variables

In the following example, two query variables are defined to be sent as arguments in the query

{
  "query": "fish",
  "first": 1
}

Last updated