@@ -24,6 +24,7 @@ lazy_static! {
2424#[ cfg( debug_assertions) ]
2525lazy_static ! {
2626 pub static ref TEST_WITH_NO_REORG : Mutex <bool > = Mutex :: new( false ) ;
27+ pub static ref TEST_SQL_QUERIES_ENABLED : Mutex <bool > = Mutex :: new( false ) ;
2728}
2829
2930/// Panics if:
@@ -189,6 +190,10 @@ pub struct EnvVars {
189190 /// Set by the environment variable `ETHEREUM_REORG_THRESHOLD`. The default
190191 /// value is 250 blocks.
191192 reorg_threshold : BlockNumber ,
193+ /// Enable SQL query interface. SQL queries are disabled by default
194+ /// because they are still experimental. Set by the environment variable
195+ /// `GRAPH_ENABLE_SQL_QUERIES`. Off by default.
196+ enable_sql_queries : bool ,
192197 /// The time to wait between polls when using polling block ingestor.
193198 /// The value is set by `ETHERUM_POLLING_INTERVAL` in millis and the
194199 /// default is 1000.
@@ -341,6 +346,7 @@ impl EnvVars {
341346 external_ws_base_url : inner. external_ws_base_url ,
342347 static_filters_threshold : inner. static_filters_threshold ,
343348 reorg_threshold : inner. reorg_threshold ,
349+ enable_sql_queries : inner. enable_sql_queries . 0 ,
344350 ingestor_polling_interval : Duration :: from_millis ( inner. ingestor_polling_interval ) ,
345351 subgraph_settings : inner. subgraph_settings ,
346352 prefer_substreams_block_streams : inner. prefer_substreams_block_streams ,
@@ -414,6 +420,27 @@ impl EnvVars {
414420 pub fn reorg_threshold ( & self ) -> i32 {
415421 self . reorg_threshold
416422 }
423+
424+ #[ cfg( debug_assertions) ]
425+ pub fn sql_queries_enabled ( & self ) -> bool {
426+ // SQL queries are disabled by default for security.
427+ // For testing purposes, we allow tests to enable SQL queries via TEST_SQL_QUERIES_ENABLED.
428+ if * TEST_SQL_QUERIES_ENABLED . lock ( ) . unwrap ( ) {
429+ true
430+ } else {
431+ self . enable_sql_queries
432+ }
433+ }
434+ #[ cfg( not( debug_assertions) ) ]
435+ pub fn sql_queries_enabled ( & self ) -> bool {
436+ self . enable_sql_queries
437+ }
438+
439+ #[ cfg( debug_assertions) ]
440+ pub fn enable_sql_queries_for_tests ( & self , enable : bool ) {
441+ let mut lock = TEST_SQL_QUERIES_ENABLED . lock ( ) . unwrap ( ) ;
442+ * lock = enable;
443+ }
417444}
418445
419446impl Default for EnvVars {
@@ -514,6 +541,8 @@ struct Inner {
514541 // JSON-RPC specific.
515542 #[ envconfig( from = "ETHEREUM_REORG_THRESHOLD" , default = "250" ) ]
516543 reorg_threshold : BlockNumber ,
544+ #[ envconfig( from = "GRAPH_ENABLE_SQL_QUERIES" , default = "false" ) ]
545+ enable_sql_queries : EnvVarBoolean ,
517546 #[ envconfig( from = "ETHEREUM_POLLING_INTERVAL" , default = "1000" ) ]
518547 ingestor_polling_interval : u64 ,
519548 #[ envconfig( from = "GRAPH_EXPERIMENTAL_SUBGRAPH_SETTINGS" ) ]
0 commit comments