3

I'm working on an application which for some of its features has to calculate the total balance of a wallet for a given time range. Here's a query that I've written (I don't have access to the original code at the moment, the following snippet was copied and adjusted from this example, which I also used originally, so it might contain some mistakes if you actually try to run it):

query getBalanceBetweenBlocks($address: String!, $min: Int!, $max: Int!) {
  blocks(where: {number: {_gte: $min, _lte: $max}}) {
    transactions(where: {_or: [
      {inputs:  {address: {_eq: $address}}}
      {outputs: {address: {_eq: $address}}}
    ]}) {
      inputs_aggregate(where:  {address: {_eq: $address}}) {aggregate {sum {value}}}
      outputs_aggregate(where: {address: {_eq: $address}}) {aggregate {sum {value}}}
    }
  }
}

It works correctly, but only if the [$min; $max] range is fairly small, for example $max = $min + 2000. If I try to increase it to, say, $maxblock = $minblock + 5000 the aggregated result is wrong, and I believe it's happening because the [$min; $max] range is actually cut off at some point artificially limiting how much data can be processed per single GraphQL query.

Also, I've tried writing the same query in SQL to interact with cardano-db-sync, and it does work correctly. Unfortunately, I cannot use cardano-db-sync directly which is why I'm using cardano-graphql in the first place.

Does anybody know if that's a problem with cardano-graphql or maybe some other thing on top of it (GraphQL, Hasura etc.), and if there's a way to deal with this problem? While it does perform fairly well, I'd like to see whether aggregating all the inputs/outputs at once is more efficient than doing so in batches (which would also let me simplify the application code in the process).

1 Answer 1

1

cardano-graphql has, according to their wiki, a query result limit of 2,500 items and depth limit 3.

1
  • Thanks for the info. For some reason, this isn't mentioned on the "main page" of the github repo, and I didn't search any folders for further information.
    – Alex F
    Commented Dec 3, 2021 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.