graph-client icon indicating copy to clipboard operation
graph-client copied to clipboard

Auto pagination does not work with nested first

Open matthewlilley opened this issue 3 years ago • 14 comments

Hey @ardatan,

Auto pagination doesn't do anything when first is nested, these should be in the 10s of thousands.

Screenshot_434

Screenshot_435

matthewlilley avatar Jul 13 '22 10:07 matthewlilley

Could you share a reproduction on CodeSandbox or StackBlitz? Thanks!

ardatan avatar Jul 19 '22 13:07 ardatan

Could you share a reproduction on CodeSandbox or StackBlitz? Thanks!

Have you got a repro template for CodeSandbox or StackBlitz I can fork by anychance?

matthewlilley avatar Jul 19 '22 14:07 matthewlilley

Currently we don't have any. I can create one for you if you have issues with those?

ardatan avatar Jul 20 '22 08:07 ardatan

Currently we don't have any right now. I can create one for you if you have issues with those?

Yeah, if you have a basic template I could use for repros that would be great.

matthewlilley avatar Jul 20 '22 16:07 matthewlilley

I created this one but not sure if you use it as an SDK with Node, Browser, ApolloClient or Urql etc. https://codesandbox.io/s/hardcore-antonelli-7e6mlr?file=/example-query.graphql

ardatan avatar Jul 20 '22 17:07 ardatan

I think this PR covers the use case; https://github.com/graphprotocol/graph-client/pull/163

ardatan avatar Jul 22 '22 10:07 ardatan

Available in the latest release! https://github.com/graphprotocol/graph-client/pull/164#issue-1315214243

ardatan avatar Jul 22 '22 17:07 ardatan

Thanks @ardatan! I notice when setting first to >5000, I start seeing these errors:

AggregateError: The skip argument must be between 0 and 5000, but is 6000, The skip argument must be between 0 and 5000, but is 7000, The skip argument must be between 0 and 5000, but is 8000, The skip argument must be between 0 and 5000, but is 9000, The skip argument must be between 0 and 5000, but is 10000, The skip argument must be between 0 and 5000, but is 11000, The skip argument must be between 0 and 5000, but is 12000, The skip argument must be between 0 and 5000, but is 13000, The skip argument must be between 0 and 5000, but is 14000, The skip argument must be between 0 and 5000, but is 15000, The skip argument must be between 0 and 5000, but is 16000, The skip argument must be between 0 and 5000, but is 17000, The skip argument must be between 0 and 5000, but is 18000, The skip argument must be between 0 and 5000, but is 19000, The skip argument must be between 0 and 5000, but is 20000, The skip argument must be between 0 and 5000, but is 21000, The skip argument must be between 0 and 5000, but is 22000, The skip argument must be between 0 and 5000, but is 23000, The skip argument must be between 0 and 5000, but is 24000

I guess this is unexpected?

matthewlilley avatar Jul 22 '22 19:07 matthewlilley

Ah, I see the "skipArgumentLimit" on the auto-pagination transform config. That looks like it'll do the trick.

matthewlilley avatar Jul 22 '22 20:07 matthewlilley

Unfortuately not, it seems anything above 5k will fail.

matthewlilley avatar Jul 22 '22 20:07 matthewlilley

Ok so I think it is not a good idea to have multiple queries for the pagination of the nested fields because we will need to do multiple queries for each nested field and this might take forever on the client side. In case of exceeding the skip limit, we have to make subsequential queries which are blocking each other. @dotansimha Not sure if this is what we want to have in Graph Client.

ardatan avatar Jul 22 '22 23:07 ardatan

@ardatan is there a reason skip is being used? I know the docs, recommend against using using skip for fetching a large amount of enities, which is what we need in this use case (which is to get all positions for a user/contract).

https://thegraph.com/docs/en/querying/graphql-api/#example-using-and-2

matthewlilley avatar Jul 23 '22 09:07 matthewlilley

@matthewlilley Thanks to skip, we can still get all the data we need in a single query;

{
   users(first: 2500) {
      ...
   }
}

becomes the following so it is way faster then sending multiple queries by waiting each other's "last id"

{
  users_0: users(first: 1000) {
    ...
  }
  users_1: users(first: 1000, skip: 1000) {
    ...
  }
  users_2: users(first: 500, skip: 2000) {
     ...
  }
}

However we do this when skip exceeds 5000. But this is a bit tricky for nested fields because in this case we need to make the same query again and again together with the parent selection sets. And this increases the permutation if you have another pagination in the same query.

This will take forever :) Query -> Get Result -> Make another query -> Get Result

But still I will take a look at the issue with nested fields with 5000+ records

ardatan avatar Jul 23 '22 12:07 ardatan

@ardatan Gotcha! The alternative is in the other issue https://github.com/graphprotocol/graph-client/issues/148, but ofc this is problematic as well because you'd need to scan all ID's to get back what you want...

matthewlilley avatar Jul 23 '22 20:07 matthewlilley