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

Commit

Permalink
Rewrite GraphQL query type and operation resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
deekerno committed Dec 15, 2023
1 parent c2015e2 commit f1f6005
Show file tree
Hide file tree
Showing 18 changed files with 3,149 additions and 1,894 deletions.
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 {
id: ID!
block: Block! @join(on:hash)
height: U64! @search
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

0 comments on commit f1f6005

Please sign in to comment.