Skip to content

Commit

Permalink
misc: Rename node to entity in gql aoi
Browse files Browse the repository at this point in the history
  • Loading branch information
cvauclair committed Dec 12, 2024
1 parent 669495e commit 99f2a7b
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ pub struct Query;
#[graphql_object]
#[graphql(context = KnowledgeGraph, scalar = S: ScalarValue)]
impl Query {
async fn node<'a, S: ScalarValue>(
async fn entity<'a, S: ScalarValue>(
&'a self,
executor: &'a Executor<'_, '_, KnowledgeGraph, S>,
id: String,
space_id: Option<String>,
version_id: Option<String>,
) -> Option<Node> {
) -> Option<Entity> {
// let query = QueryMapper::default().select_root_node(&id, &executor.look_ahead()).build();
// tracing::info!("Query: {}", query);

Check warning on line 41 in api/src/main.rs

View workflow job for this annotation

GitHub Actions / stable / fmt

Diff in /home/runner/work/kg-node/kg-node/api/src/main.rs

Expand All @@ -52,16 +52,16 @@ impl Query {
.find_node::<HashMap<String, serde_json::Value>>(query)
.await
.expect("Failed to find node")
.map(Node::from)
.map(Entity::from)
}
}

// Attributes GraphQL scalar
#[derive(Clone, Debug, GraphQLScalar)]
#[graphql(with = node_data)]
#[graphql(with = attributes)]
pub struct Attributes(HashMap<String, serde_json::Value>);

mod node_data {
mod attributes {
use juniper::{InputValue, ParseScalarResult, ScalarToken, ScalarValue, Value};

use super::*;
Expand Down Expand Up @@ -100,14 +100,14 @@ mod node_data {
}

#[derive(Clone, Debug)]
pub struct Node {
pub struct Entity {
id: String,
space_id: String,
types: Vec<String>,
attributes: Attributes,
}

impl From<kg::mapping::Node<HashMap<String, serde_json::Value>>> for Node {
impl From<kg::mapping::Node<HashMap<String, serde_json::Value>>> for Entity {
fn from(node: kg::mapping::Node<HashMap<String, serde_json::Value>>) -> Self {
Self {
id: node.id().to_string(),
Expand All @@ -120,7 +120,7 @@ impl From<kg::mapping::Node<HashMap<String, serde_json::Value>>> for Node {

#[graphql_object]
#[graphql(context = KnowledgeGraph, scalar = S: ScalarValue)]
impl Node {
impl Entity {
fn id(&self) -> &str {
&self.id
}
Expand Down Expand Up @@ -182,21 +182,21 @@ impl Relation {
&self.attributes
}

async fn from<'a, S: ScalarValue>(&'a self, executor: &'a Executor<'_, '_, KnowledgeGraph, S>) -> Node {
async fn from<'a, S: ScalarValue>(&'a self, executor: &'a Executor<'_, '_, KnowledgeGraph, S>) -> Entity {
executor.context().0
.find_node_from_relation::<HashMap<String, serde_json::Value>>(&self.id)
.await
.expect("Failed to find node")
.map(Node::from)
.map(Entity::from)
.unwrap()
}

async fn to<'a, S: ScalarValue>(&'a self, executor: &'a Executor<'_, '_, KnowledgeGraph, S>) -> Node {
async fn to<'a, S: ScalarValue>(&'a self, executor: &'a Executor<'_, '_, KnowledgeGraph, S>) -> Entity {
executor.context().0
.find_node_to_relation::<HashMap<String, serde_json::Value>>(&self.id)
.await
.expect("Failed to find node")
.map(Node::from)
.map(Entity::from)
.unwrap()
}
}
Expand Down

0 comments on commit 99f2a7b

Please sign in to comment.