mirror of
https://github.com/hasura/graphql-engine.git
synced 2025-01-07 16:21:52 +03:00
Defer local relationship check until IR creation (#716)
<!-- Thank you for submitting this PR! :) --> ## Description Making the schema work for boolean expressions has been challenging as they are no longer tied to a single data connector, so we cannot do any checks of whether a relationships is local or remote. We defer this to the IR step when the source data connector for a relationship is known, so that we can generate schema for boolean expressions decoupled from any concept of data connector. Functional no-op. V3_GIT_ORIGIN_REV_ID: d2923acedf92b031ba092bb83c515812c4d346f0
This commit is contained in:
parent
e8edc5e596
commit
0f245de566
@ -201,7 +201,28 @@ fn build_filter_expression_from_boolean_expression<'s>(
|
|||||||
// Add the target model being used in the usage counts
|
// Add the target model being used in the usage counts
|
||||||
count_model(target_model_name, usage_counts);
|
count_model(target_model_name, usage_counts);
|
||||||
|
|
||||||
let ndc_relationship_name = NDCRelationshipName::new(source_type, relationship_name)?;
|
// filter expression with relationships is currently only supported for local relationships
|
||||||
|
// this is the first point at which we know the source data connector, so we must
|
||||||
|
// ensure only a local relationship is used
|
||||||
|
match metadata_resolve::relationship_execution_category(
|
||||||
|
data_connector_link,
|
||||||
|
&target_source.model.data_connector,
|
||||||
|
&target_source.capabilities,
|
||||||
|
) {
|
||||||
|
metadata_resolve::RelationshipExecutionCategory::RemoteForEach => {
|
||||||
|
Err(error::Error::Internal(error::InternalError::Engine(
|
||||||
|
error::InternalEngineError::InternalGeneric {
|
||||||
|
description:
|
||||||
|
"Remote relationships are not supported in boolean expressions"
|
||||||
|
.to_string(),
|
||||||
|
},
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata_resolve::RelationshipExecutionCategory::Local => {
|
||||||
|
let ndc_relationship_name =
|
||||||
|
NDCRelationshipName::new(source_type, relationship_name)?;
|
||||||
|
|
||||||
relationships.insert(
|
relationships.insert(
|
||||||
ndc_relationship_name.clone(),
|
ndc_relationship_name.clone(),
|
||||||
LocalModelRelationshipInfo {
|
LocalModelRelationshipInfo {
|
||||||
@ -245,6 +266,8 @@ fn build_filter_expression_from_boolean_expression<'s>(
|
|||||||
predicate: Some(Box::new(exists_filter_clause)),
|
predicate: Some(Box::new(exists_filter_clause)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
other_boolean_annotation => Err(error::InternalEngineError::UnexpectedAnnotation {
|
other_boolean_annotation => Err(error::InternalEngineError::UnexpectedAnnotation {
|
||||||
annotation: schema::Annotation::Input(InputAnnotation::BooleanExpression(
|
annotation: schema::Annotation::Input(InputAnnotation::BooleanExpression(
|
||||||
other_boolean_annotation.clone(),
|
other_boolean_annotation.clone(),
|
||||||
|
@ -9,8 +9,8 @@ use super::types::output_type::relationship::FilterRelationshipAnnotation;
|
|||||||
use super::types::{BooleanExpressionAnnotation, InputAnnotation, TypeId};
|
use super::types::{BooleanExpressionAnnotation, InputAnnotation, TypeId};
|
||||||
use metadata_resolve::{
|
use metadata_resolve::{
|
||||||
mk_name, BooleanExpressionGraphqlConfig, ModelExpressionType, ModelWithPermissions,
|
mk_name, BooleanExpressionGraphqlConfig, ModelExpressionType, ModelWithPermissions,
|
||||||
ObjectBooleanExpressionDataConnector, ObjectBooleanExpressionType, ObjectTypeWithRelationships,
|
ObjectBooleanExpressionType, ObjectTypeWithRelationships, Qualified, Relationship,
|
||||||
Qualified, Relationship, RelationshipModelMapping, ResolvedObjectBooleanExpressionType,
|
RelationshipModelMapping, ResolvedObjectBooleanExpressionType,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::permissions;
|
use crate::permissions;
|
||||||
@ -187,7 +187,6 @@ fn build_comparable_fields_schema(
|
|||||||
fn build_comparable_relationships_schema(
|
fn build_comparable_relationships_schema(
|
||||||
gds: &GDS,
|
gds: &GDS,
|
||||||
object_type_representation: &ObjectTypeWithRelationships,
|
object_type_representation: &ObjectTypeWithRelationships,
|
||||||
object_boolean_expression_data_connector: &Option<ObjectBooleanExpressionDataConnector>,
|
|
||||||
builder: &mut gql_schema::Builder<GDS>,
|
builder: &mut gql_schema::Builder<GDS>,
|
||||||
) -> Result<BTreeMap<ast::Name, gql_schema::Namespaced<GDS, gql_schema::InputField<GDS>>>, Error> {
|
) -> Result<BTreeMap<ast::Name, gql_schema::Namespaced<GDS, gql_schema::InputField<GDS>>>, Error> {
|
||||||
let mut input_fields = BTreeMap::new();
|
let mut input_fields = BTreeMap::new();
|
||||||
@ -214,7 +213,6 @@ fn build_comparable_relationships_schema(
|
|||||||
// try and create a new input field
|
// try and create a new input field
|
||||||
if let Some((name, schema)) = build_model_relationship_schema(
|
if let Some((name, schema)) = build_model_relationship_schema(
|
||||||
object_type_representation,
|
object_type_representation,
|
||||||
object_boolean_expression_data_connector,
|
|
||||||
target_object_type_representation,
|
target_object_type_representation,
|
||||||
target_model,
|
target_model,
|
||||||
relationship,
|
relationship,
|
||||||
@ -238,7 +236,6 @@ type InputField = (
|
|||||||
// build comparable relationships input fields
|
// build comparable relationships input fields
|
||||||
fn build_model_relationship_schema(
|
fn build_model_relationship_schema(
|
||||||
source_object_type_representation: &ObjectTypeWithRelationships,
|
source_object_type_representation: &ObjectTypeWithRelationships,
|
||||||
source_object_boolean_expression_data_connector: &Option<ObjectBooleanExpressionDataConnector>,
|
|
||||||
target_object_type_representation: &ObjectTypeWithRelationships,
|
target_object_type_representation: &ObjectTypeWithRelationships,
|
||||||
target_model: &ModelWithPermissions,
|
target_model: &ModelWithPermissions,
|
||||||
relationship: &Relationship,
|
relationship: &Relationship,
|
||||||
@ -251,22 +248,10 @@ fn build_model_relationship_schema(
|
|||||||
// both the source boolean expression and target_model are backed by a source
|
// both the source boolean expression and target_model are backed by a source
|
||||||
// We'll need to find a way of getting this information for BooleanExpressionTypes
|
// We'll need to find a way of getting this information for BooleanExpressionTypes
|
||||||
// that are uncoupled from their data connector source
|
// that are uncoupled from their data connector source
|
||||||
if let (Some(source_data_connector), Some(target_source)) = (
|
if let Some(target_source) = &target_model.model.source {
|
||||||
&source_object_boolean_expression_data_connector,
|
|
||||||
&target_model.model.source,
|
|
||||||
) {
|
|
||||||
let target_model_source =
|
let target_model_source =
|
||||||
metadata_resolve::ModelTargetSource::from_model_source(target_source, relationship)?;
|
metadata_resolve::ModelTargetSource::from_model_source(target_source, relationship)?;
|
||||||
|
|
||||||
// filter expression with relationships is currently only supported for local relationships
|
|
||||||
if let metadata_resolve::RelationshipExecutionCategory::Local =
|
|
||||||
metadata_resolve::relationship_execution_category(
|
|
||||||
&source_data_connector.link,
|
|
||||||
&target_source.data_connector,
|
|
||||||
&target_model_source.capabilities,
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if target_source.data_connector.name == source_data_connector.name {
|
|
||||||
match &target_model.model.filter_expression_type {
|
match &target_model.model.filter_expression_type {
|
||||||
None => {}
|
None => {}
|
||||||
Some(ModelExpressionType::BooleanExpressionType(_)) => {
|
Some(ModelExpressionType::BooleanExpressionType(_)) => {
|
||||||
@ -306,10 +291,8 @@ fn build_model_relationship_schema(
|
|||||||
relationship.field_name.clone(),
|
relationship.field_name.clone(),
|
||||||
None,
|
None,
|
||||||
types::Annotation::Input(InputAnnotation::BooleanExpression(
|
types::Annotation::Input(InputAnnotation::BooleanExpression(
|
||||||
BooleanExpressionAnnotation
|
BooleanExpressionAnnotation::BooleanExpressionArgument {
|
||||||
::BooleanExpressionArgument {
|
field: types::ModelFilterArgument::RelationshipField(
|
||||||
field:
|
|
||||||
types::ModelFilterArgument::RelationshipField(
|
|
||||||
annotation,
|
annotation,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@ -322,15 +305,13 @@ fn build_model_relationship_schema(
|
|||||||
None,
|
None,
|
||||||
gql_schema::DeprecationStatus::NotDeprecated,
|
gql_schema::DeprecationStatus::NotDeprecated,
|
||||||
),
|
),
|
||||||
namespace_annotations
|
namespace_annotations,
|
||||||
),
|
),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
@ -409,7 +390,6 @@ fn build_schema_with_object_boolean_expression_type(
|
|||||||
input_fields.extend(build_comparable_relationships_schema(
|
input_fields.extend(build_comparable_relationships_schema(
|
||||||
gds,
|
gds,
|
||||||
object_type_representation,
|
object_type_representation,
|
||||||
&object_boolean_expression_type.data_connector,
|
|
||||||
builder,
|
builder,
|
||||||
)?);
|
)?);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user