-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve union type in response (#2019)
Co-authored-by: Tushar Mathur <[email protected]>
- Loading branch information
1 parent
9264f22
commit f464794
Showing
49 changed files
with
3,665 additions
and
141 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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_union_resolver( | ||
config: &ConfigModule, | ||
union_name: &str, | ||
union_: &config::Union, | ||
) -> Valid<Discriminator, String> { | ||
Valid::from_iter(&union_.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 union type".to_string(), | ||
) | ||
}) | ||
.and_then(|types| { | ||
let types: Vec<_> = types.into_iter().collect(); | ||
|
||
Discriminator::new(union_name, &types) | ||
}) | ||
} | ||
|
||
pub fn update_union_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(union_) = config.find_union(&field.type_of) else { | ||
return Valid::succeed(b_field); | ||
}; | ||
|
||
compile_union_resolver(config, &field.type_of, union_).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 | ||
}) | ||
}, | ||
) | ||
} |
Oops, something went wrong.
f464794
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
415421 requests in 30.03s, 2.08GB read
Requests/sec: 13833.90
Transfer/sec: 71.00MB