# Autocomplete

{% hint style="warning" %}
Please refer to the[ Food Search](https://docs.suggestic.com/graphql/query/search/food-search-for-food-log/food-search) section for a new and improved way for searching for foods for food logging or other purposes.
{% endhint %}

The `Autocomplete` search covers all object types (recipes, products, own recipes) and is mostly used for [Food Logging](https://docs.suggestic.com/graphql/query/queries/food-log) purposes.

### Required Arguments

| Argument   | Required | Type                                                                                         | Description                              |
| ---------- | -------- | -------------------------------------------------------------------------------------------- | ---------------------------------------- |
| `query`    | true     | String                                                                                       | Search query                             |
| `mealType` | true     | [MealType](https://docs.suggestic.com/graphql/objects/food-logs/meal-type#available-options) | Type of meal/food that is being searched |

Leaving the `mealType` argument empty will result in a search that covers: RECIPE and USDA\_MEAL. Using the argument will narrow the search to that particular domain.&#x20;

### Available Fields

| Field Name | Type    | Description                                                                                                                      |
| ---------- | ------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `enter`    | Boolean | **True** to complete the value based on which the user entered. If this value is not defined, by default it will be set as true. |
| `first`    | String  | Retrieves the first results from the list.                                                                                       |
| `after`    | String  | For more information, refer to the [Search ](https://docs.suggestic.com/graphql/query/search)documentation                       |
| `last`     | String  | Retrieves the last results from the list                                                                                         |

### Pagination

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

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

```graphql
cursor
    }
     pageInfo {
      endCursor
      hasNextPage
    }
```

{% endtab %}
{% endtabs %}

Refer to the [pagination ](https://docs.suggestic.com/graphql/query/search#pagination)documentation for more information.

### Examples

Searching in a single *meal type*

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

```graphql
{
  autocomplete(query: "egg" mealType: USDA_MEAL) {
    edges {
      node {
        mealType
        databaseId
        name
      }
    }
  }
}

```

{% endtab %}

{% tab title="Response" %}

```javascript
{
  "data": {
    "autocomplete": {
      "edges": [
        {
          "node": {
            "mealType": "USDA_MEAL",
            "databaseId": "01123",
            "name": "Egg, whole, raw, fresh"
          }
        },
        {
          "node": {
            "mealType": "USDA_MEAL",
            "databaseId": "01124",
            "name": "Egg, white, raw, fresh"
          }
        },
        {
          "node": {
            "mealType": "USDA_MEAL",
            "databaseId": "01057",
            "name": "Eggnog"
          }
        },
        {
          "node": {
            "mealType": "USDA_MEAL",
            "databaseId": "11209",
            "name": "Eggplant, raw"
          }
        }
      ]
    }
  }
}
```

{% endtab %}
{% endtabs %}
