Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Problems with filter in graphql playground #1254

Closed
chlenc opened this issue Aug 11, 2023 · 11 comments
Closed

Problems with filter in graphql playground #1254

chlenc opened this issue Aug 11, 2023 · 11 comments

Comments

@chlenc
Copy link

chlenc commented Aug 11, 2023

GM my indexer family
Finaly I have deployed my indexer in a docker compose, the playground is alive on
https://spark-indexer.spark-defi.com/api/playground/swaygang/spark_indexer

I'm trying to get buy and sell orders from graphql API, to do that I need to match 3 fields: status, asset0, asset1,

I'm using that query to fetch the data

query buy{
  orderentity(offset: 0, filter: {
    asset0: {equals: "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8"},
    status: { equals: "Canceled"},	
    # asset0: {equals: "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8"}
  }){
    id
		status
    asset0
    asset1
}

and response is "data": []

But if I moving filters that way

filter: {
    status: { equals: "Canceled"},	
    asset0: {equals: "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8"},
  }

response will be like that
And asset0 is wrong in that response

{
  "data": [
    {
      "asset0": "17e68049bb3cf21a85f00778fde367465bbd8263e8d4f8e47e533fe0df865658",
      "asset1": "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8",
      "id": 1,
      "status": "Canceled"
    },
    {
      "asset0": "17e68049bb3cf21a85f00778fde367465bbd8263e8d4f8e47e533fe0df865658",
      "asset1": "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8",
      "id": 2,
      "status": "Canceled"
    },
    {
      "asset0": "17e68049bb3cf21a85f00778fde367465bbd8263e8d4f8e47e533fe0df865658",
      "asset1": "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8",
      "id": 3,
      "status": "Canceled"
    },
    {
      "asset0": "17e68049bb3cf21a85f00778fde367465bbd8263e8d4f8e47e533fe0df865658",
      "asset1": "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8",
      "id": 4,
      "status": "Canceled"
    }
  ]
}

Looks like only first filter line works
Please help me to figure out how to build request with

{
status": "Canceled"
asset0": "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8",
asset1": "17e68049bb3cf21a85f00778fde367465bbd8263e8d4f8e47e533fe0df865658",
}
@chlenc
Copy link
Author

chlenc commented Aug 11, 2023

Default host: aarch64-apple-darwin
fuelup home: /Users/alexey/.fuelup

installed toolchains

beta-3-aarch64-apple-darwin
latest-aarch64-apple-darwin (default)
hotfix
my-custom-toolchain

active toolchain

latest-aarch64-apple-darwin (default)
forc : 0.42.1
- forc-client
- forc-deploy : 0.42.1
- forc-run : 0.42.1
- forc-doc : 0.42.1
- forc-explore : 0.28.1
- forc-fmt : 0.42.1
- forc-index : 0.19.4
- forc-lsp : 0.42.1
- forc-tx : 0.42.1
- forc-wallet : 0.2.4
fuel-core : 0.18.3
fuel-indexer : 0.19.4

fuels versions

forc : 0.43
forc-wallet : 0.44.0

@ra0x3
Copy link
Contributor

ra0x3 commented Aug 11, 2023

@chlenc

An example of submitting a raw SQL query:

  1. Start your indexer with --accept-sql-queries
fuel-indexer run --accept-sql-quries
  1. Submit a query
curl -X POST http://localhost:29987/api/:namespace/:identifer -d '{"query":"SELECT COUNT(*) FROM swaygang.spark_indexer WHERE status = 'Cancelled';"}'

Let me know if this helps :)

@chlenc
Copy link
Author

chlenc commented Aug 11, 2023

@chlenc

An example of submitting a raw SQL query:

  1. Start your indexer with --accept-sql-queries
fuel-indexer run --accept-sql-quries
  1. Submit a query
curl -X POST http://localhost:29987/api/:namespace/:identifer -d '{"query":"SELECT COUNT(*) FROM swaygang.spark_indexer WHERE status = 'Cancelled';"}'

Let me know if this helps :)

I have redeployed the indexer using that docker-compose file (added --accept-sql-queries)
https://github.com/compolabs/spark/blob/beta-3/spark-indexer/docker-compose.yaml#L20

Trying to get some data from the server
curl -X POST https://spark-indexer.spark-defi.com/api/playground/swaygang/spark_indexer -d '{"query":"SELECT COUNT(*) FROM swaygang.spark_indexer WHERE status = 'Cancelled';"}'

But there is no result
image

There are my logs:
docker-compose-logs.txt

Server toolchain

Default host: x86_64-unknown-linux-gnu
fuelup home: /home/ubuntu/.fuelup

installed toolchains
--------------------
beta-3-x86_64-unknown-linux-gnu
latest-x86_64-unknown-linux-gnu (default)

active toolchain
-----------------
latest-x86_64-unknown-linux-gnu (default)
  forc : 0.42.1
    - forc-client
      - forc-deploy : 0.42.1
      - forc-run : 0.42.1
    - forc-doc : 0.42.1
    - forc-explore : 0.28.1
    - forc-fmt : 0.42.1
    - forc-index : 0.19.4
    - forc-lsp : 0.42.1
    - forc-tx : 0.42.1
    - forc-wallet : 0.2.4
  fuel-core : 0.18.3
  fuel-indexer : 0.19.4

fuels versions
---------------
forc : 0.43
forc-wallet : 0.44.0

@chlenc
Copy link
Author

chlenc commented Aug 11, 2023

After that query
curl -X POST https://spark-indexer.spark-defi.com/api/playground/swaygang/spark_indexer -d '{"query":"SELECT COUNT(*) FROM swaygang.spark_indexer;"}'
I see this logs in a docker-container

spark-indexer-fuel-indexer-1  | 2023-08-11T16:28:52.311886Z  INFO tower_http::trace::on_request: 88: started processing request
spark-indexer-fuel-indexer-1  | 2023-08-11T16:28:52.311940Z  INFO tower_http::trace::on_response: 254: finished processing request latency=56 μs status=405

@ra0x3
Copy link
Contributor

ra0x3 commented Aug 11, 2023

@chlenc

  • Is your query correct?
  • What I gave you was intended to be just an example
  • Try this query
SELECT COUNT(*) FROM swaygang_spark_indexer.orderentity;

@chlenc
Copy link
Author

chlenc commented Aug 11, 2023

{"query":"SELECT COUNT(*) FROM swaygang_spark_indexer.orderentity;"}

{
    "details": "GraphQL error: GraphQl Parser error: Syntax { message: \" --> 1:1\\n  |\\n1 | SELECT COUNT(*) FROM swaygang_spark_indexer.orderentity;\\n  | ^---\\n  |\\n  = expected executable_definition\", start: Pos(1:1), end: None }.",
    "success": "false"
}

{"query":"SELECT COUNT(*) FROM swaygang_spark.indexer.orderentity;"}

{
    "details": "GraphQL error: GraphQl Parser error: Syntax { message: \" --> 1:1\\n  |\\n1 | SELECT COUNT(*) FROM swaygang_spark.indexer.orderentity;\\n  | ^---\\n  |\\n  = expected executable_definition\", start: Pos(1:1), end: None }.",
    "success": "false"
}

@ra0x3
Copy link
Contributor

ra0x3 commented Aug 11, 2023

@chlenc

  • That first error seems to be because you do not appear to be submitting the query to the SQL endpoint /api/sql/:namespace/:identifier
    • I can tell because it's trying to parse your SQL query as GraphQL
  • Your second example is also incorrect because swaygang_spark.indexer.orderentity is not valid SQL (in this context)

You want:

curl -X POST \
    https://spark-indexer.spark-defi.com/api/sql/swaygang/spark_indexer \
    -d '{"query":"SELECT COUNT(*) FROM swaygang_spark_indexer.orderentity;"}' \
    -H "Content-type: application/json"

Output is:

{"data":[]}

@chlenc
Copy link
Author

chlenc commented Aug 11, 2023

@chlenc

  • That first error seems to be because you do not appear to be submitting the query to the SQL endpoint /api/sql/:namespace/:identifier

    • I can tell because it's trying to parse your SQL query as GraphQL
  • Your second example is also incorrect because swaygang_spark.indexer.orderentity is not valid SQL

curl -X POST http://localhost:29987/api/sql/:namespace/:identifer -d '{"query":"SELECT COUNT(*) FROM swaygang_spark_indexer.orderentity;"}'

Got it, that works, but the result is empty
URL: https://spark-indexer.spark-defi.com/api/sql/swaygang/spark_indexer
req: {"query":"SELECT * FROM swaygang_spark_indexer.orderentity;"}
result:

{
    "data": []
}

But the GraphQL request is not empty
URL: https://spark-indexer.spark-defi.com/api/graph/swaygang/spark_indexer
req: {"query": "query buy {\n orderentity(offset: 0) {\n id\n status\n asset0\n asset1\n }\n}\n"}
result:

{
    "data": [{
        "asset0": "17e68049bb3cf21a85f00778fde367465bbd8263e8d4f8e47e533fe0df865658",
        "asset1": "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8",
        "id": 1,
        "status": "Canceled"
    }, {
        "asset0": "17e68049bb3cf21a85f00778fde367465bbd8263e8d4f8e47e533fe0df865658",
        "asset1": "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8",
        "id": 2,
        "status": "Canceled"
    }, {
        "asset0": "17e68049bb3cf21a85f00778fde367465bbd8263e8d4f8e47e533fe0df865658",
        "asset1": "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8",
        "id": 3,
        "status": "Canceled"
    }, {
        "asset0": "17e68049bb3cf21a85f00778fde367465bbd8263e8d4f8e47e533fe0df865658",
        "asset1": "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8",
        "id": 4,
        "status": "Canceled"
    }]
}

@ra0x3
Copy link
Contributor

ra0x3 commented Aug 11, 2023

@chlenc

  • If you log into your database and run the query SELECT COUNT(*) FROM swaygang_spark_indexer.orderentity; what result do you get?

@ra0x3
Copy link
Contributor

ra0x3 commented Aug 11, 2023

@chlenc

  • Let me clarify, the functionality works, I gave you a bad example query - try this:
curl -X POST https://spark-indexer.spark-defi.com/api/sql/swaygang/spark_indexer \
  -d '{"query":"select json_agg(t) from (select * from swaygang_spark_indexer.orderentity) t;"}' \
  -H "Content-type: application/json"

Response:

{
   "data" : [
      [
         {
            "amount0" : 1000000000,
            "amount1" : 300000000000,
            "asset0" : "17e68049bb3cf21a85f00778fde367465bbd8263e8d4f8e47e533fe0df865658",
            "asset1" : "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8",
            "fulfilled0" : 0,
            "fulfilled1" : 0,
            "id" : 1,
            "matcher_fee" : 1000,
            "matcher_fee_used" : 0,
            "object" : "\\x0c000000000000000d0000000101000000000000000a000000014000000000000000313765363830343962623363663231613835663030373738666465333637343635626264383236336538643466386534376535333366653064663836353635381e0000000100ca9a3b000000000a000000014000000000000000656161373536663332306631373566303032336138633966633263396237613033636538643731356630346163343961626136396432623764373465373062381e0000000100b864d945000000090000000106000000000000004163746976651e0000000100000000000000001e00000001000000000000000000000000014000000000000000636363346639323439353336636638396162306633316262353266613036633030656130333837646361633538333039323465636635366632646465643361351e000000015881d264000000401e00000001e8030000000000001e000000010000000000000000",
            "owner" : "ccc4f9249536cf89ab0f31bb52fa06c00ea0387dcac5830924ecf56f2dded3a5",
            "status" : "Canceled",
            "timestamp" : 4611686020118905176
         },
         {
            "amount0" : 1000000000,
            "amount1" : 300000000000,
            "asset0" : "17e68049bb3cf21a85f00778fde367465bbd8263e8d4f8e47e533fe0df865658",
            "asset1" : "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8",
            "fulfilled0" : 0,
            "fulfilled1" : 0,
            "id" : 2,
            "matcher_fee" : 1000,
            "matcher_fee_used" : 0,
            "object" : "\\x0c000000000000000d0000000102000000000000000a000000014000000000000000313765363830343962623363663231613835663030373738666465333637343635626264383236336538643466386534376535333366653064663836353635381e0000000100ca9a3b000000000a000000014000000000000000656161373536663332306631373566303032336138633966633263396237613033636538643731356630346163343961626136396432623764373465373062381e0000000100b864d945000000090000000106000000000000004163746976651e0000000100000000000000001e00000001000000000000000000000000014000000000000000636363346639323439353336636638396162306633316262353266613036633030656130333837646361633538333039323465636635366632646465643361351e000000015582d264000000401e00000001e8030000000000001e000000010000000000000000",
            "owner" : "ccc4f9249536cf89ab0f31bb52fa06c00ea0387dcac5830924ecf56f2dded3a5",
            "status" : "Canceled",
            "timestamp" : 4611686020118905429
         },
         {
            "amount0" : 1000000000,
            "amount1" : 300000000000,
            "asset0" : "17e68049bb3cf21a85f00778fde367465bbd8263e8d4f8e47e533fe0df865658",
            "asset1" : "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8",
            "fulfilled0" : 0,
            "fulfilled1" : 0,
            "id" : 3,
            "matcher_fee" : 1000,
            "matcher_fee_used" : 0,
            "object" : "\\x0c000000000000000d0000000103000000000000000a000000014000000000000000313765363830343962623363663231613835663030373738666465333637343635626264383236336538643466386534376535333366653064663836353635381e0000000100ca9a3b000000000a000000014000000000000000656161373536663332306631373566303032336138633966633263396237613033636538643731356630346163343961626136396432623764373465373062381e0000000100b864d945000000090000000106000000000000004163746976651e0000000100000000000000001e00000001000000000000000000000000014000000000000000636363346639323439353336636638396162306633316262353266613036633030656130333837646361633538333039323465636635366632646465643361351e0000000188c0d364000000401e00000001e8030000000000001e000000010000000000000000",
            "owner" : "ccc4f9249536cf89ab0f31bb52fa06c00ea0387dcac5830924ecf56f2dded3a5",
            "status" : "Canceled",
            "timestamp" : 4611686020118986888
         },
         {
            "amount0" : 1000000000,
            "amount1" : 300000000000,
            "asset0" : "17e68049bb3cf21a85f00778fde367465bbd8263e8d4f8e47e533fe0df865658",
            "asset1" : "eaa756f320f175f0023a8c9fc2c9b7a03ce8d715f04ac49aba69d2b7d74e70b8",
            "fulfilled0" : 0,
            "fulfilled1" : 0,
            "id" : 4,
            "matcher_fee" : 1000,
            "matcher_fee_used" : 0,
            "object" : "\\x0c000000000000000d0000000104000000000000000a000000014000000000000000313765363830343962623363663231613835663030373738666465333637343635626264383236336538643466386534376535333366653064663836353635381e0000000100ca9a3b000000000a000000014000000000000000656161373536663332306631373566303032336138633966633263396237613033636538643731356630346163343961626136396432623764373465373062381e0000000100b864d945000000090000000106000000000000004163746976651e0000000100000000000000001e00000001000000000000000000000000014000000000000000636363346639323439353336636638396162306633316262353266613036633030656130333837646361633538333039323465636635366632646465643361351e00000001f816d564000000401e00000001e8030000000000001e000000010000000000000000",
            "owner" : "ccc4f9249536cf89ab0f31bb52fa06c00ea0387dcac5830924ecf56f2dded3a5",
            "status" : "Canceled",
            "timestamp" : 4611686020119074552
         }
      ]
   ]
}

@chlenc
Copy link
Author

chlenc commented Aug 11, 2023

curl -X POST https://spark-indexer.spark-defi.com/api/sql/swaygang/spark_indexer \
  -d '{"query":"select json_agg(t) from (select * from swaygang_spark_indexer.orderentity) t;"}' \
  -H "Content-type: application/json"

Thank you very much ser, this is a big step for us. This request works for me. I'm going to go figure out how to make filters🫡

@chlenc chlenc closed this as completed Aug 11, 2023
@FuelLabs FuelLabs locked and limited conversation to collaborators Aug 11, 2023
@ra0x3 ra0x3 converted this issue into discussion #1262 Aug 11, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants