diff --git a/toolshed/Cargo.toml b/toolshed/Cargo.toml index aa77aea..52da372 100644 --- a/toolshed/Cargo.toml +++ b/toolshed/Cargo.toml @@ -23,6 +23,7 @@ serde = { version = "1.0.152", features = ["derive"] } serde_with = "3.2.0" thiserror = "1.0.49" url = { version = "2.4.0", optional = true } +async-graphql = "6.0.7" [dev-dependencies] rand = { version = "0.8.5", features = ["small_rng"] } diff --git a/toolshed/src/thegraph/mod.rs b/toolshed/src/thegraph/mod.rs index 6f2719e..6a244f7 100644 --- a/toolshed/src/thegraph/mod.rs +++ b/toolshed/src/thegraph/mod.rs @@ -3,6 +3,7 @@ pub mod attestation; use std::{fmt, fmt::LowerHex, str::FromStr}; use alloy_primitives::{Address, BlockHash, BlockNumber, B256}; +use async_graphql::{InputValueError, InputValueResult, Scalar, ScalarType, Value}; use serde::{Deserialize, Serialize}; use serde_with::{DeserializeFromStr, SerializeDisplay}; use sha3::{ @@ -139,6 +140,22 @@ impl LowerHex for DeploymentId { } } +#[Scalar] +impl ScalarType for DeploymentId { + fn parse(value: Value) -> InputValueResult { + if let Value::String(value) = &value { + Ok(DeploymentId::from_str(value)?) + } else { + Err(InputValueError::expected_type(value)) + } + } + + fn to_value(&self) -> Value { + // Convert to Qm... + Value::String(self.to_string()) + } +} + #[test] fn subgraph_id_encode() { let bytes: B256 = "0x67486e65165b1474898247760a4b852d70d95782c6325960e5b6b4fd82fed1bd"