Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better as an enum AttributeStorage { Direct, Derived }; even clearer would be to make EntityFilter::Child a struct, i.e.

    Child {
        attr: Attribute,
        entity_type: EntityType,
        filter: Box<EntityFilter>,
        derived: bool,
    },

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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