Skip to content

Commit

Permalink
Ground work for @Validate in operators module
Browse files Browse the repository at this point in the history
  • Loading branch information
mobley-trent committed May 8, 2024
1 parent 5979f5b commit dcb32d9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/blueprint/operators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod grpc;
mod http;
mod modify;
mod protected;
// mod validate;

pub use call::*;
pub use expr::*;
Expand All @@ -13,3 +14,4 @@ pub use grpc::*;
pub use http::*;
pub use modify::*;
pub use protected::*;
// pub use validate::*;
26 changes: 26 additions & 0 deletions src/blueprint/operators/validate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// use crate::blueprint::FieldDefinition;
// use crate::config::{self, ConfigModule, Field};
// use crate::lambda::{Expression, IO};
// use crate::try_fold::TryFold;
// use crate::valid::Valid;

// pub fn update_validate<'a>(
// type_name: &'a str,
// ) -> TryFold<'a, (&'a ConfigModule, &'a Field, &'a config::Type, &'a str), FieldDefinition, String>
// {
// TryFold::<(&ConfigModule, &Field, &config::Type, &'a str), FieldDefinition, String>::new(
// |(config_module, field, _type, _), mut b_field| {
// if field.validate.is_some()
// || _type.validate.is_some()
// || config_module
// .find_type(&field.type_of)
// .and_then(|_type| _type.validate.as_ref())
// .is_some()
// {
// if !config_module.is_scalar(type_name) {
// return Valid::fail("@validate can only be used on custom scalars".to_owned());
// }
// }
// }
// )
// }
8 changes: 6 additions & 2 deletions src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ pub struct Type {
///
/// Contains source information for the type.
pub tag: Option<Tag>,
///
/// Indicates if a custom scalar type is valid
/// for a given JS function
pub validate: Option<Validate>,
}

impl Type {
Expand Down Expand Up @@ -603,10 +607,10 @@ pub struct Expr {
pub body: Value,
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Eq, schemars::JsonSchema)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Eq, schemars::JsonSchema, MergeRight)]

Check warning on line 610 in src/config/config.rs

View check run for this annotation

Codecov / codecov/patch

src/config/config.rs#L610

Added line #L610 was not covered by tests
pub struct Validate {
/// Name of the JS function
pub js: JS,
pub js: String,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, schemars::JsonSchema)]
Expand Down
5 changes: 3 additions & 2 deletions src/config/from_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,12 @@ where
.fuse(to_fields(fields))
.fuse(Protected::from_directives(directives.iter()))
.fuse(Tag::from_directives(directives.iter()))
.map(|(cache, fields, protected, tag)| {
.fuse(Validate::from_directives(directives.iter()))
.map(|(cache, fields, protected, tag, validate)| {
let doc = description.to_owned().map(|pos| pos.node);

Check warning on line 248 in src/config/from_document.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

Diff in /home/runner/work/tailcall/tailcall/src/config/from_document.rs
let implements = implements.iter().map(|pos| pos.node.to_string()).collect();
let added_fields = to_add_fields_from_directives(directives);
config::Type { fields, added_fields, doc, implements, cache, protected, tag }
config::Type { fields, added_fields, doc, implements, cache, protected, tag, validate }
})
}
fn to_input_object(
Expand Down
1 change: 1 addition & 0 deletions src/config/into_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ fn get_directives(field: &crate::config::Field) -> Vec<Positioned<ConstDirective
field.cache.as_ref().map(|d| pos(d.to_directive())),
field.call.as_ref().map(|d| pos(d.to_directive())),
field.protected.as_ref().map(|d| pos(d.to_directive())),
field.validate.as_ref().map(|d| pos(d.to_directive())),
];

directives.into_iter().flatten().collect()
Expand Down

0 comments on commit dcb32d9

Please sign in to comment.