cardano-foundation / cardano-graphql

GraphQL API for Cardano
Apache License 2.0
255 stars 103 forks source link

Query for block reports "Cannot return null for non-nullable field Token.asset" #854

Open zhy827827 opened 6 months ago

zhy827827 commented 6 months ago

Ask a question

curl -X POST -H "Content-Type: application/json" -d '{"query": "{ blocks(where: { number: { _eq: 9751450}}) {hash number epochNo slotNo forgedAt size previousBlock { hash } transactions {block{hash} blockIndex hash fee size includedAt inputs {address sourceTxHash sourceTxIndex value tokens {asset {assetId assetName policyId} quantity}} outputs (order_by: { index: asc }) {address txHash index addressHasScript value paymentCredential tokens { asset {assetId assetName policyId} quantity}}}} }"}' http://localhost:3200/graphql |jq

{
    "errors": [
        {
            "message": "Cannot return null for non-nullable field Token.asset.",
            "locations": [
                {
                    "line": 1,
                    "column": 230
                }
            ],
            "path": [
                "blocks",
                0,
                "transactions",
                8,
                "inputs",
                7,
                "tokens",
                235,
                "asset"
            ],
            "extensions": {
                "code": "INTERNAL_SERVER_ERROR",
                "exception": {
                    "stacktrace": [
                        "Error: Cannot return null for non-nullable field Token.asset.",
                        "    at completeValue (/app/node_modules/graphql/execution/execute.js:560:13)",
                        "    at completeValueCatchingError (/app/node_modules/graphql/execution/execute.js:495:19)",
                        "    at resolveField (/app/node_modules/graphql/execution/execute.js:435:10)",
                        "    at executeFields (/app/node_modules/graphql/execution/execute.js:275:18)",
                        "    at collectAndExecuteSubfields (/app/node_modules/graphql/execution/execute.js:713:10)",
                        "    at completeObjectValue (/app/node_modules/graphql/execution/execute.js:703:10)",
                        "    at completeValue (/app/node_modules/graphql/execution/execute.js:591:12)",
                        "    at completeValueCatchingError (/app/node_modules/graphql/execution/execute.js:495:19)",
                        "    at /app/node_modules/graphql/execution/execute.js:618:25",
                        "    at Array.forEach (<anonymous>)"
                    ]
                }
            }
        },
        {
            "message": "Cannot return null for non-nullable field Token.asset.",
            "locations": [
                {
                    "line": 1,
                    "column": 383
                }
            ],
            "path": [
                "blocks",
                0,
                "transactions",
                8,
                "outputs",
                1,
                "tokens",
                235,
                "asset"
            ],
            "extensions": {
                "code": "INTERNAL_SERVER_ERROR",
                "exception": {
                    "stacktrace": [
                        "Error: Cannot return null for non-nullable field Token.asset.",
                        "    at completeValue (/app/node_modules/graphql/execution/execute.js:560:13)",
                        "    at completeValueCatchingError (/app/node_modules/graphql/execution/execute.js:495:19)",
                        "    at resolveField (/app/node_modules/graphql/execution/execute.js:435:10)",
                        "    at executeFields (/app/node_modules/graphql/execution/execute.js:275:18)",
                        "    at collectAndExecuteSubfields (/app/node_modules/graphql/execution/execute.js:713:10)",
                        "    at completeObjectValue (/app/node_modules/graphql/execution/execute.js:703:10)",
                        "    at completeValue (/app/node_modules/graphql/execution/execute.js:591:12)",
                        "    at completeValue (/app/node_modules/graphql/execution/execute.js:557:21)",
                        "    at completeValueCatchingError (/app/node_modules/graphql/execution/execute.js:495:19)",
                        "    at /app/node_modules/graphql/execution/execute.js:618:25"
                    ]
                }
            }
        }
    ],
  "data": {
    "blocks": [
      {
        "hash": "5a8880a94b8d37860c6c977c2bc6bdef85066a8a014747b141bf32fd336a5fd3",
        "number": 9751450,
        "epochNo": 458,
        "slotNo": "112604865",
        "forgedAt": "2024-01-02T04:52:36Z",
        "size": 28346,
        "previousBlock": {
          "hash": "79c88c83efaf466c2de99e1b9757cb7dc6cb9bbb799c8ae68d8c6dc1288fdf5f"
        },
        "transactions": [
          {
            "block": {
              "hash": "5a8880a94b8d37860c6c977c2bc6bdef85066a8a014747b141bf32fd336a5fd3"
            },
            "blockIndex": 13,
            "hash": "b78d559f7b9672d0cb51fd53207703e7e5f197baca4d2236f0e641bc2bcfcd97",
            "fee": "171573",
            "size": 363,
            "includedAt": "2024-01-02T04:52:36Z",
            "inputs": [
              {
                "address": "addr1qyrdaazl8g64ktvln7rr55vvt9d0kqx8du8v9gaj9agz3fnzwn52yzf9lduqql5tsp5a6d73vyt8zc8unxs8t7pdkszqxj4eq3",
                "sourceTxHash": "8dfba459329e1a8662a07eac5af70ecb46cd3bdb50f910cf2c3b5ed334dbe93e",
                "sourceTxIndex": 0,
                "value": "30927195",
                "tokens": []
              }
            ],
"outputs": [
              {
                "address": "addr1qyfzx4axz2k6fw9q7r3p364zl24vdze4p3f5a6mg9t6d5enzwn52yzf9lduqql5tsp5a6d73vyt8zc8unxs8t7pdkszqu8tj8c",
                "txHash": "b78d559f7b9672d0cb51fd53207703e7e5f197baca4d2236f0e641bc2bcfcd97",
                "index": 0,
                "addressHasScript": false,
                "value": "74385507",
                "paymentCredential": "122357a612ada4b8a0f0e218eaa2faaac68b350c534eeb682af4da66",
                "tokens": []
              }
            ]
          },
.........

Why does Error and Data appear at the same time? The query data originally reported an error, but there is still data returned

saravadeanil commented 2 weeks ago

Hi @Kammerlo I am using the latest release of graphql docker image v8.1.0-mainnet and I am facing the same issue on mainnet network. However, I am not facing this issue on preview network where I am using docker image v8.1.0-preview.

curl -s 'http://localhost:3100' -H 'Content-Type: application/json' --data-binary '{"query":"query transactionByHash($hash: Hash32Hex!) {transactions(where: { hash: { _eq: $hash } } )  {outputs {index txHash tokens {asset {assetName policyId} quantity}}}}","variables":{"hash":"2e334f2364e08d7a7e05993897fa7cd0bd83de2eb0ddb48c6fa8ee8584bfb394"}}' | jq

{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field Token.asset.",
      "locations": [
        {
          "line": 1,
          "column": 124
        }
      ],
      "path": [
        "transactions",
        0,
        "outputs",
        0,
        "tokens",
        0,
        "asset"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Cannot return null for non-nullable field Token.asset.",
            "    at completeValue (/app/node_modules/graphql/execution/execute.js:560:13)",
            "    at completeValueCatchingError (/app/node_modules/graphql/execution/execute.js:495:19)",
            "    at resolveField (/app/node_modules/graphql/execution/execute.js:435:10)",
            "    at executeFields (/app/node_modules/graphql/execution/execute.js:275:18)",
            "    at collectAndExecuteSubfields (/app/node_modules/graphql/execution/execute.js:713:10)",
            "    at completeObjectValue (/app/node_modules/graphql/execution/execute.js:703:10)",
            "    at completeValue (/app/node_modules/graphql/execution/execute.js:591:12)",
            "    at completeValue (/app/node_modules/graphql/execution/execute.js:557:21)",
            "    at completeValueCatchingError (/app/node_modules/graphql/execution/execute.js:495:19)",
            "    at /app/node_modules/graphql/execution/execute.js:618:25"
          ]
        }
      }
    },
    {
      "message": "Cannot return null for non-nullable field Token.asset.",
      "locations": [
        {
          "line": 1,
          "column": 124
        }
      ],
      "path": [
        "transactions",
        0,
        "outputs",
        2,
        "tokens",
        0,
        "asset"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Cannot return null for non-nullable field Token.asset.",
            "    at completeValue (/app/node_modules/graphql/execution/execute.js:560:13)",
            "    at completeValueCatchingError (/app/node_modules/graphql/execution/execute.js:495:19)",
            "    at resolveField (/app/node_modules/graphql/execution/execute.js:435:10)",
            "    at executeFields (/app/node_modules/graphql/execution/execute.js:275:18)",
            "    at collectAndExecuteSubfields (/app/node_modules/graphql/execution/execute.js:713:10)",
            "    at completeObjectValue (/app/node_modules/graphql/execution/execute.js:703:10)",
            "    at completeValue (/app/node_modules/graphql/execution/execute.js:591:12)",
            "    at completeValue (/app/node_modules/graphql/execution/execute.js:557:21)",
            "    at completeValueCatchingError (/app/node_modules/graphql/execution/execute.js:495:19)",
            "    at /app/node_modules/graphql/execution/execute.js:618:25"
          ]
        }
      }
    }
  ],
  "data": {
    "transactions": [
      {
        "outputs": [
          null,
          {
            "index": 1,
            "txHash": "2e334f2364e08d7a7e05993897fa7cd0bd83de2eb0ddb48c6fa8ee8584bfb394",
            "tokens": []
          },
          null,
          {
            "index": 3,
            "txHash": "2e334f2364e08d7a7e05993897fa7cd0bd83de2eb0ddb48c6fa8ee8584bfb394",
            "tokens": []
          }
        ]
      }
    ]
  }
}

Is there a fix or this?

Kammerlo commented 2 weeks ago

@saravadeanil I'll check. I sync up mainnet and take care of it

saravadeanil commented 2 weeks ago

Thanks a lot 🙏 @Kammerlo Just to double-check I tried to check another recent transactions to retrieve token info and it has similar issue.

Transaction:- https://beta.explorer.cardano.org/en/transaction/280af048392cda3a2e3a8f8e47575e1319d4276823ea03d8e45a2ee90733c89c/summary

curl -s 'http://localhost:3100' -H 'Content-Type: application/json' --data-binary '{"query":"query transactionByHash($hash: Hash32Hex!) {transactions(where: { hash: { _eq: $hash } } )  {outputs {index txHash tokens {asset {assetName policyId} quantity}}}}","variables":{"hash":"280af048392cda3a2e3a8f8e47575e1319d4276823ea03d8e45a2ee90733c89c"}}' | jq
{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field Token.asset.",
      "locations": [
        {
          "line": 1,
          "column": 124
        }
      ],
      "path": [
        "transactions",
        0,
        "outputs",
        0,
        "tokens",
        0,
        "asset"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Cannot return null for non-nullable field Token.asset.",
            "    at completeValue (/app/node_modules/graphql/execution/execute.js:560:13)",
            "    at completeValueCatchingError (/app/node_modules/graphql/execution/execute.js:495:19)",
            "    at resolveField (/app/node_modules/graphql/execution/execute.js:435:10)",
            "    at executeFields (/app/node_modules/graphql/execution/execute.js:275:18)",
            "    at collectAndExecuteSubfields (/app/node_modules/graphql/execution/execute.js:713:10)",
            "    at completeObjectValue (/app/node_modules/graphql/execution/execute.js:703:10)",
            "    at completeValue (/app/node_modules/graphql/execution/execute.js:591:12)",
            "    at completeValue (/app/node_modules/graphql/execution/execute.js:557:21)",
            "    at completeValueCatchingError (/app/node_modules/graphql/execution/execute.js:495:19)",
            "    at /app/node_modules/graphql/execution/execute.js:618:25"
          ]
        }
      }
    }
  ],
  "data": {
    "transactions": [
      {
        "outputs": [
          null,
          {
            "index": 1,
            "txHash": "280af048392cda3a2e3a8f8e47575e1319d4276823ea03d8e45a2ee90733c89c",
            "tokens": []
          },
          {
            "index": 2,
            "txHash": "280af048392cda3a2e3a8f8e47575e1319d4276823ea03d8e45a2ee90733c89c",
            "tokens": []
          },
          {
            "index": 3,
            "txHash": "280af048392cda3a2e3a8f8e47575e1319d4276823ea03d8e45a2ee90733c89c",
            "tokens": []
          }
        ]
      }
    ]
  }
}
Kammerlo commented 2 weeks ago

This just happens on mainnet and not on preprod? Did you use the newly introduced local token registry or the global one?

saravadeanil commented 2 weeks ago

This just happens on mainnet and not on preprod?

I just performed the same query on preview network for recent transaction and it works as expected. FYR,

Transaction link:- https://preview.beta.explorer.cardano.org/en/transaction/aecacc3ce9926eea265d1aea88b6d31059431c24d49d76de396693a485099e4c/summary

curl -s 'http://localhost:3100' -H 'Content-Type: application/json' --data-binary '{"query":"query transactionByHash($hash: Hash32Hex!) {transactions(where: { hash: { _eq: $hash } } )  {outputs {index txHash tokens {asset {assetName policyId} quantity}}}}","variables":{"hash":"aecacc3ce9926eea265d1aea88b6d31059431c24d49d76de396693a485099e4c"}}' | jq
{
  "data": {
    "transactions": [
      {
        "outputs": [
          {
            "index": 0,
            "txHash": "aecacc3ce9926eea265d1aea88b6d31059431c24d49d76de396693a485099e4c",
            "tokens": [
              {
                "asset": {
                  "assetName": "4ddffewfewfwegvwevw",
                  "policyId": "ioiavoienavnseonoivanwoevno"
                },
                "quantity": "1"
              }
            ]
          },
          {
            "index": 1,
            "txHash": "aecacc3ce9926eea265d1aea88b6d31059431c24d49d76de396693a485099e4c",
            "tokens": [
              {
                "asset": {
                  "assetName": "4ddffewfewfwegvwevw",
                  "policyId": "ioiavoienavnseonoivanwoevno"
                },
                "quantity": "21063198"
              }
            ]
          },
          {
            "index": 2,
            "txHash": "aecacc3ce9926eea265d1aea88b6d31059431c24d49d76de396693a485099e4c",
            "tokens": []
          }
        ]
      }
    ]
  }
}

Did you use the newly introduced local token registry or the global one?

I am using the below:-

Preview:- METADATA_SERVER_URI="https://metadata.world.dev.cardano.org" Mainnet:- METADATA_SERVER_URI="https://tokens.cardano.org"

@Kammerlo

saravadeanil commented 2 weeks ago

++ Just to inform you, I have synced the mainnet node from scratch after db upgrade. And based on below statement mentioned HERE.

The public Token metadata registry has a limit of daily requests, this can lead to long sync times, when resyncing from scratch. If it's still needed to run with the global environment it's possible by removing the token-metadata-registry from docker-compose.yml. And start it with for Mainnet:

METADATA_SERVER_URI="https://tokens.cardano.org" docker compose up -d

In this case what should be the endpoint used for METADATA_SERVER_URI?

Kammerlo commented 2 weeks ago

Just leave it blank. The default setting is using the local token registry. This will sync from the official github repository and therefore you don't have the daily limit anymore.

Because of the daily limit, we introduced this feature, because some users had issues. Perhaps this will solve your issue as well. I will try in parallel!

saravadeanil commented 2 weeks ago

Thanks for the help. Do we provide official docker image for this component token-metadata-registry? @Kammerlo

Is it this one? https://hub.docker.com/r/cardanofoundation/cf-token-metadata-registry-api/tags

saravadeanil commented 2 weeks ago

I ran the token-metadata-registry container and facing below error:-

Error Code : 0

Message    : FATAL: role "cardano" does not exist

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1773) ~[spring-beans-6.1.3.jar!/:6.1.3]

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599) ~[spring-beans-6.1.3.jar!/:6.1.3]

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521) ~[spring-beans-6.1.3.jar!/:6.1.3]

    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325) ~[spring-beans-6.1.3.jar!/:6.1.3]

    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.3.jar!/:6.1.3]

    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323) ~[spring-beans-6.1.3.jar!/:6.1.3]

    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-6.1.3.jar!/:6.1.3]

    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:312) ~[spring-beans-6.1.3.jar!/:6.1.3]

    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-6.1.3.jar!/:6.1.3]

    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1231) ~[spring-context-6.1.3.jar!/:6.1.3]

    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:949) ~[spring-context-6.1.3.jar!/:6.1.3]

    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624) ~[spring-context-6.1.3.jar!/:6.1.3]

    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.2.2.jar!/:3.2.2]

    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.2.2.jar!/:3.2.2]

    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.2.2.jar!/:3.2.2]

    at org.springframework.boot.SpringApplication.run(SpringApplication.java:334) ~[spring-boot-3.2.2.jar!/:3.2.2]

    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354) ~[spring-boot-3.2.2.jar!/:3.2.2]

    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-3.2.2.jar!/:3.2.2]

    at org.cardanofoundation.tokenmetadata.registry.api.TokenMetadataRegistryApplication.main(TokenMetadataRegistryApplication.java:20) ~[!/:na]

    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]

    at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]

    at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:91) ~[app.jar:na]

    at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53) ~[app.jar:na]

    at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58) ~[app.jar:na]

Caused by: org.flywaydb.core.internal.exception.FlywaySqlException: Unable to obtain connection from database: FATAL: role "cardano" does not exist

postgres container:-

PostgreSQL Database directory appears to contain a database; Skipping initialization

2024-07-04 11:03:45.791 UTC [1] LOG:  starting PostgreSQL 14.10 on x86_64-pc-linux-musl, compiled by gcc (Alpine 13.2.1_git20231014) 13.2.1 20231014, 64-bit

2024-07-04 11:03:45.791 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432

2024-07-04 11:03:45.791 UTC [1] LOG:  listening on IPv6 address "::", port 5432

2024-07-04 11:03:45.814 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"

2024-07-04 11:03:45.819 UTC [23] LOG:  database system was shut down at 2024-07-04 11:01:38 UTC

2024-07-04 11:03:45.820 UTC [24] FATAL:  the database system is starting up

2024-07-04 11:03:45.827 UTC [1] LOG:  database system is ready to accept connections

2024-07-04 11:04:05.001 UTC [88] FATAL:  role "cardano" does not exist

2024-07-04 11:04:16.503 UTC [92] FATAL:  role "cardano" does not exist

2024-07-04 11:04:42.200 UTC [93] FATAL:  role "cardano" does not exist

2024-07-04 11:05:20.270 UTC [95] FATAL:  role "cardano" does not exist

2024-07-04 11:06:11.075 UTC [99] FATAL:  role "cardano" does not exist

2024-07-04 11:07:49.685 UTC [117] FATAL:  role "cardano" does not exist

2024-07-04 11:10:40.587 UTC [137] FATAL:  role "cardano" does not exist
Kammerlo commented 2 weeks ago

Yes we have published official images for the token registry. It's these two:

There could be an issue when migrating from public token registry to local one, since the token registry is saving everything in the same database and is using the same credentials provided in the secrets as the other containers. I'll check it.

saravadeanil commented 2 weeks ago

Hi @Kammerlo thanks for your reply 🙏

Sorry, I am bit confused..you will be checking THIS issue right or something else?

Kammerlo commented 2 weeks ago

I'll need to check all of them :D But I need to wait for my mainnet instance to sync up to tip

saravadeanil commented 2 weeks ago

Aha Danke schön! @Kammerlo

Kammerlo commented 2 weeks ago

So for the token-registry, when syncing from scratch everythings fine and running as planned.

saravadeanil commented 2 weeks ago

Yes, right with token-registry METADATA_SERVER_URI="https://tokens.cardano.org". The mainnet node is able to sync up with latest block height from scratch.

Now, because I was facing issue THIS which performing query to retrieve token information..I started to implement local token-registry and I faced THIS.

Kammerlo commented 2 weeks ago

@saravadeanil Just to be sure regarding the start issues of the local token-registry, because I ran multiple tests and couldn't reproduce it. How are you setting the password? Because it using these files as secrets: Placeholder Secrets If you want to change the DB password you can either change these files or change it directly within the init script of the local token registry here

saravadeanil commented 1 week ago

Hi @Kammerlo, thanks for writing back. Actually, I am attaching the postres secret in same way and able to connect with the postres DB with those credentials. However, after I run the local token-registry it throws the error.

Kammerlo commented 1 week ago

@saravadeanil Just to inform you, I needed to resync due to an unforseen error and the HF is really close by, so this will take some time to fix this issue, so that you aware of this. But I'm on it, Sorry for this issue this long.

saravadeanil commented 1 week ago

@Kammerlo No worries, I really appreciate your help 🙇