Technical Docs
  • Introduction
  • Guides
    • Getting Started
    • Attribution Guidelines
    • Core Concepts
      • Adherence Score
      • Programs, Diets, and Rulesets
      • User Profile
      • Datasets
    • Tutorials and Walkthroughs
      • Creating a Meal Plan
      • Food Log Guide
      • Pagination
      • Executing Multiple Mutations
  • Knowledge Base
    • How-to guides
      • How to add desserts to your meal plan
      • How to log your custom recipe
      • How to generate a Meal Plan based on a template
    • Common errors
      • Meal Plan generation
    • FAQs
      • Getting Started on Suggestic
      • API and Authentication
      • Device Compatibility
      • Meal Plan
      • Nutrition
      • Programs
      • Recipes
  • HELPFUL RESOURCES
    • Deprecated Features
    • Glossary
    • Integrations
      • Building a No-code Meal Planning Application
        • Step 1: Creating the Integromat Scenario and Google Forms Connection
        • Step 2: Creating a User, Generating a Meal Plan, and Retrieving It
        • Step 3: Crafting Our PDF and Connecting PDFMonkey
        • Step 4: Sending The Document to Our User
  • Packages and SDKs
    • Node Package (NPM)
  • GraphQL
    • GraphQL Overview
    • Authentication
    • Calling GraphQL
    • GraphQL Playground
  • Changelog
    • 2025
      • March
  • Suggestic API Reference
    • Search
      • Food Log
        • Branded Foods Search
        • Common Foods Search
        • My Branded Food Search
        • My Common Foods Search
        • Food Search
        • Legacy
          • Autocomplete
          • Barcode Search
      • Recipe Search
        • Recipe Search
        • Recipe Search by Name or Ingredients
        • Recipe Search by Ingredients
      • Meal Plan Template Search
      • Profile Search
      • Restaurant Search
        • Restaurant Search by Location
        • Restaurant Search
    • Queries
      • Appointments
        • Upcoming Appointments
        • Past Appointments
        • Appointments Types
      • Assessments
        • Assessment Answers
        • Display Assessments
        • Supplement Recommendations
        • User Assessments
      • Content
        • Content Library
        • Content Categories
        • Content Tags
        • Journey
      • Food Log
        • Frequently Logged
        • Food Log Entries
        • Macros Aggregation
        • Micronutrients Aggregation
        • Macro Goals
        • Recently Logged
        • User's Foods and Recipes
          • User's Recipes
        • Legacy
          • Food Log Entries (Legacy)
          • Own Food Items
          • Own Food Item
          • Own Food Item by Id
          • Own Items
          • Own Recipe
          • Own Recipes
      • Lab Tests
        • Biomarker Categories
        • Biomarker Units
        • Biomarker Catalog
        • Biomarkers
        • Biomarker Results
        • Historical Biomarker Results
        • Historical Results by Biomarker
        • Lab Test Reports
        • Recommended Supplements
        • Recommended Articles
      • Meal Plan
        • Meal Plan
        • Custom Meal Plan
        • Simplified Meal Tracking
          • Meal Tracker
        • Meal Plan Config
        • Meal Planner (deprecated)
      • Program
        • All Programs
        • Program Details
      • Recipes
        • Equivalent Recipes (Macros)
        • Equivalent Recipes (Calories)
        • Recipe by Id
        • Recipes By MealTime
        • Recipes By Tag
        • Recipe Swap Options
        • Popular Recipes
        • Favorite Recipes
        • Premium Program Recipes
      • Restaurants
        • Restaurant By Id
        • Menu Items
        • Menu Item By Id
        • Menu Item by Program
        • Recommend Menu Items
      • Restrictions
        • Restrictions
        • Restriction by ID
      • Shopping List
        • Shopping List by Aisle
        • Shopping List by Recipes
      • Subscriptions
        • Subscription List
      • Supplement Plans
        • Supplement plan list
        • Supplement list
      • Tracking
        • Activity and Exercise
        • Checklists
          • Intake Checklist
        • Daily Recap
          • Get Daily Recap
          • Get Daily Recaps
          • Get Daily Recap Questions
          • Get Daily Mood Summary
        • Inisghts
        • Wellness Score
        • Sleep
          • Sleep Time
          • Sleep Quality Score
        • Steps
        • Water and Hydration
        • Heart Rate
        • HRV
        • Weight Tracker
      • USDA Food
      • Users
        • Users
        • User Profile
      • WGPT
        • Assistants
        • Journey
        • Guardrails
    • Mutations
      • Appointments
        • Update Appointment Credits
      • Assessments
        • New User Assessments
        • Set User Answers
      • Content
        • Mark Content as Read
      • Feedback
      • Food Log
        • Log Entries
          • Food Log
            • Add a Food Log Entry
            • Delete a Food Log Entry
          • Meal Log (Legacy)
            • Create Log Entry
            • Update Log Entry
            • Remove Log Entry
        • User's Foods and Recipes
          • Create a User Recipe
          • Create my Branded Food
          • Create my Common Foods
          • Update a User Recipe
          • Delete a User Recipe
          • Legacy: "Own" Recipe
            • Create "Own" Recipe
            • Update "Own" Recipe
            • Remove "Own" Recipe
        • AI Food Log
          • Process Ai Food
        • Legacy (ownFoods and ownRecipes)
          • Create "own" Food Item
          • Update "own Food"
          • Remove "own" Food Item
      • Journey Status
        • Start Journeys
        • Journey Status
        • Toggle Task Completed
      • Lab Tests
        • Add Biomarker
        • Update Biomarker
        • Add Biomarker Result
        • Add Biomarker Category
        • Update Biomarker Category
        • Remove Biomarker Category
        • Add Lab Test Report
        • Delete Lab Test Report
        • Update Lab Test Report
        • Create Recommended Supplement
        • Update Recommended Supplement
        • Remove Recommended Supplement
        • Create Recommended Article
        • Update Recommended Article
        • Remove Recommended Supplement
      • Meal Plan
        • Create Meal Plan Template
          • Custom Options
          • From Days
          • From Scratch
        • Assign a Meal Plan Template to a User
        • Generate Simple Meal Plan
        • Generate Meal Plan
        • Start Over Meal Plan
        • Swap Meals
        • Simplified Meal Tracking
          • Create a Meal Tracker Entry
        • Remove Meal Plan
        • Remove Meal Plan Recipe
      • Recipes
        • Add new recipe
        • Add Favorite Recipe
      • Shopping List
        • Add Multiple Recipes to the Shopping List
        • Add a Recipe to the Shopping List
        • Bulk Check/Uncheck Items
        • Check/Uncheck an Item
        • Clear Checked Items
        • Clear Shopping List
        • Remove Recipe
        • Update Serving Number
      • Subscriptions
        • Update Subscription
      • Supplement Plans
        • Create supplement plan for user
        • Update user supplement plan
        • Add Supplement
        • Update Supplement
      • Tracking
        • Activity and Exercise
          • Add Exercise Entry
          • Delete Exercise Entry
        • Checklists
          • Create my Checklist Item
          • Delete my Checklist Item
        • Daily Recap
          • Create a daily recap question
          • Select Daily Recap Questions
          • Delete a Daily Recap Question
        • Sleep
          • Add Sleep Time
          • Add Sleep Quality Score
        • Steps
          • Add Steps Count
          • Delete Steps Count
        • Heart Rate
          • Add Heart Rate
          • Delete Heart Rate
        • HRV
          • Add HRV
          • Delete HRV
        • Water and Hydration
        • Weight
          • Add Weight Entry
          • Remove Weight Entry
        • User Tracker Goals
          • Create User Goal
          • Update User Goal
          • Remove User Goal
      • Users
        • Authenticate using a Magic Link
        • Create User
        • Custom Attributes
        • Delete a User Account
        • Login User
        • Merge User Accounts
        • Request Reset Password
        • Reset Password
        • Request Password Reset email
        • Sensitive Profile Attributes
        • Update Profile
        • Update User's Program
        • User's Restrictions
        • Update Meal Plan Settings
        • User's Goals
        • Legacy User Mutations
          • Legacy | User's Biomarkers
          • User's Meal Plan Settings (deprecated)
      • WGPT
        • Add user to journey
  • Objects
    • Appointments
      • Appointment
      • Appointment Type
      • Appointment Credit
      • Attendee
      • Coach
    • Common
      • User
      • Adherence
      • Aisle Name
      • CPC
      • CPCIngredientGroup
      • Meal Times
      • Menu Item
      • Own Serving
      • Own Nutrients
      • MacroNutrientsRangeInput
      • Range
      • Tracker
      • Restaurant
    • Food Logs
      • Food Filter
      • Ingredient Amount
      • Ingredients
      • Own Recipe Ingredient
      • Meal Type
      • Nutrients
        • Nutrient Enum
      • Portions
      • Servings
      • AI Food Log
        • Food Analysis
    • Meal Plan
      • Debug Meal Plan Conditions
      • Meal
      • Meal Plan Day
      • Maximum Time per Meal
      • Maximum Ingredient Count
      • Meal Plan Template
      • Simple Meal Plan Filters
    • Recipe
      • Recipe
        • Tags
        • Cuisines
      • Recipe Swap Options
      • Parsed Ingredient Lines
      • Nutritional Info
      • Nutrients Per Serving
      • Calories Per Serving
      • Relative Calories
      • Source
      • Ingredients
      • Units of Measurement
    • Lab Tests
      • Article
      • Biomarker
    • Supplement
    • Assessments
      • Question
      • Answer
    • Content
      • Content Library
      • Content Categories
      • Content Tag
    • WGPT
      • Journey
      • dayJourney
      • Interaction
  • Case Studies
    • Reverse Health Case Study
Powered by GitBook
On this page
  • Pagination
  • Cursor-based Pagination
  • Forward pagination arguments
  • Backward pagination arguments
  • Examples
  • Slicing

Was this helpful?

  1. Guides
  2. Tutorials and Walkthroughs

Pagination

Using pagination and slicing to work with search queries

PreviousFood Log GuideNextExecuting Multiple Mutations

Last updated 1 year ago

Was this helpful?

Use Pagination to query a list of data in discrete parts. Also, use the cursor-based pagination to select which set of results to retrieve from a connection.

Implementing pagination in data-heavy queries helps to:

  • Optimize the application performance

  • Reduce the load time the application is rendering the results in the UI.

Use Slicing to fetch exactly the number of results from the data.

Learn more about Cursors here:

Pagination

Within pagination, connections retrieve a list of nodes. A node is an object that has a global ID. Nodes are said to be connected by edges.

  • node: Used to select the fields that you want to retrieve from the node at each edge.

  • edges: Used to select the fields that you want to retrieve from each edge in the connection. The edges field is similar to a for-loop because it retrieves the selected fields from each edge in the connection.

query {
 edges 
  {
    node
     {
      name
     }
  }
}

The following example retrieves the list of restaurants:

{
  restaurantSearch(
    query:"Mexican Restaurant") 
  {
    edges
    {
     node
      {
        name
       }   
    }
 }
}
{
  "data": {
    "restaurantSearch": {
      "edges": [
        {
          "node": {
            "name": "The Islander Restaurant"
          }
        },
        {
          "node": {
            "name": "Hua Ting Restaurant"
          }
        },
        {
          "node": {
            "name": "Tom's Restaurant"
       }
      ]
    }
  }
}

Cursor-based Pagination

A cursor is a unique string that identifies a particular row. You can include the following fields in your queries to paginate your results:

  • pageInfo:Each connection can return a PageInfo object which contains general information about the particular page returned. This object includes:

    • hasNextPage: displays whether there are results in the connection after the current segment.

    • hasPreviousPage displays whether there are results in the connection before the current segment.

    • startCursor and endCursor: return non-null opaque strings. Both must be the cursors corresponding to the first and last nodes in edges, respectively.

    • endCursor

  • cursor: A marker for an edge's position in the connection.

Forward pagination arguments

To enable forward pagination arguments, use the following fields:

  • first:it takes a non-negative integer.

  • after: It takes the cursor type and retrieves results after that position.

Pass the cursor of the last edge on the previous page for after.

Backward pagination arguments

  • last:it takes a non-negative integer.

  • before: It takes the cursor type and retrieves the results before that position.

Pass the cursor of the first edge on the next page for before.

Examples

Fetching results using Cursor based pagination

In the following example, use pageInfo and cursor fields in the queries to paginate the results.

{
  restaurantSearch(
    query:"Mexican Restaurant"
    distance: 100
    meals: "meat"
    isOpen:true
    first:3
) 
  {
edges
    {
      node{
        name
        cityTown
        country
        recommendation
      }  
       cursor
    }
    pageInfo{
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
}
}
{
  "data": {
    "restaurantSearch": {
      "edges": [
        {
          "node": {
            "name": "The Islander Restaurant",
            "cityTown": "Mercer Island",
            "country": "US",
            "recommendation": "Prime Rib"
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjA="
        },
        {
          "node": {
            "name": "Hua Ting Restaurant",
            "cityTown": "Hinsdale",
            "country": "US",
            "recommendation": "Young Chow Noodles"
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjE="
        },
        {
          "node": {
            "name": "Tom's Restaurant",
            "cityTown": "Rochester",
            "country": "US",
            "recommendation": "Fried Combo Seafood"
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjI="
        }
      ],
      "pageInfo": {
        "hasNextPage": true,
        "hasPreviousPage": false,
        "startCursor": "YXJyYXljb25uZWN0aW9uOjA=",
        "endCursor": "YXJyYXljb25uZWN0aW9uOjI="
      }
    }
  }
}

The result retrieves three results from the beginning of the connection, and they include a cursor for each edge. In addition, we asked for hasNextPage; that will tell us if there are more edges available, or if we’ve reached the end of this connection.

Fetching results using after parameter

In the following example, use after argument to pass the information of a specific cursor, so results display the information after that cursor. For instance, define the after parameter with the YXJyYXljb25uZWN0aW9uOjI= value, which corresponds to the "name": "Tom's Restaurant" last result retrieved in the previous example:

{
  restaurantSearch(
    query:"Mexican Restaurant"
    distance: 100
    meals: "meat"
    isOpen:true
    first:3
    after: "YXJyYXljb25uZWN0aW9uOjI="
) 
  {
edges
    {
      node{
        name
        cityTown
        country
        recommendation
      }  
       cursor
    }
    pageInfo{
      hasNextPage
      hasPreviousPage
      startCursor
   
    }
}
}
{
  "data": {
    "restaurantSearch": {
      "edges": [
        {
          "node": {
            "name": "Queen's Pizza & Restaurant",
            "cityTown": "Clearwater",
            "country": "US",
            "recommendation": "Vegetarian Delight Pizza"
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjM="
        },
        {
          "node": {
            "name": "Coco Palm Restaurant",
            "cityTown": "Pomona",
            "country": "US",
            "recommendation": "Ropa Vieja"
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjQ="
        },
        {
          "node": {
            "name": "Snook's Bayside Restaurant & Grand Tiki bar",
            "cityTown": "Key Largo",
            "country": "US",
            "recommendation": "Conch Steak"
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjU="
        }
      ],
      "pageInfo": {
        "hasNextPage": true,
        "hasPreviousPage": false,
        "startCursor": "YXJyYXljb25uZWN0aW9uOjM=",
  
      }
    }
  }
}

The results retrieve the next three restaurants listed immediately after the "Tom's Restaurant" which has been retrieved in a previous example.

{
  recipeSearch(
    meals: ["Breakfast"],
    query: "coconut",
    first: 3,
    after: "YXJyYXljb25uZWN0aW9uOjEw"
  ) {
    edges {
      node {
        id
        name
      }
      cursor
    }
    pageInfo {
      endCursor
      hasNextPage
    }
  }
}
{
  "data": {
    "recipeSearch": {
      "edges": [
        {
          "node": {
            "id": "UmVjaXBlOjg5ZmU4Y2JhLWNlNmUtNDM5Zi04NDEzLThkZDI2NmNmZDkyZg==",
            "name": "Coconut Cupcakes"
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjEx"
        },
        {
          "node": {
            "id": "UmVjaXBlOjk5YzBhYThmLTNhOWYtNGY5Mi1hZWQzLWUyZDI0ZDhhOGY2YQ==",
            "name": "Coconut Cupcakes"
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjEy"
        },
        {
          "node": {
            "id": "UmVjaXBlOjEyYjQ4MGE0LThjZmYtNDJkNy1hYjQ4LTU4Mjc4NmZmZTA3MQ==",
            "name": "Coconut Cookies"
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjEz"
        }
      ],
      "pageInfo": {
        "endCursor": "YXJyYXljb25uZWN0aW9uOjEz",
        "hasNextPage": true
      }
    }
  }
}

We can continue the pagination using the endCursor

{
  restaurantSearch(
    query:"Mexican Restaurant"
    distance: 100
    meals: "meat"
    isOpen:true
    first:3
    after: "YXJyYXljb25uZWN0aW9uOjI="
) 
  {
edges
    {
      node{
        name
        cityTown
        country
        recommendation
      }  
       cursor
    }
    pageInfo{
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
}
}
{
  "data": {
    "restaurantSearch": {
      "edges": [
        {
          "node": {
            "name": "Queen's Pizza & Restaurant",
            "cityTown": "Clearwater",
            "country": "US",
            "recommendation": "Vegetarian Delight Pizza"
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjM="
        },
        {
          "node": {
            "name": "Coco Palm Restaurant",
            "cityTown": "Pomona",
            "country": "US",
            "recommendation": "Ropa Vieja"
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjQ="
        },
        {
          "node": {
            "name": "Snook's Bayside Restaurant & Grand Tiki bar",
            "cityTown": "Key Largo",
            "country": "US",
            "recommendation": "Conch Steak"
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjU="
        }
      ],
      "pageInfo": {
        "hasNextPage": true,
        "hasPreviousPage": false,
        "startCursor": "YXJyYXljb25uZWN0aW9uOjM=",
        "endCursor": "YXJyYXljb25uZWN0aW9uOjU="
      }
    }
  }
}

Fetching results using first parameter

The following example uses the first and after aruments to modify the edges returned by the connection, returning edges after the after cursor, and returning the 3 first edges.

{
  restaurantSearch(
    query:"Mexican Restaurant"
    first:3
    after: "YXJyYXljb25uZWN0aW9uOjI="
) 
  {
edges
    {
      node{
        name
        cityTown
        country
      }  
       cursor
    }
    pageInfo{
      hasNextPage
      hasPreviousPage
    }
}
}
{
  "data": {
    "restaurantSearch": {
      "edges": [
        {
          "node": {
            "name": "Queen's Pizza & Restaurant",
            "cityTown": "Clearwater",
            "country": "US"
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjM="
        },
        {
          "node": {
            "name": "Coco Palm Restaurant",
            "cityTown": "Pomona",
            "country": "US"
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjQ="
        },
        {
          "node": {
            "name": "Snook's Bayside Restaurant & Grand Tiki bar",
            "cityTown": "Key Largo",
            "country": "US"
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjU="
        }
      ],
      "pageInfo": {
        "hasNextPage": true,
        "hasPreviousPage": false
      }
    }
  }
}

Slicing

In the following example, we retrieve the first 10 results from a recipe search containing the meal_tag Breakfast and including the term coconut.

{
  restaurantSearch(
    query:"Mexican Restaurant"
    meals: "meat"
    isOpen:true
    first:10
) 
  {
edges
    {
      node{
        name
        cityTown
        country
        recommendation
      }  
    }
}
}
{
  "data": {
    "restaurantSearch": {
      "edges": [
        {
          "node": {
            "name": "The Islander Restaurant",
            "cityTown": "Mercer Island",
            "country": "US",
            "recommendation": "Prime Rib"
          }
        },
        {
          "node": {
            "name": "Hua Ting Restaurant",
            "cityTown": "Hinsdale",
            "country": "US",
            "recommendation": "Young Chow Noodles"
          }
        },
        {
          "node": {
            "name": "Tom's Restaurant",
            "cityTown": "Rochester",
            "country": "US",
            "recommendation": "Fried Combo Seafood"
          }
        },
        {
          "node": {
            "name": "Queen's Pizza & Restaurant",
            "cityTown": "Clearwater",
            "country": "US",
            "recommendation": "Vegetarian Delight Pizza"
          }
        },
        {
          "node": {
            "name": "Coco Palm Restaurant",
            "cityTown": "Pomona",
            "country": "US",
            "recommendation": "Ropa Vieja"
          }
        },
        {
          "node": {
            "name": "Snook's Bayside Restaurant & Grand Tiki bar",
            "cityTown": "Key Largo",
            "country": "US",
            "recommendation": "Conch Steak"
          }
        },
        {
          "node": {
            "name": "Topclass Jamaican Restaurant",
            "cityTown": "Orlando",
            "country": "US",
            "recommendation": "Curry Chicken"
          }
        },
        {
          "node": {
            "name": "Lulu's Restaurant",
            "cityTown": "Van Nuys",
            "country": "US",
            "recommendation": "Greek Salad"
          }
        },
        {
          "node": {
            "name": "Romas Pizzeria & Restaurant",
            "cityTown": "Southgate",
            "country": "US",
            "recommendation": "Ravioli (Meat or Cheese)"
          }
        },
        {
          "node": {
            "name": "Subway Restaurants",
            "cityTown": "Overland Park",
            "country": "US",
            "recommendation": null
          }
        }
      ]
    }
  }
}

https://relay.dev/graphql/connections.htm