Split up apollo and relay stages (#815)

<!-- The PR description should answer 2 (maybe 3) important questions:
-->

### What

In the haste of breaking things up, realised we put the `relay` checks
in with the `apollo` ones where they are two separate things.

<!-- What is this PR trying to accomplish (and why, if it's not
obvious)? -->

<!-- Consider: do we need to add a changelog entry? -->

### How

Split up `apollo` step into `relay` and `apollo` steps. Functional
no-op.

<!-- How is it trying to accomplish it (what are the implementation
steps)? -->

V3_GIT_ORIGIN_REV_ID: 8d02d3cb77b1248239be37ed61d0b87b9b734fdf
This commit is contained in:
Daniel Harvey 2024-07-09 18:18:53 +01:00 committed by hasura-bot
parent 788fd9e197
commit 55dcab09b1
3 changed files with 32 additions and 16 deletions

View File

@ -1,6 +1,6 @@
use std::collections::BTreeMap;
use open_dds::{models::ModelName, types::CustomTypeName};
use open_dds::types::CustomTypeName;
use crate::types::error::Error;
@ -11,22 +11,11 @@ use crate::types::subgraph::Qualified;
/// Ideally, we could move more Apollo-based resolving into this discreet step, haven't
/// investigated this too deeply yet.
pub fn resolve(
global_id_enabled_types: &BTreeMap<Qualified<CustomTypeName>, Vec<Qualified<ModelName>>>,
apollo_federation_entity_enabled_types: &BTreeMap<
Qualified<CustomTypeName>,
Option<Qualified<open_dds::models::ModelName>>,
>,
) -> Result<(), Error> {
// To check if global_id_fields are defined in object type but no model has global_id_source set to true:
// - Throw an error if no model with globalIdSource:true is found for the object type.
for (object_type, model_name_list) in global_id_enabled_types {
if model_name_list.is_empty() {
return Err(Error::GlobalIdSourceNotDefined {
object_type: object_type.clone(),
});
}
}
// To check if apollo federation entity keys are defined in object type but no model has
// apollo_federation_entity_source set to true:
// - Throw an error if no model with apolloFederation.entitySource:true is found for the object type.

View File

@ -13,6 +13,7 @@ pub mod models_graphql;
pub mod object_boolean_expressions;
pub mod object_types;
pub mod relationships;
mod relay;
pub mod roles;
pub mod scalar_boolean_expressions;
pub mod scalar_types;
@ -146,10 +147,9 @@ pub fn resolve(
&boolean_expression_types,
)?;
apollo::resolve(
&global_id_enabled_types,
&apollo_federation_entity_enabled_types,
)?;
apollo::resolve(&apollo_federation_entity_enabled_types)?;
relay::resolve(&global_id_enabled_types)?;
let object_types_with_relationships = relationships::resolve(
&metadata_accessor,

View File

@ -0,0 +1,27 @@
use std::collections::BTreeMap;
use open_dds::{models::ModelName, types::CustomTypeName};
use crate::types::error::Error;
use crate::types::subgraph::Qualified;
/// This isn't a particularly satisfying resolve step, as it only serves to validate
/// the output of previous steps.
/// Ideally, we could move more Relay-based resolving into this discreet step, haven't
/// investigated this too deeply yet.
pub fn resolve(
global_id_enabled_types: &BTreeMap<Qualified<CustomTypeName>, Vec<Qualified<ModelName>>>,
) -> Result<(), Error> {
// To check if global_id_fields are defined in object type but no model has global_id_source set to true:
// - Throw an error if no model with globalIdSource:true is found for the object type.
for (object_type, model_name_list) in global_id_enabled_types {
if model_name_list.is_empty() {
return Err(Error::GlobalIdSourceNotDefined {
object_type: object_type.clone(),
});
}
}
Ok(())
}