Consensys/ethql

Only fetch block transactions when necessary

raulk opened this issue · 0 comments

raulk commented

Currently we are calling web3.eth.getBlock(..., true) when resolving a block, which means that we are fetching all transactions from JSON-RPC unconditionally.

It is possible that the inner query does not request any transactions, e.g.

block(number: 123) {
  parent {
    hash
  }
}

The above case it would've been superfluous to fetch transactions.

Goal:

Make ethql intelligent enough so that it calls getBlock(number, true) only when resolving the query would require fetching all transaction data. In all other cases, it would call getBlock(number, false).

Transactions should be fetched when the query requests these fields:

  • transactions
  • transactionsInvolving
  • transactionsParticipants

NOT with:

  • transactionAt: the resolution logic should change to call web3.eth.getTransactionFromBlock.

Design:

To decide whether to fetch transaction or not, we should use the 4th parameter the GraphQL resolvers, as it gives us access to the "GraphQL Resolve Info" object. See https://graphql.org/graphql-js/type/#graphqlobjecttype.

See library: https://github.com/jakepusateri/graphql-list-fields for a way to obtain a list of the inner fields queried.