-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(discriminator): Add Discriminator support for Interfaces (#2966)
Co-authored-by: Kiryl Mialeshka <[email protected]>
- Loading branch information
Showing
28 changed files
with
879 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use std::collections::HashSet; | ||
|
||
use crate::core::blueprint::FieldDefinition; | ||
use crate::core::config; | ||
use crate::core::config::{ConfigModule, Field}; | ||
use crate::core::ir::model::IR; | ||
use crate::core::ir::Discriminator; | ||
use crate::core::try_fold::TryFold; | ||
use crate::core::valid::{Valid, Validator}; | ||
|
||
fn compile_interface_resolver( | ||
config: &ConfigModule, | ||
interface_name: &str, | ||
interface_types: HashSet<String>, | ||
) -> Valid<Discriminator, String> { | ||
Valid::from_iter(&interface_types, |type_name| { | ||
Valid::from_option( | ||
config | ||
.find_type(type_name) | ||
.map(|type_| (type_name.as_str(), type_)), | ||
"Can't find a type that is member of interface type".to_string(), | ||
) | ||
}) | ||
.and_then(|types| { | ||
let types: Vec<_> = types.into_iter().collect(); | ||
|
||
Discriminator::new(interface_name, &types) | ||
}) | ||
} | ||
|
||
pub fn update_interface_resolver<'a>( | ||
) -> TryFold<'a, (&'a ConfigModule, &'a Field, &'a config::Type, &'a str), FieldDefinition, String> | ||
{ | ||
TryFold::<(&ConfigModule, &Field, &config::Type, &str), FieldDefinition, String>::new( | ||
|(config, field, _, _), mut b_field| { | ||
let Some(interface_types) = config.interfaces_types_map().get(field.type_of.name()) | ||
else { | ||
return Valid::succeed(b_field); | ||
}; | ||
|
||
compile_interface_resolver( | ||
config, | ||
field.type_of.name(), | ||
interface_types.iter().cloned().collect(), | ||
) | ||
.map(|discriminator| { | ||
b_field.resolver = Some( | ||
b_field | ||
.resolver | ||
.unwrap_or(IR::ContextPath(vec![b_field.name.clone()])), | ||
); | ||
b_field.map_expr(move |expr| IR::Discriminate(discriminator, expr.into())); | ||
b_field | ||
}) | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
a48cf84
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running 30s test @ http://localhost:8000/graphql
4 threads and 100 connections
412554 requests in 30.01s, 797.27MB read
Requests/sec: 13746.07
Transfer/sec: 26.56MB