subql icon indicating copy to clipboard operation
subql copied to clipboard

[$3000 in SQT] Allow query historical data by block range

Open jiqiang90 opened this issue 2 years ago • 5 comments

Description

We currently allow pass a block height, and get any result less equal than this height

image

We now want to add a filter for block height, so it can filter data with in a specific block range

image

Single entities

To start with we should have the ability to query an entity by its id and specify a block range. We need to consider that we only return 100 results and there might be more in the block range.

Possible example query:


{
  # current single entity query
  example1: entity(id: 'foo') {
    id
    field1
    field2
  }
  # extend the current query
  example2: entity(id: 'foo', blockRange: [0, 100]) {
    id
    field1
    field2
  }
  # a new entity name
  example3: entityHistory(id: 'foo', blockRange: [0, 100]) {
    id
    field1
    field2
  }
}

Example response:


{
  example1: {
    id: 'foo',
    field1: 1,
    field2: 'bar',
  },
  example2: {
    // Keyed by block height
    5: {
      id: 'foo',
      field1: 1,
      field2: 'bar',
    },
    10: {
      id: 'foo',
      field1: 2,
      field2: 'bazz',
    },
    90: null, // indicates the entity was deleted
  },
  // example3 same result as example 2
}

Multiple entities

This is more complex and can come as another improvement at a later stage

Requirements

  • Tests which generate a schema and correctly show gql being converted to the appropriate sql
  • Documentation should be updated to include how to use this feature
  • Backwards compatible, i.e it should not change the behaviour of any current queries
  • Work with all other graphql plugins and features such as filtering, ordering, relations

jiqiang90 avatar Jul 17 '23 04:07 jiqiang90

Will take this up!

abhishek818 avatar Aug 15 '24 10:08 abhishek818

Will take this up!

@abhishek818 i have assigned you to this. Let us know if you have any questions

stwiname avatar Aug 18 '24 21:08 stwiname

Will take this up!

@abhishek818 i have assigned you to this. Let us know if you have any questions

Added a query in draft PR, pls have a look.

abhishek818 avatar Aug 19 '24 21:08 abhishek818

hey @stwiname is this still open. like I see a draft PR but there is no contiuation of it!

and also is this is still part of developer guild !

Gmin2 avatar Sep 03 '25 16:09 Gmin2

@Gmin2, yes this is still open. The existing PR has been abandoned so feel free to pick this up

stwiname avatar Sep 04 '25 04:09 stwiname