diff --git a/Cargo.lock b/Cargo.lock index 3e167fd51..6cd5595b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -485,39 +485,6 @@ dependencies = [ "tracing-futures", ] -[[package]] -name = "async-graphql" -version = "5.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b35ef8f9be23ee30fe1eb1cf175c689bc33517c6c6d0fd0669dade611e5ced7f" -dependencies = [ - "async-graphql-derive 5.0.10", - "async-graphql-parser 5.0.10", - "async-graphql-value 5.0.10", - "async-stream", - "async-trait", - "base64 0.13.1", - "bytes", - "fast_chemail", - "fnv", - "futures-util", - "handlebars", - "http", - "indexmap 1.9.3", - "mime", - "multer", - "num-traits", - "once_cell", - "pin-project-lite", - "regex", - "serde", - "serde_json", - "serde_urlencoded", - "static_assertions", - "tempfile", - "thiserror", -] - [[package]] name = "async-graphql" version = "6.0.6" @@ -588,22 +555,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "async-graphql-derive" -version = "5.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a0f6ceed3640b4825424da70a5107e79d48d9b2bc6318dfc666b2fc4777f8c4" -dependencies = [ - "Inflector", - "async-graphql-parser 5.0.10", - "darling 0.14.4", - "proc-macro-crate", - "proc-macro2", - "quote", - "syn 1.0.109", - "thiserror", -] - [[package]] name = "async-graphql-derive" version = "6.0.6" @@ -3409,9 +3360,9 @@ dependencies = [ name = "fuel-indexer-graphql" version = "0.20.8" dependencies = [ - "async-graphql 5.0.10", - "async-graphql-parser 5.0.10", - "async-graphql-value 5.0.10", + "async-graphql 6.0.6", + "async-graphql-parser 6.0.6", + "async-graphql-value 6.0.6", "fuel-indexer-database", "fuel-indexer-database-types", "fuel-indexer-lib", @@ -3485,8 +3436,8 @@ dependencies = [ name = "fuel-indexer-macros" version = "0.20.8" dependencies = [ - "async-graphql-parser 5.0.10", - "async-graphql-value 5.0.10", + "async-graphql-parser 6.0.6", + "async-graphql-value 6.0.6", "fuel-abi-types 0.3.0", "fuel-indexer-database-types", "fuel-indexer-lib", diff --git a/Cargo.toml b/Cargo.toml index 8ecdac55d..50f33f6d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,8 @@ members = [ "packages/fuel-indexer-database", "packages/fuel-indexer-database/database-types", "packages/fuel-indexer-database/postgres", - "packages/fuel-indexer-graphql", "packages/fuel-indexer-graphql-dyn", + "packages/fuel-indexer-graphql", "packages/fuel-indexer-lib", "packages/fuel-indexer-macros", "packages/fuel-indexer-macros/macro-utils", @@ -33,13 +33,12 @@ members = [ ] default-members = [ - "packages/fuel-indexer", "packages/fuel-indexer-api-server", "packages/fuel-indexer-database", "packages/fuel-indexer-database/database-types", "packages/fuel-indexer-database/postgres", - "packages/fuel-indexer-graphql", "packages/fuel-indexer-graphql-dyn", + "packages/fuel-indexer-graphql", "packages/fuel-indexer-lib", "packages/fuel-indexer-macros", "packages/fuel-indexer-metrics", @@ -47,6 +46,7 @@ default-members = [ "packages/fuel-indexer-schema", "packages/fuel-indexer-types", "packages/fuel-indexer-utils", + "packages/fuel-indexer", "plugins/forc-index", "plugins/forc-postgres", ] @@ -67,9 +67,9 @@ version = "0.20.8" [workspace.dependencies] async-graphql = "6.0" +async-graphql-axum = "6.0" async-graphql-parser = "6.0" async-graphql-value = "6.0" -async-graphql-axum = "6.0" bincode = "1.3" clap = "3.1" forc-index = { version = "0.20.8", path = "./plugins/forc-index" } @@ -79,6 +79,7 @@ fuel-indexer-api-server = { version = "0.20.8", path = "./packages/fuel-indexer- fuel-indexer-database = { version = "0.20.8", path = "./packages/fuel-indexer-database" } fuel-indexer-database-types = { version = "0.20.8", path = "./packages/fuel-indexer-database/database-types" } fuel-indexer-graphql = { version = "0.20.8", path = "./packages/fuel-indexer-graphql" } +fuel-indexer-graphql-dyn = { version = "0.20.8", path = "./packages/fuel-indexer-graphql-dyn" } fuel-indexer-lib = { version = "0.20.8", path = "./packages/fuel-indexer-lib" } fuel-indexer-macro-utils = { version = "0.20.8", path = "./packages/fuel-indexer-macros/macro-utils" } fuel-indexer-macros = { version = "0.20.8", path = "./packages/fuel-indexer-macros", default-features = false } diff --git a/packages/fuel-indexer-graphql-dyn/Cargo.toml b/packages/fuel-indexer-graphql-dyn/Cargo.toml index fad9f7fde..7bed4c151 100644 --- a/packages/fuel-indexer-graphql-dyn/Cargo.toml +++ b/packages/fuel-indexer-graphql-dyn/Cargo.toml @@ -9,32 +9,31 @@ repository = { workspace = true } rust-version = { workspace = true } description = "Library for building executable dynamic GraphQL schemas" -[features] -default = ["json", "testing"] -json = ["dep:serde_json"] -testing = ["dep:graphql-parser"] - [dependencies] +anyhow = { version = "1.0", default-features = false } async-graphql = { workspace = true, features = ["dynamic-schema", "dataloader"] } +async-graphql-parser = { workspace = true } async-graphql-value = { workspace = true } -async-trait = "0.1.73" +async-trait = "0.1" +convert_case = "0.6.0" extension-trait = "1.0.2" graphql-parser = { version = "0.4.0", optional = true } indexmap = "2.0.0" +lazy_static = "1.4" +serde = { workspace = true } serde_json = { workspace = true, optional = true } -tokio = { workspace = true, features = ["sync"] } thiserror = { workspace = true } -anyhow = "1.0" -lazy_static = "1.4.0" -convert_case = "0.6.0" -async-graphql-parser = "6.0.4" -serde.workspace = true +tokio = { workspace = true, features = ["sync"] } [dev-dependencies] assert_matches = "1.5.0" -async-graphql-parser = { workspace = true } graphql-parser = "0.4.0" insta = { version = "1.31.0", features = ["json", "ron"] } serde_json = { workspace = true } tokio = { workspace = true, features = ["sync", "rt", "macros"] } velcro = "0.5.4" + +[features] +default = ["json", "testing"] +json = ["dep:serde_json"] +testing = ["dep:graphql-parser"] diff --git a/packages/fuel-indexer-graphql-dyn/src/lib.rs b/packages/fuel-indexer-graphql-dyn/src/lib.rs index 43a78a806..918468c7a 100644 --- a/packages/fuel-indexer-graphql-dyn/src/lib.rs +++ b/packages/fuel-indexer-graphql-dyn/src/lib.rs @@ -5,7 +5,7 @@ pub mod spec; pub mod store; pub mod testing; -pub(self) mod self_prelude { +pub mod self_prelude { pub use anyhow::anyhow; pub use async_trait::async_trait; pub use extension_trait::extension_trait; diff --git a/packages/fuel-indexer-graphql-dyn/src/schema/mod.rs b/packages/fuel-indexer-graphql-dyn/src/schema/mod.rs index dc978ecf9..40ae9200c 100644 --- a/packages/fuel-indexer-graphql-dyn/src/schema/mod.rs +++ b/packages/fuel-indexer-graphql-dyn/src/schema/mod.rs @@ -10,7 +10,7 @@ pub mod schema_builder; pub mod schema_type; pub mod schema_type_builder; -pub(self) mod self_prelude { +pub mod self_prelude { pub use super::super::self_prelude::*; pub use crate::spec::*; pub use crate::store; diff --git a/packages/fuel-indexer-graphql-dyn/src/schema/schema_builder.rs b/packages/fuel-indexer-graphql-dyn/src/schema/schema_builder.rs index 7f82b9624..15c901ec6 100644 --- a/packages/fuel-indexer-graphql-dyn/src/schema/schema_builder.rs +++ b/packages/fuel-indexer-graphql-dyn/src/schema/schema_builder.rs @@ -25,7 +25,7 @@ impl Default for DynSchemaBuilder { impl DynSchemaBuilder { pub fn new(schema_type: &DynSchemaType, store: Arc>) -> Self { let loader = DynLoader::new(store); - let resolver = DynResolver::new(&schema_type, Arc::new(Mutex::new(loader))); + let resolver = DynResolver::new(schema_type, Arc::new(Mutex::new(loader))); let DynSchemaBuilder { mut schema, mut query, diff --git a/packages/fuel-indexer-graphql-dyn/src/spec/mod.rs b/packages/fuel-indexer-graphql-dyn/src/spec/mod.rs index ef893dd1e..e20e720e1 100644 --- a/packages/fuel-indexer-graphql-dyn/src/spec/mod.rs +++ b/packages/fuel-indexer-graphql-dyn/src/spec/mod.rs @@ -14,7 +14,7 @@ pub mod node; pub mod paging; pub mod query; -pub(self) mod self_prelude { +pub mod self_prelude { pub use super::super::self_prelude::*; pub use async_graphql::dynamic::*; pub use std::{hash::Hash, str::FromStr}; diff --git a/packages/fuel-indexer-graphql-dyn/src/store/mod.rs b/packages/fuel-indexer-graphql-dyn/src/store/mod.rs index 916aa3bc3..ff9d8bf90 100644 --- a/packages/fuel-indexer-graphql-dyn/src/store/mod.rs +++ b/packages/fuel-indexer-graphql-dyn/src/store/mod.rs @@ -10,7 +10,7 @@ pub mod store; pub mod store_type; pub mod store_type_builder; -pub(self) mod self_prelude { +pub mod self_prelude { pub use super::super::self_prelude::*; pub use indexmap::IndexMap; pub use serde::{Deserialize, Serialize}; diff --git a/packages/fuel-indexer-graphql-dyn/src/testing/mod.rs b/packages/fuel-indexer-graphql-dyn/src/testing/mod.rs index 4a2103044..eea708368 100644 --- a/packages/fuel-indexer-graphql-dyn/src/testing/mod.rs +++ b/packages/fuel-indexer-graphql-dyn/src/testing/mod.rs @@ -3,7 +3,7 @@ pub mod schema_type; pub mod store; pub mod store_type; -pub(self) mod self_prelude { +pub mod self_prelude { pub use super::super::self_prelude::*; pub use indexmap::IndexMap; pub use lazy_static::lazy_static; diff --git a/packages/fuel-indexer-graphql-lib/src/json_resolver.rs b/packages/fuel-indexer-graphql-lib/src/json_resolver.rs deleted file mode 100644 index dfae5ea48..000000000 --- a/packages/fuel-indexer-graphql-lib/src/json_resolver.rs +++ /dev/null @@ -1,178 +0,0 @@ -use std::collections::HashMap; - -pub use crate::spec::*; - -pub(self) mod prelude { - pub use crate::spec::*; - pub use async_graphql::dynamic::*; - pub use serde_json::Value as JsonValue; -} - -use prelude::*; - -pub struct Node(pub String, pub JsonValue); -impl Node { - pub fn id(&self) -> &str { - &self.0 - } - pub fn type_id(&self) -> &str { - self.id().split(':').next().unwrap() - } - pub fn local_id(&self) -> &str { - self.id().split(':').nth(1).unwrap() - } - pub fn data(&self) -> &JsonValue { - &self.1 - } - - pub fn to_field_value(&self) -> FieldValue { - FieldValue::borrowed_any(self) - } - pub fn to_typed_field_value(&self) -> FieldValue { - let type_id = self.type_id().to_string(); - FieldValue::borrowed_any(self).with_type(type_id) - } -} - -pub struct JsonResolver { - pub nodes: HashMap, -} -impl JsonResolver { - pub fn new(nodes: Vec) -> Self { - let nodes = nodes - .into_iter() - .map(|node| (node.id().to_string(), node)) - .collect::>(); - Self { nodes } - } -} - -impl QueryResolver for JsonResolver { - fn resolve_node_by_id(ctx: ResolverContext) -> FieldFuture { - FieldFuture::new(async move { - let resolver = ctx.data_unchecked::(); - let id = ctx.args.get("id").unwrap(); - let id = id.string().unwrap(); - let node = resolver.nodes.get(id); - if let Some(node) = node { - Ok(Some(node.to_typed_field_value())) - } else { - Ok(None) - } - }) - } - fn resolve_node_by_ids(ctx: ResolverContext) -> FieldFuture { - FieldFuture::new(async move { - let resolver = ctx.data_unchecked::(); - let ids = ctx.args.get("ids").unwrap(); - let ids = ids.list().unwrap(); - let ids = ids - .iter() - .map(|id| id.string().unwrap().to_string()) - .collect::>(); - let nodes = ids - .iter() - .map(|id| { - let node = resolver.nodes.get(id).unwrap(); - node.to_typed_field_value() - }) - .collect::>(); - Ok(Some(FieldValue::list(nodes))) - }) - } -} - -impl NodeResolver for JsonResolver { - fn resolve_id( - ctx: async_graphql::dynamic::ResolverContext, - ) -> async_graphql::dynamic::FieldFuture { - FieldFuture::new(async move { - let parent = ctx.parent_value.try_downcast_ref::()?; - Ok(Some(FieldValue::value(parent.id()))) - }) - } - fn resolve_data(ctx: ResolverContext) -> FieldFuture { - FieldFuture::new(async move { - let parent = ctx.parent_value.try_downcast_ref::()?; - let path_node = ctx.path_node.unwrap(); - let field_name = path_node.field_name(); - let value = parent.data()[field_name].as_str().unwrap(); - Ok(Some(FieldValue::value(value))) - }) - } - fn resolve_ref(ctx: ResolverContext) -> FieldFuture { - FieldFuture::new(async move { - let parent = ctx.parent_value.try_downcast_ref::()?; - let path_node = ctx.path_node.unwrap(); - let field_name = path_node.field_name(); - let id = parent.data()[field_name].as_str().unwrap(); - let resolver = ctx.data_unchecked::(); - let node = resolver.nodes.get(id).unwrap(); - Ok(Some(node.to_field_value())) - }) - } - fn resolve_connection(_ctx: ResolverContext) -> FieldFuture { - unimplemented!() - } -} - -impl ConnectionResolver for JsonResolver { - fn resolve_total_count(_ctx: ResolverContext) -> FieldFuture { - unimplemented!() - } - fn resolve_nodes(_ctx: ResolverContext) -> FieldFuture { - unimplemented!() - } - fn resolve_edges(_ctx: ResolverContext) -> FieldFuture { - unimplemented!() - } - fn resolve_page_info(_ctx: ResolverContext) -> FieldFuture { - unimplemented!() - } -} - -impl EdgeResolver for JsonResolver { - fn resolve_node(_ctx: ResolverContext) -> FieldFuture { - unimplemented!() - } - fn resolve_cursor(_ctx: ResolverContext) -> FieldFuture { - unimplemented!() - } -} - -impl PageInfoResolver for JsonResolver { - fn resolve_has_next_page( - ctx: async_graphql::dynamic::ResolverContext, - ) -> async_graphql::dynamic::FieldFuture { - FieldFuture::new(async move { - let parent = ctx.parent_value.try_downcast_ref::()?; - Ok(Some(FieldValue::value( - parent["has_next_page"].as_bool().unwrap(), - ))) - }) - } - fn resolve_has_previous_page(ctx: ResolverContext) -> FieldFuture { - FieldFuture::new(async move { - let parent = ctx.parent_value.try_downcast_ref::()?; - Ok(Some(FieldValue::value( - parent["has_previous_page"].as_bool().unwrap(), - ))) - }) - } - fn resolve_start_cursor(ctx: ResolverContext) -> FieldFuture { - FieldFuture::new(async move { - let parent = ctx.parent_value.try_downcast_ref::()?; - Ok(Some(FieldValue::value( - parent["start_cursor"].as_str().unwrap(), - ))) - }) - } - fn resolve_end_cursor(ctx: ResolverContext) -> FieldFuture { - FieldFuture::new(async move { - let parent = ctx.parent_value.try_downcast_ref::()?; - Ok(Some(FieldValue::value( - parent["end_cursor"].as_str().unwrap(), - ))) - }) - } -} diff --git a/packages/fuel-indexer-graphql/Cargo.toml b/packages/fuel-indexer-graphql/Cargo.toml index af0774798..0415692da 100644 --- a/packages/fuel-indexer-graphql/Cargo.toml +++ b/packages/fuel-indexer-graphql/Cargo.toml @@ -10,9 +10,9 @@ rust-version = { workspace = true } description = "Fuel Indexer GraphQL" [dependencies] -async-graphql = { version = "5.0", features = ["dynamic-schema"] } -async-graphql-parser = "5.0" -async-graphql-value = "5.0" +async-graphql = { workspace = true, features = ["dynamic-schema"] } +async-graphql-parser = { workspace = true } +async-graphql-value = { workspace = true } fuel-indexer-database = { workspace = true } fuel-indexer-database-types = { workspace = true } fuel-indexer-schema = { workspace = true, features = ["db-models"] } @@ -24,3 +24,4 @@ thiserror = { workspace = true } [dev-dependencies] fuel-indexer-lib = { workspace = true, default-features = true } pretty_assertions = "0.5.0" + diff --git a/packages/fuel-indexer-macros/Cargo.toml b/packages/fuel-indexer-macros/Cargo.toml index 6a193bc45..3089845a4 100644 --- a/packages/fuel-indexer-macros/Cargo.toml +++ b/packages/fuel-indexer-macros/Cargo.toml @@ -13,8 +13,8 @@ description = "Fuel Indexer Macros" proc-macro = true [dependencies] -async-graphql-parser = "5.0" -async-graphql-value = "5.0" +async-graphql-parser = { workspace = true } +async-graphql-value = { workspace = true } fuel-abi-types = "0.3" fuel-indexer-database-types = { workspace = true } fuel-indexer-lib = { workspace = true, default-features = true }