@@ -9,13 +9,12 @@ use anyhow::anyhow;
99use async_graphql:: { EmptySubscription , Schema } ;
1010use async_graphql_axum:: GraphQL ;
1111use axum:: {
12+ http:: { HeaderValue , Response } ,
1213 routing:: { post, post_service} ,
13- Json , Router ,
14+ Router ,
1415} ;
1516use indexer_config:: { Config , DipsConfig } ;
16- use reqwest:: Url ;
17- use serde:: { de:: DeserializeOwned , Serialize } ;
18- use serde_json:: { json, Value } ;
17+ use reqwest:: { header:: CONTENT_TYPE , Url } ;
1918use sqlx:: PgPool ;
2019use thegraph_core:: attestation:: eip712_domain;
2120use thegraph_core:: DeploymentId ;
@@ -26,6 +25,7 @@ use crate::{
2625 self ,
2726 dips:: { AgreementStore , InMemoryAgreementStore } ,
2827 } ,
28+ middleware:: AttestationInput ,
2929 routes:: dips:: Price ,
3030 service:: indexer_service:: { IndexerServiceOptions , IndexerServiceRelease } ,
3131} ;
@@ -38,42 +38,6 @@ mod tap_receipt_header;
3838pub use indexer_service:: { AttestationOutput , IndexerServiceResponse , IndexerServiceState } ;
3939pub use tap_receipt_header:: TapReceipt ;
4040
41- #[ derive( Debug ) ]
42- pub struct SubgraphServiceResponse {
43- inner : String ,
44- attestable : bool ,
45- }
46-
47- impl SubgraphServiceResponse {
48- pub fn new ( inner : String , attestable : bool ) -> Self {
49- Self { inner, attestable }
50- }
51- }
52-
53- impl IndexerServiceResponse for SubgraphServiceResponse {
54- type Data = Json < Value > ;
55- type Error = SubgraphServiceError ; // not used
56-
57- fn is_attestable ( & self ) -> bool {
58- self . attestable
59- }
60-
61- fn as_str ( & self ) -> Result < & str , Self :: Error > {
62- Ok ( self . inner . as_str ( ) )
63- }
64-
65- fn finalize ( self , attestation : AttestationOutput ) -> Self :: Data {
66- let ( attestation_key, attestation_value) = match attestation {
67- AttestationOutput :: Attestation ( attestation) => ( "attestation" , json ! ( attestation) ) ,
68- AttestationOutput :: Attestable => ( "attestable" , json ! ( self . is_attestable( ) ) ) ,
69- } ;
70- Json ( json ! ( {
71- "graphQLResponse" : self . inner,
72- attestation_key: attestation_value,
73- } ) )
74- }
75- }
76-
7741#[ derive( Clone ) ]
7842pub struct SubgraphServiceState {
7943 pub config : & ' static Config ,
@@ -95,11 +59,11 @@ impl SubgraphService {
9559}
9660
9761impl SubgraphService {
98- pub async fn process_request < Request : DeserializeOwned + Send + std :: fmt :: Debug + Serialize > (
62+ pub async fn process_request (
9963 & self ,
10064 deployment : DeploymentId ,
101- request : & Request ,
102- ) -> Result < SubgraphServiceResponse , SubgraphServiceError > {
65+ req : String ,
66+ ) -> Result < Response < String > , SubgraphServiceError > {
10367 let deployment_url = self
10468 . state
10569 . graph_node_query_base_url
@@ -110,7 +74,8 @@ impl SubgraphService {
11074 . state
11175 . graph_node_client
11276 . post ( deployment_url)
113- . json ( request)
77+ . body ( req. clone ( ) )
78+ . header ( CONTENT_TYPE , HeaderValue :: from_static ( "application/json" ) )
11479 . send ( )
11580 . await
11681 . map_err ( SubgraphServiceError :: QueryForwardingError ) ?;
@@ -126,8 +91,16 @@ impl SubgraphService {
12691 . text ( )
12792 . await
12893 . map_err ( SubgraphServiceError :: QueryForwardingError ) ?;
94+ let attestation_input = if attestable {
95+ AttestationInput :: Attestable { req }
96+ } else {
97+ AttestationInput :: NotAttestable
98+ } ;
99+
100+ let mut response = Response :: new ( body) ;
101+ response. extensions_mut ( ) . insert ( attestation_input) ;
129102
130- Ok ( SubgraphServiceResponse :: new ( body , attestable ) )
103+ Ok ( response )
131104 }
132105}
133106
0 commit comments