@@ -24,6 +24,7 @@ lazy_static! {
24
24
#[ cfg( debug_assertions) ]
25
25
lazy_static ! {
26
26
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 ) ;
27
28
}
28
29
29
30
/// Panics if:
@@ -189,6 +190,10 @@ pub struct EnvVars {
189
190
/// Set by the environment variable `ETHEREUM_REORG_THRESHOLD`. The default
190
191
/// value is 250 blocks.
191
192
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 ,
192
197
/// The time to wait between polls when using polling block ingestor.
193
198
/// The value is set by `ETHERUM_POLLING_INTERVAL` in millis and the
194
199
/// default is 1000.
@@ -341,6 +346,7 @@ impl EnvVars {
341
346
external_ws_base_url : inner. external_ws_base_url ,
342
347
static_filters_threshold : inner. static_filters_threshold ,
343
348
reorg_threshold : inner. reorg_threshold ,
349
+ enable_sql_queries : inner. enable_sql_queries . 0 ,
344
350
ingestor_polling_interval : Duration :: from_millis ( inner. ingestor_polling_interval ) ,
345
351
subgraph_settings : inner. subgraph_settings ,
346
352
prefer_substreams_block_streams : inner. prefer_substreams_block_streams ,
@@ -414,6 +420,27 @@ impl EnvVars {
414
420
pub fn reorg_threshold ( & self ) -> i32 {
415
421
self . reorg_threshold
416
422
}
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
+ }
417
444
}
418
445
419
446
impl Default for EnvVars {
@@ -514,6 +541,8 @@ struct Inner {
514
541
// JSON-RPC specific.
515
542
#[ envconfig( from = "ETHEREUM_REORG_THRESHOLD" , default = "250" ) ]
516
543
reorg_threshold : BlockNumber ,
544
+ #[ envconfig( from = "GRAPH_ENABLE_SQL_QUERIES" , default = "false" ) ]
545
+ enable_sql_queries : EnvVarBoolean ,
517
546
#[ envconfig( from = "ETHEREUM_POLLING_INTERVAL" , default = "1000" ) ]
518
547
ingestor_polling_interval : u64 ,
519
548
#[ envconfig( from = "GRAPH_EXPERIMENTAL_SUBGRAPH_SETTINGS" ) ]
0 commit comments