-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for external directives (#2894)
Co-authored-by: Tushar Mathur <[email protected]>
- Loading branch information
1 parent
44777af
commit 1511db7
Showing
37 changed files
with
723 additions
and
351 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
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 std::collections::HashMap; | ||
|
||
use async_graphql::parser::types::ConstDirective; | ||
use async_graphql::Name; | ||
use serde_json::Value; | ||
|
||
use crate::core::valid::{Valid, ValidationError, Validator}; | ||
use crate::core::{config, pos}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Directive { | ||
pub name: String, | ||
pub arguments: HashMap<String, Value>, | ||
} | ||
|
||
pub fn to_directive(const_directive: ConstDirective) -> Valid<Directive, String> { | ||
const_directive | ||
.arguments | ||
.into_iter() | ||
.map(|(k, v)| { | ||
let value = v.node.into_json(); | ||
|
||
value.map(|value| (k.node.to_string(), value)) | ||
}) | ||
.collect::<Result<_, _>>() | ||
.map_err(|e| ValidationError::new(e.to_string())) | ||
.map(|arguments| Directive { name: const_directive.name.node.to_string(), arguments }) | ||
.into() | ||
} | ||
|
||
pub fn to_const_directive(directive: &Directive) -> Valid<ConstDirective, String> { | ||
Valid::from_iter(directive.arguments.iter(), |(k, v)| { | ||
let name = pos(Name::new(k)); | ||
Valid::from(serde_json::from_value(v.clone()).map(pos).map_err(|e| { | ||
ValidationError::new(e.to_string()).trace(format!("@{}", directive.name).as_str()) | ||
})) | ||
.map(|value| (name, value)) | ||
}) | ||
.map(|arguments| ConstDirective { name: pos(Name::new(&directive.name)), arguments }) | ||
} | ||
|
||
impl From<config::Directive> for Directive { | ||
fn from(value: config::Directive) -> Self { | ||
Self { | ||
name: value.name, | ||
arguments: value.arguments.into_iter().collect(), | ||
} | ||
} | ||
} |
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.
1511db7
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
424132 requests in 30.04s, 792.84MB read
Requests/sec: 14120.11
Transfer/sec: 26.39MB