Skip to content

Commit

Permalink
add env var for forcing relation strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Druue committed Feb 19, 2024
1 parent 5a9203d commit 860d6a1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions query-engine/core/src/query_graph_builder/read/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;
use crate::{ArgumentListLookup, FieldPair, ParsedField, ReadQuery};
use once_cell::sync::Lazy;
use psl::datamodel_connector::{ConnectorCapability, JoinStrategySupport};
use query_structure::{native_distinct_compatible_with_order_by, prelude::*, RelationLoadStrategy};
use schema::{
Expand Down Expand Up @@ -259,6 +260,13 @@ pub(crate) fn get_relation_load_strategy(
nested_queries: &[ReadQuery],
query_schema: &QuerySchema,
) -> QueryGraphBuilderResult<RelationLoadStrategy> {
static RELATION_LOAD_STRATEGY: Lazy<Result<RelationLoadStrategy, DomainError>> =
Lazy::new(|| std::env::var("RELATION_LOAD_STRATEGY").unwrap().as_str().try_into());

if RELATION_LOAD_STRATEGY.is_ok() {
return Ok(*RELATION_LOAD_STRATEGY.as_ref().unwrap());
}

match query_schema.join_strategy_support() {
// Connector and database version supports the `Join` strategy...
JoinStrategySupport::Yes => match requested_strategy {
Expand Down
15 changes: 15 additions & 0 deletions query-engine/query-structure/src/query_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ impl RelationLoadStrategy {
}
}

impl TryFrom<&str> for RelationLoadStrategy {
type Error = crate::error::DomainError;

fn try_from(value: &str) -> crate::Result<Self> {
match value {
"join" => Ok(RelationLoadStrategy::Join),
"query" => Ok(RelationLoadStrategy::Query),
_ => Err(DomainError::ConversionFailure(
value.to_owned(),
"RelationLoadStrategy".to_owned(),
)),
}
}
}

impl std::fmt::Debug for QueryArguments {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("QueryArguments")
Expand Down

0 comments on commit 860d6a1

Please sign in to comment.