Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

enhancement: revamp GraphQL query generation #1450

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
type Block @entity {
type Transaction @entity {
id: ID!
height: U64!
hash: Bytes32! @unique
}

type Transaction @entity {
type Block @entity @queryable {
id: ID!
block: Block! @join(on:hash)
height: U64! @search @unique
hash: Bytes32! @unique
transactions: [Transaction!]!
}

13 changes: 7 additions & 6 deletions examples/hello-world/hello-world/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ use fuel_indexer_utils::prelude::*;
pub mod hello_world_index_mod {

fn hello_world_handler(block_data: BlockData) {
let block = Block::new(block_data.header.height.into(), block_data.id);
block.save();
let mut transactions = vec![];

for transaction in block_data.transactions.iter() {
let tx = Transaction::new(
block_data.id,
Bytes32::from(<[u8; 32]>::from(transaction.id)),
);
let tx = Transaction::new(Bytes32::from(<[u8; 32]>::from(transaction.id)));
tx.save();
transactions.push(tx.id);
}

let block =
Block::new(block_data.header.height.into(), block_data.id, transactions);
block.save();
}
}
2 changes: 1 addition & 1 deletion packages/fuel-indexer-api-server/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use axum::{
Router,
};
use fuel_indexer_database::{IndexerConnectionPool, IndexerDatabaseError};
use fuel_indexer_graphql::graphql::GraphqlError;
use fuel_indexer_graphql::GraphqlError;
use fuel_indexer_lib::{config::IndexerConfig, defaults, utils::ServiceRequest};
use fuel_indexer_schema::db::{manager::SchemaManager, IndexerSchemaDbError};
use hyper::Method;
Expand Down
28 changes: 21 additions & 7 deletions packages/fuel-indexer-api-server/src/uses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use fuel_indexer_database::{
types::{IndexerAsset, IndexerAssetType, IndexerStatus, RegisteredIndexer},
IndexerConnectionPool,
};
use fuel_indexer_graphql::dynamic::{build_dynamic_schema, execute_query};
use fuel_indexer_lib::{
config::{auth::AuthenticationStrategy, IndexerConfig},
defaults,
Expand Down Expand Up @@ -58,13 +57,28 @@ pub(crate) async fn query_graph(
.await
{
Ok(schema) => {
let dynamic_schema = build_dynamic_schema(&schema)?;
let dynamic_schema =
fuel_indexer_graphql::dynamic::build_dynamic_schema(&schema)?;
let user_query = req.0.query.clone();
let response =
execute_query(req.into_inner(), dynamic_schema, user_query, pool, schema)
.await?;
let data = serde_json::json!({ "data": response });
Ok(axum::Json(data))
match fuel_indexer_graphql::query::execute(
req.into_inner(),
dynamic_schema,
user_query,
pool,
schema,
)
.await
{
Ok(response) => {
let data = serde_json::json!({"data": response});
Ok(axum::Json(data))
}
Err(e) => {
let data =
serde_json::json!({"errors": [{"message": e.to_string()}]});
Ok(axum::Json(data))
}
}
}
Err(_e) => Err(ApiError::Http(HttpError::NotFound(format!(
"The graph '{namespace}.{identifier}' was not found."
Expand Down
3 changes: 3 additions & 0 deletions packages/fuel-indexer-graphql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ async-graphql-parser = "5.0"
async-graphql-value = "5.0"
fuel-indexer-database = { workspace = true }
fuel-indexer-database-types = { workspace = true }
fuel-indexer-lib = { workspace = true }
fuel-indexer-schema = { workspace = true, features = ["db-models"] }
fuel-indexer-types = { workspace = true }
indexmap = "2.1"
lazy_static = "1.4"
petgraph = "0.6"
serde_json = { workspace = true }
thiserror = { workspace = true }

Expand Down
Loading
Loading