Handle Build-Your-Own dishes with real-time nutrition calculations
Many restaurants offer customizable dishes—build-your-own bowls, salads, pizzas, and more. When guests toggle ingredients on and off, they expect the nutrition panel and allergen warnings to update in real-time.
EveryBite provides two approaches for handling this:
Approach
Best For
Tradeoffs
Calculate endpoint (recommended)
Most integrations
Simple to implement, always accurate, requires API call per update
Client-side calculation
Offline support, full control
You implement the math, must handle updates when our data changes
First, fetch the available customization options for a dish:
Copy
query DishCustomizations($dishId: ID!) { dish(id: $dishId) { id name isCustomizable customizationGroups { id name description selectionType # SINGLE or MULTIPLE minSelections maxSelections options { id name isDefault isAvailable additionalPrice tags # e.g., ["vegan", "gluten-free"] } } }}
The calculate endpoint is optimized for real-time use, but if you’re calling it on every toggle:
Debounce your requests. Wait 200-300ms after the user stops making changes before calling the API. This prevents unnecessary calls while they’re rapidly selecting options.
Example debounce pattern (JavaScript):
Copy
let debounceTimer;function onSelectionChange(selectedOptions) { // Update UI optimistically if desired clearTimeout(debounceTimer); debounceTimer = setTimeout(() => { calculateCustomization(selectedOptions); }, 250);}
For applications that need offline support or want full control over the calculation, you can request complete nutrition data for each customization option and calculate totals yourself.
A dish qualifies for a dietary flag only if all selected options qualify:
Copy
function checkDietaryFlag(flag, selectedOptions) { return selectedOptions.every(option => option.dietaryTags.includes(flag) );}
Dietary flag logic can be more complex than simple intersection. For example, a dish might be “vegan” only if it contains no animal products AND meets certain preparation requirements. The calculate endpoint handles these nuances automatically.
Need guaranteed accuracy for allergen/dietary info
Don’t want to maintain calculation logic
Use Client-Side Calculation
Building an offline-first application
Need instant updates without any network latency
Have specific UX requirements that need full control
Willing to maintain calculation logic
Most developers choose the calculate endpoint. It’s simpler to implement and ensures your users always see accurate information, even as our nutrition data and dietary classification rules evolve.
type CustomizationOption { id: ID! name: String! isDefault: Boolean! isAvailable: Boolean! additionalPrice: Float tags: [String!]! nutrition: Nutrition # Only with full data query allergens: [Allergen!] # Only with full data query dietaryTags: [String!] # Only with full data query}