Skip to content
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

feat: Query Hasura Endpoint through Block Streamer #745

Merged
merged 17 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
296 changes: 295 additions & 1 deletion block-streamer/Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions block-streamer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ borsh = "0.10.2"
cached = "0.49.3"
chrono = "0.4.25"
futures = "0.3.5"
graphql_client = { version = "0.14.0", features = ["reqwest"] }
lazy_static = "1.4.0"
mockall = "0.11.4"
near-lake-framework = "0.7.8"
prometheus = "0.13.3"
prost = "0.12.3"
redis = { version = "0.21.5", features = ["tokio-comp", "connection-manager"] }
reqwest = { version = "^0.11.0", features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1.0.55"
tracing = "0.1.40"
Expand All @@ -31,8 +34,6 @@ wildmatch = "2.1.1"

registry-types = { path = "../registry/types" }
darunrs marked this conversation as resolved.
Show resolved Hide resolved

near-lake-framework = "0.7.8"

[build-dependencies]
tonic-build = "0.10"

Expand Down
14 changes: 14 additions & 0 deletions block-streamer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// TODO: Improve README further
darunrs marked this conversation as resolved.
Show resolved Hide resolved

## GraphQL Code Generation
darunrs marked this conversation as resolved.
Show resolved Hide resolved
Querying a GraphQL requires informing Rust of the correct types to deserialize the response data into. In order to do this, the schema of the GraphQL data needs to be introspected. Following that, the query intended to be called needs to be fully defined. With this information, code can be generated using the graphql-client API. Below are the instructions on how to do so.

### Generating schema.json
Run the following command with the relevant sections replaced. It will create a JSON containing schemas for ALL tables under some Hasura Role.

`graphql-client introspect-schema --output PATH_TO_SOMEWHERE HASURA_ENDPOINT/v1/graphql --header 'x-hasura-role: SOME_HASURA_ROLE'`

### Generating Rust types file for query
Run the following command with the correct arguments to generate a Rust file containing Structs and Modules to deserialize GraphQL responses for that particular query. After the codegen completes, you may need to manually modify the file further to resolve type issues. For example, replacing `super::date` with `String`.

`graphql-client generate --schema-path PATH_TO_SCHEMA_JSON --response-derives 'Debug' --output-directory PATH_TO_GRAPHQL_QUERIES_FOLDER PATH_TO_QUERY_GRAPHQL_FILE`
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query GetBitmapsExact($block_date: date, $receiver_ids: [String!], $limit: Int, $offset: Int) {
darunrs_near_bitmap_v5_actions_index(limit: $limit, offset: $offset, where: {block_date: {_eq: $block_date}, receiver: {receiver: {_in: $receiver_ids}}}) {
bitmap
first_block_height
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query GetBitmapsWildcard($block_date: date, $receiver_ids: String, $limit: Int, $offset: Int) {
darunrs_near_bitmap_v5_actions_index(limit: $limit, offset: $offset, where: {block_date: {_eq: $block_date}, receiver: {receiver: {_regex: $receiver_ids}}}) {
bitmap
first_block_height
}
}
Loading
Loading