-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Graphql event keys filtering (#1062)
- Loading branch information
Showing
7 changed files
with
117 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use async_graphql::dynamic::{Field, InputValue, ResolverContext, TypeRef}; | ||
use async_graphql::Error; | ||
|
||
use crate::utils::extract; | ||
|
||
pub fn keys_argument(field: Field) -> Field { | ||
field.argument(InputValue::new("keys", TypeRef::named_list(TypeRef::STRING))) | ||
} | ||
|
||
pub fn parse_keys_argument(ctx: &ResolverContext<'_>) -> Result<Option<Vec<String>>, Error> { | ||
let keys = extract::<Vec<String>>(ctx.args.as_index_map(), "keys"); | ||
|
||
if let Ok(keys) = keys { | ||
if !keys.iter().all(|s| is_hex_or_star(s)) { | ||
return Err("Key parts can only be hex string or wild card `*`".into()); | ||
} | ||
|
||
return Ok(Some(keys)); | ||
} | ||
|
||
Ok(None) | ||
} | ||
|
||
fn is_hex_or_star(s: &str) -> bool { | ||
if s == "*" { | ||
return true; | ||
} | ||
let s = if let Some(stripped) = s.strip_prefix("0x") { stripped } else { s }; | ||
|
||
s.chars().all(|c| c.is_ascii_hexdigit()) | ||
} |
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