Skip to content

Commit

Permalink
feat: add GraphQL conversions for DeploymentId
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannis committed Oct 4, 2023
1 parent 747bddd commit 39d6d45
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions toolshed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
17 changes: 17 additions & 0 deletions toolshed/src/thegraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -139,6 +140,22 @@ impl LowerHex for DeploymentId {
}
}

#[Scalar]
impl ScalarType for DeploymentId {
fn parse(value: Value) -> InputValueResult<Self> {
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"
Expand Down

0 comments on commit 39d6d45

Please sign in to comment.