Skip to content

Commit

Permalink
misc: Add logs if running in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
cvauclair committed Feb 20, 2025
1 parent 213ac8c commit 6dd6abc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 49 deletions.
54 changes: 24 additions & 30 deletions api/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ type Entity {
"""Entity description (if available)"""
description: String

"""Entity name (if available)"""
"""Entity cover (if available)"""
cover: String

"""Entity name (if available)"""
"""Entity blocks (if available)"""
blocks: [Entity!]!

"""Types of the entity (which are entities themselves)"""
types: [Entity!]!

"""
The space ID of the entity (note: the same entity can exist in multiple spaces)
"""
Expand All @@ -30,14 +33,14 @@ type Entity {
updatedAt: String!
updatedAtBlock: String!

"""Types of the entity (which are entities themselves)"""
types: [Entity!]!

"""Attributes of the entity"""
attributes(filter: AttributeFilter): [Triple!]!

"""Relations outgoing from the entity"""
relations(where: EntityRelationFilter): [Relation!]!

"""Versions of the entity, ordered chronologically"""
versions: [EntityVersion!]!
}

"""Filter the entities by attributes and their values and value types"""
Expand Down Expand Up @@ -75,8 +78,6 @@ input EntityFilter {
idNotIn: [String!]

"""Exact match for the entity types"""
types: [String!]
typesNot: [String!]
typesContains: [String!]
typesNotContains: [String!]
attributes: [EntityAttributeFilter!]
Expand All @@ -99,7 +100,13 @@ input EntityRelationFilter {

"""Filter the relations by the entity they point to"""
to: EntityFilter
attributes: [EntityAttributeFilter!]
}

type EntityVersion {
id: String!

"""Attributes of the entity"""
attributes(filter: AttributeFilter): [Triple!]!
}

type Options {
Expand All @@ -115,54 +122,38 @@ enum OrderDirection {

type Query {
"""Returns a single entity identified by its ID and space ID"""
entity(id: String!, spaceId: String!): Entity
entity(id: String!, spaceId: String!, versionId: String): Entity

"""
Returns multiple entities according to the provided space ID and filter
"""
entities(spaceId: String!, orderBy: String, orderDirection: OrderDirection, where: EntityFilter): [Entity!]!

"""Returns a single relation identified by its ID and space ID"""
relation(id: String!, spaceId: String!): Relation
relation(id: String!, spaceId: String!, versionId: String): Relation

"""
Returns multiple relations according to the provided space ID and filter
"""
relations(spaceId: String!, orderBy: String, orderDirection: OrderDirection, where: RelationFilter): [Relation!]!
}

"""
Relation object
Note: Relations are also entities, but they have a different structure in the database.
In other words, the Relation object is a "view" on a relation entity. All relations
can also be queried as entities.
"""
"""Relation object"""
type Relation {
"""Relation ID"""
id: String!

"""Relation name (if available)"""
name: String
createdAt: String!
createdAtBlock: String!
updatedAt: String!
updatedAtBlock: String!

"""Attributes of the relation"""
attributes: [Triple!]!
"""Entity of the relation"""
entity: Entity!

"""Relation type of the relation"""
relationType: [Entity!]!
relationType: Entity!

"""Entity from which the relation originates"""
from: Entity!

"""Entity to which the relation points"""
to: Entity!

"""Relations outgoing from the relation"""
relations(spaceId: String!, where: EntityRelationFilter): [Relation!]!
}

"""Relation filter input object"""
Expand Down Expand Up @@ -202,6 +193,9 @@ type Triple {
"""Options of the triple (if any)"""
options: Options!

"""Space ID of the triple"""
spaceId: String!

"""Name of the attribute (if available)"""
name: String
}
Expand Down
13 changes: 8 additions & 5 deletions sdk/src/mapping/entity_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use futures::stream::TryStreamExt;

use serde::{Deserialize, Serialize};

use crate::{error::DatabaseError, indexer_ids, models::{space, BlockMetadata}, system_ids};
use crate::{error::DatabaseError, indexer_ids, models::BlockMetadata, system_ids};

Check warning on line 6 in sdk/src/mapping/entity_node.rs

View workflow job for this annotation

GitHub Actions / stable / fmt

Diff in /home/runner/work/kg-node/kg-node/sdk/src/mapping/entity_node.rs

use super::{
attributes, entity_version, query_utils::{
Expand Down Expand Up @@ -292,11 +292,14 @@ impl FindManyQuery {
impl Query<Vec<EntityNode>> for FindManyQuery {
async fn send(self) -> Result<Vec<EntityNode>, DatabaseError> {
let neo4j = self.neo4j.clone();
// let query = self.into_query_part().build();

let query_part = self.into_query_part();
tracing::info!("eneity_node::FindManyQuery:\n{}", query_part.query());
let query = query_part.build();
let query = if cfg!(debug_assertions) {
let query_part = self.into_query_part();
tracing::info!("entity_node::FindManyQuery:\n{}", query_part.query());
query_part.build()
} else {
self.into_query_part().build()
};

#[derive(Debug, Deserialize)]
struct RowResult {
Expand Down
17 changes: 9 additions & 8 deletions sdk/src/mapping/query_utils/query_part.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ impl QueryPart {
.collect::<Vec<_>>()
.join(", "),
);
query.push('\n');
}

if let Some((clause, other)) = &self.with_clauses {
Expand All @@ -176,6 +177,14 @@ impl QueryPart {
query.push('\n');
}

if let Some(limit) = self.limit {
query.push_str(&format!("LIMIT {}\n", limit));
}

if let Some(skip) = self.skip {
query.push_str(&format!("SKIP {}\n", skip));
}

if !self.return_clauses.is_empty() {
query.push_str("RETURN ");
query.push_str(
Expand All @@ -189,14 +198,6 @@ impl QueryPart {
query.push('\n');
}

if let Some(limit) = self.limit {
query.push_str(&format!("LIMIT {}\n", limit));
}

if let Some(skip) = self.skip {
query.push_str(&format!("SKIP {}\n", skip));
}

query
}

Expand Down
16 changes: 10 additions & 6 deletions sdk/src/mapping/triple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ impl Query<Option<Triple>> for FindOneQuery {
.params("entity_id", self.entity_id)
.params("space_id", self.space_id);

tracing::info!("triple::FindOneQuery:\n{}", query_part.query());
if cfg!(debug_assertions) {
tracing::info!("triple::FindOneQuery:\n{}", query_part.query());
}
let query = query_part.build();

self.neo4j
Expand Down Expand Up @@ -444,12 +446,14 @@ impl FindManyQuery {
impl Query<Vec<Triple>> for FindManyQuery {
async fn send(self) -> Result<Vec<Triple>, DatabaseError> {
let neo4j = self.neo4j.clone();
// println!("FindManyQuery::send");
// let query = self.into_query_part().build();

let qpart = self.into_query_part();
tracing::info!("triple::FindManyQuery:\n{}", qpart.query());
let query = qpart.build();
let query = if cfg!(debug_assertions) {
let query_part = self.into_query_part();
tracing::info!("triple::FindManyQuery:\n{}", query_part.query());
query_part.build()
} else {
self.into_query_part().build()
};

neo4j
.execute(query)
Expand Down

0 comments on commit 6dd6abc

Please sign in to comment.