@@ -5,19 +5,16 @@ use std::str::FromStr;
55
66use crate :: database:: cost_model:: { self , CostModel } ;
77use async_graphql:: { Context , EmptyMutation , EmptySubscription , Object , Schema , SimpleObject } ;
8- use async_graphql_axum:: { GraphQLRequest , GraphQLResponse } ;
9- use axum:: extract:: State ;
108use lazy_static:: lazy_static;
119use prometheus:: {
1210 register_counter, register_counter_vec, register_histogram, register_histogram_vec, Counter ,
1311 CounterVec , Histogram , HistogramVec ,
1412} ;
1513use serde:: { Deserialize , Serialize } ;
1614use serde_json:: Value ;
15+ use sqlx:: PgPool ;
1716use thegraph_core:: DeploymentId ;
1817
19- use crate :: service:: SubgraphServiceState ;
20-
2118lazy_static ! {
2219 pub static ref COST_MODEL_METRIC : HistogramVec = register_histogram_vec!(
2320 "indexer_cost_model_seconds" ,
@@ -126,7 +123,7 @@ impl Query {
126123 ctx : & Context < ' _ > ,
127124 deployment_ids : Vec < DeploymentId > ,
128125 ) -> Result < Vec < GraphQlCostModel > , anyhow:: Error > {
129- let pool = & ctx. data_unchecked :: < SubgraphServiceState > ( ) . database ;
126+ let pool = & ctx. data_unchecked :: < PgPool > ( ) ;
130127 let cost_models = cost_model:: cost_models ( pool, & deployment_ids) . await ?;
131128 Ok ( cost_models. into_iter ( ) . map ( |m| m. into ( ) ) . collect ( ) )
132129 }
@@ -136,7 +133,7 @@ impl Query {
136133 ctx : & Context < ' _ > ,
137134 deployment_id : DeploymentId ,
138135 ) -> Result < Option < GraphQlCostModel > , anyhow:: Error > {
139- let pool = & ctx. data_unchecked :: < SubgraphServiceState > ( ) . database ;
136+ let pool = & ctx. data_unchecked :: < PgPool > ( ) ;
140137 cost_model:: cost_model ( pool, & deployment_id)
141138 . await
142139 . map ( |model_opt| model_opt. map ( GraphQlCostModel :: from) )
@@ -145,17 +142,8 @@ impl Query {
145142
146143pub type CostSchema = Schema < Query , EmptyMutation , EmptySubscription > ;
147144
148- pub async fn build_schema ( ) -> CostSchema {
149- Schema :: build ( Query , EmptyMutation , EmptySubscription ) . finish ( )
150- }
151-
152- pub async fn cost (
153- State ( state) : State < SubgraphServiceState > ,
154- req : GraphQLRequest ,
155- ) -> GraphQLResponse {
156- state
157- . cost_schema
158- . execute ( req. into_inner ( ) . data ( state. clone ( ) ) )
159- . await
160- . into ( )
145+ pub async fn build_schema ( data : PgPool ) -> CostSchema {
146+ Schema :: build ( Query , EmptyMutation , EmptySubscription )
147+ . data ( data)
148+ . finish ( )
161149}
0 commit comments