Common Foods Search

The commonFoods query allows users to search for any type of common food. Within the search, food can be filtered by using tags.

Common foods are known as the most intake foods on a daily basis. Among these common foods, we can find apples, cookies, milk, rice, sugar, noodles, etc.

Characteristics

Within the common food search you are able to:

How to calculate the nutrient according to a food portion

Common food nutrients are per each 100g. The value can be different depending on the portion of each food. For example, the weight of a small banana can be 20g, while a big banana can weigh 30g. To calculate the nutrients, use the following equation:

nutrientvalueweight/100nutrient value *weight/100

Where:

  • weight is equivalent the gramWeightfield included within the portions object

Available Arguments

Define at least one argument within the query.

Argument Name

Type

Description

query

Query

Name or keyword of the food. It is possible to add more than one value. The query is case insensitive.

filter

Object that filters food according to different criteria. Use this object to filter:

  • Id

  • externalId

  • Barcode

  • Name

  • Tags

  • Nutrients

  • mealTime

  • Ingredients

after

String

before

String

first

String

Retrieves the first results from the list.

last

String

Available Fields

Field Name

Type

Description

id

ID

Id of the food

description

String

Description of the food

foodDataId

String

Food Id to use in the addFoodLog mutation

name

String

Name of the food

nutrients

Object that retrieves the information of the nutrients of the food. For more information on how to use nutrients, see this example.

portions

Object that retrieves the information of the food portions

tags

String

Displays the available tags

Pagination

The commonFood query supports the use of pagination. The following fields can be used

 pageInfo{
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }

Example

Get the nutritional information of a specific food

{
  commonFoods(
    filter: {
      id: "Q29tbW9uRm9vZE5vZGU6N2QyYTY0NDUtN2MwZi00ZTYxLTlkNjctYTA4ZWI2NDhlNTY3"
    }
  ) {
    edges {
      node {
        id
        name
        description
        nutrients {
          type
          amount
          name
          unit
        }
        portions {
          amount
          gramWeight
          modifier
        }
      }
    }
  }
}

Get the list of foods that contain "milk chocolate"

{
  commonFoods(query: "milk chocolate", first: 1) {
    edges {
      node {
        id
        name
        portions {
          modifier
          amount
          gramWeight
        }
        nutrients {
          type
          amount
          name
          unit
        }
      }
    }
  }
}

UI/UX example

In the same way, we have code examples, this is an implementation example in which see results of the API execution in the Suggestic App.

Login to the App, tap on the Food Log + option, choose the Candies, Milk chocolate recipe (the same recipe retrieved in the above example) and the nutrition information is displayed along with the different available portions for the given recipe:

Use pagination to get the first results of foods that contain bread

{
  commonFoods(query: "bread", first: 2) {
    edges {
      node {
        id
        name
        description
        portions {
          amount
          modifier
          gramWeight
        }
        nutrients {
          id
          amount
          name
          unit
        }
      }
       }
     pageInfo{
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
    }
    
  }

Filter all the common foods that include the "fat-free" tag

Filter all the common foods that include the "fat-free" and "caffeine-free" tags

{
  commonFoods(
      filter: {
      tags: ["fat-free", "caffeine-free"]
    }
  ) {
    count
    edges {
      node {
        id
        name
        description
        tags

      }
    }
  }
}

Get all the common foods that contain Vitamin A and Folic Acid

{
  commonFoods(filter: {
      nutrients: [
        {nutrient:VITAMIN_A_RAE range: {lte: 100}}
        {nutrient:FOLIC_ACID range: {gte: 10}}
      ]
    }
  )
    {
    count
    edges {
      node {
        id
        name
        description
        foodDataId
      }
    }
  }
}

Last updated