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:
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!
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:
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.