Skip to content

Commit

Permalink
Improve README and add TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
darunrs committed May 21, 2024
1 parent 8cc9810 commit 028fcc2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
14 changes: 9 additions & 5 deletions block-streamer/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// TODO: Improve README further

Generating schema.json
graphql-client introspect-schema --output PATH_TO_SOMEWHERE HASURA_ENDPOINT/v1/graphql --header 'x-hasura-role: SOME_HASURA_ROLE'
## GraphQL Code Generation
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 Rust types file for query
graphql-client generate --schema-path PATH_TO_SCHEMA_JSON --response-derives 'Debug' --output-directory PATH_TO_GRAPHQL_QUERIES_FOLDER PATH_TO_QUERY_GRAPHQL_FILE
After the codegen comples, you may need to manually modify the file further to resolve issues such as "super::date" not being found.
### 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`
1 change: 1 addition & 0 deletions block-streamer/src/graphql/queries/get_bitmaps_exact.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: Replace this file with query agaisnt production Indexer
#![allow(clippy::all, warnings)]
pub struct GetBitmapsExact;
pub mod get_bitmaps_exact {
Expand Down
1 change: 1 addition & 0 deletions block-streamer/src/graphql/queries/get_bitmaps_wildcard.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: Replace this file with query agaisnt production Indexer
#![allow(clippy::all, warnings)]
pub struct GetBitmapsWildcard;
pub mod get_bitmaps_wildcard {
Expand Down

0 comments on commit 028fcc2

Please sign in to comment.