Skip to content

[Graphql] graphql query not getting new data #21006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vladilen11 opened this issue Jan 30, 2025 · 3 comments
Open

[Graphql] graphql query not getting new data #21006

vladilen11 opened this issue Jan 30, 2025 · 3 comments
Assignees
Labels

Comments

@vladilen11
Copy link
Contributor

vladilen11 commented Jan 30, 2025

Env

network: testnet
graphql api: https://sui-testnet.mystenlabs.com/graphql

Description

When I use graphql for the first time to query the data, it can query the cursor for each data, then I use the cursor to page it to the last page and when there is new data coming in, it can't retrieve the new data.

this is my query:

Here, after comes from the cursor of a transaction in the previous query. (I save the edge.cursor for each tx)

query {
  transactionBlocks(
    first: 50,
    after:"eyJjIjoxNTc4OTU5NTgsInQiOjIwODY1NzI0MjYsImkiOmZhbHNlfQ",
    filter: {
    changedObject: "0xc2a55e7d2bee29426be17ffe1190fee863acb1de1bc7554ec8d742ee90a16ef7"
    },
  ) {
    
    pageInfo {
      hasNextPage
      endCursor
      
    }
  	edges {
      cursor
      node {
        digest
        effects {
          timestamp
          checkpoint {
            sequenceNumber
          }
        }
      }
    }
  }
}

this is the query result:

{
  "data": {
    "transactionBlocks": {
      "pageInfo": {
        "hasNextPage": false,
        "endCursor": "eyJjIjoxNTc4OTU5NTgsInQiOjIwODY1NzI4MTQsImkiOmZhbHNlfQ"
      },
      "edges": [
        {
          "cursor": "eyJjIjoxNTc4OTU5NTgsInQiOjIwODY1NzI1ODMsImkiOmZhbHNlfQ",
          "node": {
            "digest": "4HBqq8sAPeC45DZDa37XPeV14ePcHeeaCqomUeMg9iNj",
            "effects": {
              "timestamp": "2025-01-30T05:58:45.386Z",
              "checkpoint": {
                "sequenceNumber": 157894652
              }
            }
          }
        },
        {
          "cursor": "eyJjIjoxNTc4OTU5NTgsInQiOjIwODY1NzI2ODUsImkiOmZhbHNlfQ",
          "node": {
            "digest": "63akpDqUQGmMtdrJaw5GRS2eHd1KNV45hbxNGtSXwqtV",
            "effects": {
              "timestamp": "2025-01-30T05:58:48.530Z",
              "checkpoint": {
                "sequenceNumber": 157894664
              }
            }
          }
        },
        {
          "cursor": "eyJjIjoxNTc4OTU5NTgsInQiOjIwODY1NzI4MTQsImkiOmZhbHNlfQ",
          "node": {
            "digest": "JD157EnbMMqAjA3oQ29sY1pRKnCBDHmATqWhDKpd4NcX",
            "effects": {
              "timestamp": "2025-01-30T05:58:51.826Z",
              "checkpoint": {
                "sequenceNumber": 157894677
              }
            }
          }
        }
      ]
    }
  }
}

You can see that there are several new transactions, but the new data is not queried through the previous cursor. The only way to query the new data is to re-query and re-construct the cursor, but this very much affects the efficiency and logic of the query.

https://testnet.suivision.xyz/account/0xb0637946747572b54d4a91ece3b8fc6d370d236dbc70382f5304445cc999a36f?tab=Transaction+Blocks

Image

My goal

I need to page through queries based on the cursor and when there is new data, I can query the last cursor of the previous record for the new data.
Also I would like to confirm how transactionBlocks sets the orderBy or what is the logic of its default orderBy?

Copy link
Contributor

Thank you for opening this issue, a team member will review it shortly. Until then, please do not interact with any users that claim to be from Sui support and do not click on any links!

@wlmyng
Copy link
Contributor

wlmyng commented Jan 30, 2025

Thanks for trying out graphql beta! This is expected behavior: per https://docs.sui.io/concepts/graphql-rpc#consistency, "a future call to fetch the next page of results using the cursors returned by the first query continues to read from the network at checkpoint X, even if data for future checkpoints is now available." This is so that when resolving other components of these transaction blocks, such as the balance changes or output state of objects, we return the correct state as anchored at the time of query.

However, that indeed means that new transactions will not appear when submitting requests with a cursor.

May I ask what your query is serving? Could you instead do last instead of first? Transaction blocks are ordered by when they appear in a checkpoint. If first is specified, or none, the oldest txs appear first, and if last is specified, the latest transaction blocks are returned first.

@vladilen11
Copy link
Contributor Author

vladilen11 commented Feb 1, 2025

@wlmyng You mean by replacing first with last to achieve a descending sort (new data is always at the beginning) Right?

    const response = await publicClient.queryTransactionBlocks({
        filter: {
            ChangedObject: "0xxxxxxx",
        },
        order: 'ascending',
        cursor: lastTxRecord,
        limit: 50,
        options: {
            showEvents: true,
        },
    });

There is also a detail, if you start localnet, with sdk queryTransactionBlocks query data, here the cursor content is the transaction digest, where you can always query to the latest data (if the query process in the new data, you can also query to the new data).

  1. So currently there is another problem, that is, the node rpc's queryTransactionBlocks and graphql's queryTransactionBlocks cursor logic is not consistent.
  2. As well as I found that the data structure of the events they return is not the same (mainly the return of enum type data will be inconsistent)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants