hubertursua / ncovph

GraphQL API for COVID-19 data (Philippines)
https://ncovph.com
ISC License
26 stars 4 forks source link

Amount of cases retrieved using the new api. #59

Closed Pipaolo closed 4 years ago

Pipaolo commented 4 years ago

Hello @hyubs, I am trying to use the new api that is based on graphql. I managed to use it in my app, but there is a slight problem for me when it comes to querying all the cases in the Philippines. Whenever I try to fetch it, it only gives me a small amount, why is that? Oh and upon checking the query, I can also give it a limit, but that limit only has a maximum of 50. Is there a way of increasing the amount of cases that the new api can give?

Thank you in advance!!

hubertursua commented 4 years ago

You'll have to loop through to get everything using limit and offset.

Your query should look something like this:

{
  cases {
    countConfirmedCases,
    confirmedCases(
      limit: 50
      offset: 0
    ) {
      caseNumber,
      age,
      sex,
      dateReportConfirmed
    }
  }
}

Use offset to paginate through the data. So for this query, you'll loop with the offset value of 0, 50, 100, 150,... until you exceed the value of countConfirmedCases.

Currently, the max limit is 50. I'll increase that to 500 later. The server should be able to handle 500 without compromise.

I cannot emit all cases because it affects the server's performance. Also, this is to ensure that the API and users of the API won't be affected in the future if we ever have too many cases.

Pipaolo commented 4 years ago

Oh I see, I thought that was a bad way of doing it. How about the amount of requests that users can make? If I were to loop using the limit and offset I might easily max out the number of requests per minute.

It's stated in the website that the requests are limited to 45 per minute.

hubertursua commented 4 years ago

In normal circumstances, you don't need to query a lot. Note that the data only changes once a day, when DOH uploads a data drop. You can store a copy of the data within the app and update it when needed. This will also give a better UX for your app because the app can load the local copy right away.

For what use case do you need to retrieve all cases? If it's for an aggregation, let me know because I can probably provide that as a subquery. But if you are just using it to display all cases on the screen, I recommend you store a local copy instead.

Pipaolo commented 4 years ago

Okay thank you so much for your help!

The use case is that I want to display the all the cases in the app. From your suggestion, I have implement a system that stores the data once the app is opened once, and also it checks if there is an update in the server.

Thank you once again for your help!