# Querying for associated diseases doesn't return full list

**URL:** <https://community.opentargets.org/t/querying-for-associated-diseases-doesnt-return-full-list/1563>\
**Category:** GraphQL API\
**Created:** [26 September 2024 00:32 UTC](https://community.opentargets.org/t/querying-for-associated-diseases-doesnt-return-full-list/1563 "2024-09-26T00:32:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HyperValent](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/hypervalent/32/677_2.png) [@HyperValent](https://community.opentargets.org/u/HyperValent)\
**Post date:** [26 September 2024 00:32 UTC](https://community.opentargets.org/t/querying-for-associated-diseases-doesnt-return-full-list/1563/1 "2024-09-26T00:32:01Z")

</div>

Hi! I just recently started using Open Targets for a project that I am working on and it has been exceptional so far!  
I just have one issue regarding using GraphQL API for getting associated diseases based on a target ID.  
I have a query string as formatted below to get the associated diseases of ENSG00000099785:

```auto
query TargetAssociationsQuery(
  $id: String!
) {
  target(ensemblId: $id) {
    id
    approvedSymbol
    associatedDiseases{
      count
      rows {
        disease {
          id
          name
        }
        score
        datasourceScores {
          componentId: id
          score
        }
      }
    }
  }
}

```

The count for associated diseases say 93, which matches what the platform says when searching it up manually. However, the number of diseases that the API request string returns is only 25 diseases.  
I tried setting the size manually to be a large number in a separate query string, but it seems to return even less. Is there a way to get all 93 in one singular string?  
Thank you!

---

<div class="post-metadata">

**Author:** ![carcruz](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/carcruz/32/276_2.png) [@carcruz](https://community.opentargets.org/u/carcruz)\
**Post date:** [26 September 2024 01:08 UTC](https://community.opentargets.org/t/querying-for-associated-diseases-doesnt-return-full-list/1563/2 "2024-09-26T01:08:17Z")

</div>

Hi!

Thank you for your kind words, and we’re glad to hear that you’re finding Open Targets useful for your project!

Regarding your question, the behavior you’re seeing is due to the default pagination that’s applied to the `associatedDiseases` field in our GraphQL API. By default, only 25 items are returned unless otherwise specified. To retrieve more results in a single query, you can use the `page` (with `size` and `index`) argument within your `associatedDiseases` query.

Here’s an updated version of your query that specifies the `size` and `index` argument to return more results in one call:

```graphql
query TargetAssociationsQuery(
  $id: String!
) {
  target(ensemblId: $id) {
    id
    approvedSymbol
    associatedDiseases (page: {size: 100, index: 1}) { # Specify the size & index here
      count
      rows {
        disease {
          id
          name
        }
        score
        datasourceScores {
          componentId: id
          score
        }
      }
    }
  }
}

```

In this example, I’ve set the size to 100, but you can adjust it to match the exact number of associated diseases (93 in this case).  
If the total count of associations is higher than what can be returned in one query (the limit we use in our UI is **500** ), you can iterate through multiple pages using the `index` argument to paginate through the results.

I hope this helps

Carlos

---

<div class="post-metadata">

**Author:** ![HyperValent](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/hypervalent/32/677_2.png) [@HyperValent](https://community.opentargets.org/u/HyperValent)\
**Post date:** [26 September 2024 14:27 UTC](https://community.opentargets.org/t/querying-for-associated-diseases-doesnt-return-full-list/1563/3 "2024-09-26T14:27:12Z")

</div>

Hello @carcruz

Thank you for the quick reply. I tried implementing what you told me, but it seems all that did was return nothing at all:

```auto
{'data': {'target': {'id': 'ENSG00000099785', 'approvedSymbol': 'MARCHF2', 'associatedDiseases': {'count': 93, 'rows': []}}}}

```

```auto
  query TargetAssociationsQuery(
      $id: String!
    ) {
      target(ensemblId: $id) {
        id
        approvedSymbol
        associatedDiseases (page: {size: 100, index: 1}) {
          count
          rows {
            disease {
              id
              name
            }
            score
            datasourceScores {
              componentId: id
              score
            }
          }
        }
      }
    }

```

---

<div class="post-metadata">

**Author:** ![carcruz](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/carcruz/32/276_2.png) [@carcruz](https://community.opentargets.org/u/carcruz)\
**Post date:** [26 September 2024 23:01 UTC](https://community.opentargets.org/t/querying-for-associated-diseases-doesnt-return-full-list/1563/4 "2024-09-26T23:01:23Z")

</div>

> [@HyperValent](#):
>
> `'ENSG00000099785'`

Oh, sorry, my mistake. The pagination index starts from **0** , not **1**.

This is the updated query:

```graphql
query TargetAssociationsQuery(
      $id: String!
    ) {
      target(ensemblId: $id) {
        id
        approvedSymbol
        associatedDiseases (page: {size: 100, index:0}) {
          count
          rows {
            disease {
              id
              name
            }
            score
            datasourceScores {
              componentId: id
              score
            }
          }
        }
      }
    }

```
