Skip to content

Commit 304cc56

Browse files
authored
refactor: move graphql queries to own crate (#487)
1 parent c51866e commit 304cc56

28 files changed

+173
-111
lines changed

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ members = [
33
"crates/common",
44
"crates/config",
55
"crates/dips",
6+
"crates/query",
67
"crates/service",
78
"crates/tap-agent",
89
]

crates/common/Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
indexer-config = { path = "../config" }
8+
indexer-query = { path = "../query" }
89
thiserror.workspace = true
910
async-trait.workspace = true
1011
alloy.workspace = true
@@ -29,14 +30,14 @@ tokio = { workspace = true, features = ["fs", "tokio-macros"] }
2930
cost-model = { git = "https://github.com/graphprotocol/agora", rev = "3ed34ca" }
3031
regex = "1.7.1"
3132
axum-extra = { version = "0.9.3", features = [
32-
"typed-header",
33+
"typed-header",
3334
], default-features = false }
3435
autometrics = { version = "1.0.1", features = ["prometheus-exporter"] }
3536
tower_governor = "0.4.0"
3637
tower-http = { version = "0.5.2", features = [
37-
"cors",
38-
"normalize-path",
39-
"trace",
38+
"cors",
39+
"normalize-path",
40+
"trace",
4041
] }
4142
tokio-util = "0.7.10"
4243
bip39 = "2.0.0"

crates/common/src/allocations/monitor.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,11 @@ use std::{
99

1010
use super::Allocation;
1111
use crate::{prelude::SubgraphClient, watcher::new_watcher};
12-
use alloy::primitives::{TxHash, B256, U256};
13-
use graphql_client::GraphQLQuery;
12+
use alloy::primitives::TxHash;
13+
use indexer_query::allocations_query::{self, AllocationsQuery};
1414
use thegraph_core::{Address, DeploymentId};
1515
use tokio::sync::watch::Receiver;
1616

17-
type BigInt = U256;
18-
type Bytes = B256;
19-
20-
#[derive(GraphQLQuery)]
21-
#[graphql(
22-
schema_path = "../graphql/network.schema.graphql",
23-
query_path = "../graphql/allocations.query.graphql",
24-
response_derives = "Debug",
25-
variables_derives = "Clone"
26-
)]
27-
pub struct AllocationsQuery;
28-
2917
impl TryFrom<allocations_query::AllocationFragment> for Allocation {
3018
type Error = anyhow::Error;
3119

crates/common/src/attestations/dispute_manager.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,10 @@ use crate::subgraph_client::SubgraphClient;
55
use crate::watcher::new_watcher;
66
use alloy::primitives::Address;
77
use anyhow::Error;
8-
use graphql_client::GraphQLQuery;
8+
use indexer_query::dispute_manager::{self, DisputeManager};
99
use std::time::Duration;
1010
use tokio::sync::watch::Receiver;
1111

12-
type Bytes = Address;
13-
14-
#[derive(GraphQLQuery)]
15-
#[graphql(
16-
schema_path = "../graphql/network.schema.graphql",
17-
query_path = "../graphql/dispute.query.graphql",
18-
response_derives = "Debug",
19-
variables_derives = "Clone"
20-
)]
21-
struct DisputeManager;
22-
2312
pub async fn dispute_manager(
2413
network_subgraph: &'static SubgraphClient,
2514
interval: Duration,

crates/common/src/escrow_accounts.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99

1010
use alloy::primitives::{Address, U256};
1111
use anyhow::{anyhow, Result};
12-
use graphql_client::GraphQLQuery;
12+
use indexer_query::escrow_account::{self, EscrowAccountQuery};
1313
use thiserror::Error;
1414
use tokio::sync::watch::Receiver;
1515
use tracing::{error, warn};
@@ -87,17 +87,6 @@ impl EscrowAccounts {
8787
}
8888
}
8989

90-
type BigInt = String;
91-
92-
#[derive(GraphQLQuery)]
93-
#[graphql(
94-
schema_path = "../graphql/tap.schema.graphql",
95-
query_path = "../graphql/escrow_account.query.graphql",
96-
response_derives = "Debug",
97-
variables_derives = "Clone"
98-
)]
99-
pub struct EscrowAccountQuery;
100-
10190
pub async fn escrow_accounts(
10291
escrow_subgraph: &'static SubgraphClient,
10392
indexer_address: Address,
@@ -121,7 +110,7 @@ async fn get_escrow_accounts(
121110
// isAuthorized == true means that the signer is still authorized to sign
122111
// payments in the name of the sender.
123112
let response = escrow_subgraph
124-
.query::<EscrowAccountQuery, _>(escrow_account_query::Variables {
113+
.query::<EscrowAccountQuery, _>(escrow_account::Variables {
125114
indexer: format!("{:x?}", indexer_address),
126115
thaw_end_timestamp: if reject_thawing_signers {
127116
U256::ZERO.to_string()

crates/common/src/indexer_service/http/health.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,11 @@ use axum::{
88
};
99
use graphql_client::GraphQLQuery;
1010
use indexer_config::GraphNodeConfig;
11+
use indexer_query::{health_query, HealthQuery};
1112
use reqwest::StatusCode;
1213
use serde_json::json;
1314
use thiserror::Error;
1415

15-
#[derive(GraphQLQuery)]
16-
#[graphql(
17-
schema_path = "../graphql/indexing_status.schema.graphql",
18-
query_path = "../graphql/subgraph_health.query.graphql",
19-
response_derives = "Debug",
20-
variables_derives = "Clone"
21-
)]
22-
pub struct HealthQuery;
23-
2416
#[derive(Debug, Error)]
2517
pub enum CheckHealthError {
2618
#[error("Failed to send request")]

crates/common/src/subgraph_client/client.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ impl SubgraphClient {
312312
mod test {
313313
use std::str::FromStr;
314314

315+
use indexer_query::{current_epoch, user_query, CurrentEpoch, UserQuery};
315316
use serde_json::json;
316317
use wiremock::matchers::{method, path};
317318
use wiremock::{Mock, MockServer, ResponseTemplate};
@@ -356,15 +357,6 @@ mod test {
356357
.await
357358
}
358359

359-
#[derive(GraphQLQuery)]
360-
#[graphql(
361-
schema_path = "../graphql/network.schema.graphql",
362-
query_path = "../graphql/epoch.query.graphql",
363-
response_derives = "Debug",
364-
variables_derives = "Clone"
365-
)]
366-
struct CurrentEpoch;
367-
368360
#[tokio::test]
369361
#[ignore = "depends on the defunct hosted-service"]
370362
async fn test_network_query() {
@@ -380,15 +372,6 @@ mod test {
380372
assert!(result.is_ok());
381373
}
382374

383-
#[derive(GraphQLQuery)]
384-
#[graphql(
385-
schema_path = "../graphql/test.schema.graphql",
386-
query_path = "../graphql/user.query.graphql",
387-
response_derives = "Debug",
388-
variables_derives = "Clone"
389-
)]
390-
struct UserQuery;
391-
392375
#[tokio::test]
393376
async fn test_uses_local_deployment_if_healthy_and_synced() {
394377
let deployment =

crates/common/src/subgraph_client/monitor.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,18 @@
33

44
use std::time::Duration;
55

6-
use deployment_status_query::Health;
76
use graphql_client::GraphQLQuery;
7+
use indexer_query::{
8+
deployment_status_query::{self, Health},
9+
DeploymentStatusQuery,
10+
};
811
use reqwest::Url;
912
use serde::Deserialize;
1013
use thegraph_core::DeploymentId;
1114
use tokio::sync::watch::Receiver;
1215

1316
use crate::watcher::new_watcher;
1417

15-
#[derive(GraphQLQuery)]
16-
#[graphql(
17-
schema_path = "../graphql/indexing_status.schema.graphql",
18-
query_path = "../graphql/subgraph_deployment_status.graphql",
19-
response_derives = "Debug",
20-
variables_derives = "Clone"
21-
)]
22-
pub struct DeploymentStatusQuery;
23-
2418
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
2519
pub struct DeploymentStatus {
2620
pub synced: bool,

crates/query/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "indexer-query"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
graphql_client.workspace = true
8+
thegraph-core.workspace = true
9+
serde.workspace = true
10+
alloy.workspace = true
11+
anyhow.workspace = true

0 commit comments

Comments
 (0)