Skip to content

Commit baad0fe

Browse files
committed
store: Do not require that FromEntityData is Default
1 parent aaf42b2 commit baad0fe

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

store/postgres/src/relational_queries.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,23 @@ impl ForeignKeyClauses for Column {
269269
}
270270
}
271271

272-
pub trait FromEntityData: Default {
272+
pub trait FromEntityData {
273273
type Value: FromColumnValue;
274274

275+
fn new_entity(typename: String) -> Self;
276+
275277
fn insert_entity_data(&mut self, key: String, v: Self::Value);
276278
}
277279

278280
impl FromEntityData for Entity {
279281
type Value = graph::prelude::Value;
280282

283+
fn new_entity(typename: String) -> Self {
284+
let mut entity = Entity::new();
285+
entity.insert("__typename".to_string(), Self::Value::String(typename));
286+
entity
287+
}
288+
281289
fn insert_entity_data(&mut self, key: String, v: Self::Value) {
282290
self.insert(key, v);
283291
}
@@ -286,6 +294,12 @@ impl FromEntityData for Entity {
286294
impl FromEntityData for BTreeMap<String, r::Value> {
287295
type Value = r::Value;
288296

297+
fn new_entity(typename: String) -> Self {
298+
let mut map = BTreeMap::new();
299+
map.insert("__typename".to_string(), Self::Value::from_string(typename));
300+
map
301+
}
302+
289303
fn insert_entity_data(&mut self, key: String, v: Self::Value) {
290304
self.insert(key, v);
291305
}
@@ -481,11 +495,7 @@ impl EntityData {
481495
use serde_json::Value as j;
482496
match self.data {
483497
j::Object(map) => {
484-
let mut out = T::default();
485-
out.insert_entity_data(
486-
"__typename".to_owned(),
487-
T::Value::from_string(entity_type.into_string()),
488-
);
498+
let mut out = T::new_entity(entity_type.into_string());
489499
for (key, json) in map {
490500
// Simply ignore keys that do not have an underlying table
491501
// column; those will be things like the block_range that

store/postgres/src/writable.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl WritableStoreTrait for WritableAgent {
382382
self.store.supports_proof_of_indexing().await
383383
}
384384

385-
fn get(&self, key: &EntityKey) -> Result<Option<EntityVersion>, StoreError> {
385+
fn get(&self, key: &EntityKey) -> Result<Option<Entity>, StoreError> {
386386
self.store.get(key)
387387
}
388388

@@ -394,7 +394,7 @@ impl WritableStoreTrait for WritableAgent {
394394
stopwatch: StopwatchMetrics,
395395
data_sources: Vec<StoredDynamicDataSource>,
396396
deterministic_errors: Vec<SubgraphError>,
397-
) -> Result<Vec<(EntityKey, Vid)>, StoreError> {
397+
) -> Result<(), StoreError> {
398398
self.store.transact_block_operations(
399399
block_ptr_to,
400400
firehose_cursor,
@@ -408,7 +408,7 @@ impl WritableStoreTrait for WritableAgent {
408408
fn get_many(
409409
&self,
410410
ids_for_type: BTreeMap<&EntityType, Vec<&str>>,
411-
) -> Result<BTreeMap<EntityType, Vec<EntityVersion>>, StoreError> {
411+
) -> Result<BTreeMap<EntityType, Vec<Entity>>, StoreError> {
412412
self.store.get_many(ids_for_type)
413413
}
414414

@@ -432,4 +432,12 @@ impl WritableStoreTrait for WritableAgent {
432432
fn shard(&self) -> &str {
433433
self.store.shard()
434434
}
435+
436+
async fn health(&self, id: &DeploymentHash) -> Result<schema::SubgraphHealth, StoreError> {
437+
self.store.health(id).await
438+
}
439+
440+
fn input_schema(&self) -> Arc<Schema> {
441+
self.store.input_schema()
442+
}
435443
}

0 commit comments

Comments
 (0)