# Metadata to determine if there are more results

**URL:** <https://discuss.dgraph.io/t/metadata-to-determine-if-there-are-more-results/15422>\
**Category:** GraphQL\
**Tags:** kind:question\
**Created:** [August 29, 2021, 11:25am UTC](https://discuss.dgraph.io/t/metadata-to-determine-if-there-are-more-results/15422 "2021-08-29T11:25:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![charklewis](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/charklewis/32/6282_2.png) [@charklewis](https://discuss.dgraph.io/u/charklewis)\
**Post date:** [August 29, 2021, 11:25am UTC](https://discuss.dgraph.io/t/metadata-to-determine-if-there-are-more-results/15422/1 "2021-08-29T11:25:45Z")

</div>

When performing pagination type queries, is there a way to determine if there are more results? I can see I can use the `offset` and `first` parameters but in the response it doesn’t tell me if there are any more results. Is this possible?

---

<div class="post-metadata">

**Author:** ![charklewis](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/charklewis/32/6282_2.png) [@charklewis](https://discuss.dgraph.io/u/charklewis)\
**Post date:** [October 31, 2021, 1:10am UTC](https://discuss.dgraph.io/t/metadata-to-determine-if-there-are-more-results/15422/2 "2021-10-31T01:10:39Z")

</div>

Does anyone have any ideas ?

---

<div class="post-metadata">

**Author:** ![jdgamble555](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jdgamble555/32/7503_2.png) [@jdgamble555](https://discuss.dgraph.io/u/jdgamble555)\
**Post date:** [October 31, 2021, 1:22am UTC](https://discuss.dgraph.io/t/metadata-to-determine-if-there-are-more-results/15422/3 "2021-10-31T01:22:22Z")

</div>

Generally speaking, get the total count and subtract the offset.

J

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [October 31, 2021, 4:38am UTC](https://discuss.dgraph.io/t/metadata-to-determine-if-there-are-more-results/15422/4 "2021-10-31T04:38:27Z")

</div>

You can do a separate block that returns the count of all and then use it to figure out if there are more still.

Let me know if you need an example

---

<div class="post-metadata">

**Author:** ![BenW](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/benw/32/7532_2.png) [@BenW](https://discuss.dgraph.io/u/BenW)\
**Post date:** [October 31, 2021, 10:01am UTC](https://discuss.dgraph.io/t/metadata-to-determine-if-there-are-more-results/15422/5 "2021-10-31T10:01:25Z")

</div>

The way I solved this problem:

GraphQL query:

```auto
query PaginateParagraphs($slug: String!, $first: Int!, $offset: Int!){
  paginateParagraphs(slug: $slug, first: $first, offset: $offset) {
    id
    speaker {
      name
    }
  }
  paginateParagraphsMetadata(slug: $slug) {
    total_count
  }
}

```

schema.graphql:

```auto
  paginateParagraphs(slug: String!, first: Int!, offset: Int!): [Paragraph] @custom(dql: """
    query paginateParagraphs(func: uid(paragraphs), first: $first, offset: $offset) @cascade {
      id: uid
      speaker: Paragraph.speaker {
        name: Speaker.name
      }
    }
  }
  """)

  paginateParagraphsMetadata(slug: String!): Metadata @custom(dql: """
    query q($slug: string) {
      var(func: type(Transcript)) @filter(eq(Transcript.slug, $slug)) {
        Transcript.paragraphs {
          a as count(uid)
        }
      }

      paginateParagraphsMetadata() @normalize {
        total_count : sum(val(a))
      }
    }
   """)

```

As for how to determine whether there are more results, I use [SvelteQuery](https://sveltequery.vercel.app/guides/infinite-queries) (Based on [ReactQuery](https://react-query.tanstack.com/guides/infinite-queries#_top)), and pass in a `getNextPageParam` function that calculates whether there is another page based on how many results have been fetched (no. of pages \* amount of results per page), and whether this number is higher than the total\_count.

```javascript
  const paragraphQueryResult = useInfiniteQuery('paragraphsQuery', getParagraphs, {
    getNextPageParam: (lastGroup, pages) => {
      const total = lastGroup.paginateParagraphsMetadata.total_count;

      if (pages.length * limit >= total) {
        return undefined;
      } else {
        return pages.length * limit
      }
    }
  });

```

Let me know if any of that doesn’t make sense.
