Sitelet https://github.com/nullmastermind/graph-node/commit/4c7cb15df985d08503871c742e8f584383fda56b
Skip to content

Commit 4c7cb15

Browse files
authored
all: Add child filters (graphprotocol#3184)
1 parent b2603cf commit 4c7cb15

10 files changed

Lines changed: 679 additions & 73 deletions

File tree

‎graph/src/components/store/mod.rs‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ impl From<&str> for EntityType {
8282

8383
impl CheapClone for EntityType {}
8484

85+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
86+
pub struct EntityFilterDerivative(bool);
87+
88+
impl EntityFilterDerivative {
89+
pub fn new(derived: bool) -> Self {
90+
Self(derived)
91+
}
92+
93+
pub fn is_derived(&self) -> bool {
94+
self.0
95+
}
96+
}
97+
8598
// Note: Do not modify fields without making a backward compatible change to
8699
// the StableHash impl (below)
87100
/// Key by which an individual entity in the store can be accessed.
@@ -166,6 +179,13 @@ fn key_stable_hash() {
166179
"905b57035d6f98cff8281e7b055e10570a2bd31190507341c6716af2d3c1ad98",
167180
);
168181
}
182+
#[derive(Clone, Debug, PartialEq)]
183+
pub struct Child {
184+
pub attr: Attribute,
185+
pub entity_type: EntityType,
186+
pub filter: Box<EntityFilter>,
187+
pub derived: bool,
188+
}
169189

170190
/// Supported types of store filters.
171191
#[derive(Clone, Debug, PartialEq)]
@@ -193,6 +213,7 @@ pub enum EntityFilter {
193213
NotEndsWith(Attribute, Value),
194214
NotEndsWithNoCase(Attribute, Value),
195215
ChangeBlockGte(BlockNumber),
216+
Child(Child),
196217
}
197218

198219
// A somewhat concise string representation of a filter
@@ -236,6 +257,13 @@ impl fmt::Display for EntityFilter {
236257
NotEndsWith(a, v) => write!(f, "{a} !~ *{v}$"),
237258
NotEndsWithNoCase(a, v) => write!(f, "{a} !~ *{v}$i"),
238259
ChangeBlockGte(b) => write!(f, "block >= {b}"),
260+
Child(child /* a, et, cf, _ */) => write!(
261+
f,
262+
"join on {} with {}({})",
263+
child.attr,
264+
child.entity_type,
265+
child.filter.to_string()
266+
),
239267
}
240268
}
241269
}

‎graph/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub mod prelude {
114114
pub use crate::components::server::query::GraphQLServer;
115115
pub use crate::components::server::subscription::SubscriptionServer;
116116
pub use crate::components::store::{
117-
AttributeNames, BlockNumber, CachedEthereumCall, ChainStore, ChildMultiplicity,
117+
AttributeNames, BlockNumber, CachedEthereumCall, ChainStore, Child, ChildMultiplicity,
118118
EntityCache, EntityChange, EntityChangeOperation, EntityCollection, EntityFilter,
119119
EntityKey, EntityLink, EntityModification, EntityOperation, EntityOrder, EntityQuery,
120120
EntityRange, EntityWindow, EthereumCallCache, ParentLink, PartialBlockPtr, PoolWaitStats,

0 commit comments

Comments
 (0)