Skip to content

Commit

Permalink
all: Add child filters (#3184)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored Jun 27, 2022
1 parent b2603cf commit 4c7cb15
Show file tree
Hide file tree
Showing 10 changed files with 679 additions and 73 deletions.
28 changes: 28 additions & 0 deletions graph/src/components/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ impl From<&str> for EntityType {

impl CheapClone for EntityType {}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct EntityFilterDerivative(bool);

impl EntityFilterDerivative {
pub fn new(derived: bool) -> Self {
Self(derived)
}

pub fn is_derived(&self) -> bool {
self.0
}
}

// Note: Do not modify fields without making a backward compatible change to
// the StableHash impl (below)
/// Key by which an individual entity in the store can be accessed.
Expand Down Expand Up @@ -166,6 +179,13 @@ fn key_stable_hash() {
"905b57035d6f98cff8281e7b055e10570a2bd31190507341c6716af2d3c1ad98",
);
}
#[derive(Clone, Debug, PartialEq)]
pub struct Child {
pub attr: Attribute,
pub entity_type: EntityType,
pub filter: Box<EntityFilter>,
pub derived: bool,
}

/// Supported types of store filters.
#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -193,6 +213,7 @@ pub enum EntityFilter {
NotEndsWith(Attribute, Value),
NotEndsWithNoCase(Attribute, Value),
ChangeBlockGte(BlockNumber),
Child(Child),
}

// A somewhat concise string representation of a filter
Expand Down Expand Up @@ -236,6 +257,13 @@ impl fmt::Display for EntityFilter {
NotEndsWith(a, v) => write!(f, "{a} !~ *{v}$"),
NotEndsWithNoCase(a, v) => write!(f, "{a} !~ *{v}$i"),
ChangeBlockGte(b) => write!(f, "block >= {b}"),
Child(child /* a, et, cf, _ */) => write!(
f,
"join on {} with {}({})",
child.attr,
child.entity_type,
child.filter.to_string()
),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion graph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub mod prelude {
pub use crate::components::server::query::GraphQLServer;
pub use crate::components::server::subscription::SubscriptionServer;
pub use crate::components::store::{
AttributeNames, BlockNumber, CachedEthereumCall, ChainStore, ChildMultiplicity,
AttributeNames, BlockNumber, CachedEthereumCall, ChainStore, Child, ChildMultiplicity,
EntityCache, EntityChange, EntityChangeOperation, EntityCollection, EntityFilter,
EntityKey, EntityLink, EntityModification, EntityOperation, EntityOrder, EntityQuery,
EntityRange, EntityWindow, EthereumCallCache, ParentLink, PartialBlockPtr, PoolWaitStats,
Expand Down
Loading

0 comments on commit 4c7cb15

Please sign in to comment.