-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(torii-graphql): event messages update & subscription #2227
Conversation
WalkthroughOhayo, sensei! The recent updates significantly enhance entity management flexibility across our codebase. The subscription field is now called Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant GraphQL
participant Database
Client->>GraphQL: Subscribe to entityUpdated
GraphQL->>Database: Listen for changes on Entity
Database-->>GraphQL: Notify on entity update
GraphQL-->>Client: Send updated entity data
Recent review detailsConfiguration used: .coderabbit.yaml Files selected for processing (1)
Additional comments not posted (3)
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2227 +/- ##
==========================================
- Coverage 69.60% 69.60% -0.01%
==========================================
Files 352 352
Lines 46019 46032 +13
==========================================
+ Hits 32030 32039 +9
- Misses 13989 13993 +4 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
fn event_message_field() -> Field { | ||
Field::new("eventMessage", TypeRef::named("EventMessage"), |ctx| { | ||
FieldFuture::new(async move { | ||
match ctx.parent_value.try_to_value()? { | ||
Value::Object(indexmap) => { | ||
let mut conn = ctx.data::<Pool<Sqlite>>()?.acquire().await?; | ||
let entity_id = utils::extract::<String>(indexmap, INTERNAL_ENTITY_ID_KEY)?; | ||
let data = | ||
fetch_single_row(&mut conn, EVENT_MESSAGE_TABLE, ID_COLUMN, &entity_id) | ||
.await?; | ||
let event_message = value_mapping_from_row(&data, &ENTITY_TYPE_MAPPING, false)?; | ||
|
||
Ok(Some(Value::Object(event_message))) | ||
} | ||
_ => Err("incorrect value, requires Value::Object".into()), | ||
} | ||
}) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohayo, sensei! The new event_message_field
function looks solid!
The function is well-structured and follows best practices for asynchronous database access and error handling.
Consider adding more detailed error messages to improve debugging.
- _ => Err("incorrect value, requires Value::Object".into()),
+ _ => Err("Incorrect value type encountered. Expected Value::Object.".into()),
Ensure that this function is covered by unit tests.
Do you want me to generate the unit testing code or open a GitHub issue to track this task?
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
fn event_message_field() -> Field { | |
Field::new("eventMessage", TypeRef::named("EventMessage"), |ctx| { | |
FieldFuture::new(async move { | |
match ctx.parent_value.try_to_value()? { | |
Value::Object(indexmap) => { | |
let mut conn = ctx.data::<Pool<Sqlite>>()?.acquire().await?; | |
let entity_id = utils::extract::<String>(indexmap, INTERNAL_ENTITY_ID_KEY)?; | |
let data = | |
fetch_single_row(&mut conn, EVENT_MESSAGE_TABLE, ID_COLUMN, &entity_id) | |
.await?; | |
let event_message = value_mapping_from_row(&data, &ENTITY_TYPE_MAPPING, false)?; | |
Ok(Some(Value::Object(event_message))) | |
} | |
_ => Err("incorrect value, requires Value::Object".into()), | |
} | |
}) | |
}) | |
} | |
fn event_message_field() -> Field { | |
Field::new("eventMessage", TypeRef::named("EventMessage"), |ctx| { | |
FieldFuture::new(async move { | |
match ctx.parent_value.try_to_value()? { | |
Value::Object(indexmap) => { | |
let mut conn = ctx.data::<Pool<Sqlite>>()?.acquire().await?; | |
let entity_id = utils::extract::<String>(indexmap, INTERNAL_ENTITY_ID_KEY)?; | |
let data = | |
fetch_single_row(&mut conn, EVENT_MESSAGE_TABLE, ID_COLUMN, &entity_id) | |
.await?; | |
let event_message = value_mapping_from_row(&data, &ENTITY_TYPE_MAPPING, false)?; | |
Ok(Some(Value::Object(event_message))) | |
} | |
_ => Err("Incorrect value type encountered. Expected Value::Object.".into()), | |
} | |
}) | |
}) | |
} |
66fbbdf
to
e903e3d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
fn event_message_field() -> Field { | ||
Field::new("eventMessage", TypeRef::named(EVENT_MESSAGE_TYPE_NAME), |ctx| { | ||
FieldFuture::new(async move { | ||
match ctx.parent_value.try_to_value()? { | ||
Value::Object(indexmap) => { | ||
let mut conn = ctx.data::<Pool<Sqlite>>()?.acquire().await?; | ||
let entity_id = utils::extract::<String>(indexmap, INTERNAL_ENTITY_ID_KEY)?; | ||
let data = | ||
fetch_single_row(&mut conn, EVENT_MESSAGE_TABLE, ID_COLUMN, &entity_id) | ||
.await?; | ||
let event_message = value_mapping_from_row( | ||
&data, | ||
EVENT_MESSAGE_ID_COLUMN, | ||
&ENTITY_TYPE_MAPPING, | ||
false, | ||
)?; | ||
|
||
Ok(Some(Value::Object(event_message))) | ||
} | ||
_ => Err("incorrect value, requires Value::Object".into()), | ||
} | ||
}) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohayo, sensei! The new event_message_field
function looks solid!
The function is well-structured and follows best practices for asynchronous database access and error handling.
Consider adding more detailed error messages to improve debugging.
- _ => Err("incorrect value, requires Value::Object".into()),
+ _ => Err("Incorrect value type encountered. Expected Value::Object.".into()),
Ensure that this function is covered by unit tests.
Do you want me to generate the unit testing code or open a GitHub issue to track this task?
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
fn event_message_field() -> Field { | |
Field::new("eventMessage", TypeRef::named(EVENT_MESSAGE_TYPE_NAME), |ctx| { | |
FieldFuture::new(async move { | |
match ctx.parent_value.try_to_value()? { | |
Value::Object(indexmap) => { | |
let mut conn = ctx.data::<Pool<Sqlite>>()?.acquire().await?; | |
let entity_id = utils::extract::<String>(indexmap, INTERNAL_ENTITY_ID_KEY)?; | |
let data = | |
fetch_single_row(&mut conn, EVENT_MESSAGE_TABLE, ID_COLUMN, &entity_id) | |
.await?; | |
let event_message = value_mapping_from_row( | |
&data, | |
EVENT_MESSAGE_ID_COLUMN, | |
&ENTITY_TYPE_MAPPING, | |
false, | |
)?; | |
Ok(Some(Value::Object(event_message))) | |
} | |
_ => Err("incorrect value, requires Value::Object".into()), | |
} | |
}) | |
}) | |
} | |
fn event_message_field() -> Field { | |
Field::new("eventMessage", TypeRef::named(EVENT_MESSAGE_TYPE_NAME), |ctx| { | |
FieldFuture::new(async move { | |
match ctx.parent_value.try_to_value()? { | |
Value::Object(indexmap) => { | |
let mut conn = ctx.data::<Pool<Sqlite>>()?.acquire().await?; | |
let entity_id = utils::extract::<String>(indexmap, INTERNAL_ENTITY_ID_KEY)?; | |
let data = | |
fetch_single_row(&mut conn, EVENT_MESSAGE_TABLE, ID_COLUMN, &entity_id) | |
.await?; | |
let event_message = value_mapping_from_row( | |
&data, | |
EVENT_MESSAGE_ID_COLUMN, | |
&ENTITY_TYPE_MAPPING, | |
false, | |
)?; | |
Ok(Some(Value::Object(event_message))) | |
} | |
_ => Err("Incorrect value type encountered. Expected Value::Object.".into()), | |
} | |
}) | |
}) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
fn event_message_field() -> Field { | ||
Field::new("eventMessage", TypeRef::named(EVENT_MESSAGE_TYPE_NAME), |ctx| { | ||
FieldFuture::new(async move { | ||
match ctx.parent_value.try_to_value()? { | ||
Value::Object(indexmap) => { | ||
let mut conn = ctx.data::<Pool<Sqlite>>()?.acquire().await?; | ||
let entity_id = utils::extract::<String>(indexmap, INTERNAL_ENTITY_ID_KEY)?; | ||
let data = | ||
fetch_single_row(&mut conn, EVENT_MESSAGE_TABLE, ID_COLUMN, &entity_id) | ||
.await?; | ||
let event_message = value_mapping_from_row(&data, &ENTITY_TYPE_MAPPING, false)?; | ||
|
||
Ok(Some(Value::Object(event_message))) | ||
} | ||
_ => Err("incorrect value, requires Value::Object".into()), | ||
} | ||
}) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohayo, sensei! The new event_message_field
function looks solid!
The function is well-structured and follows best practices for asynchronous database access and error handling.
Consider adding more detailed error messages to improve debugging.
- _ => Err("incorrect value, requires Value::Object".into()),
+ _ => Err("Incorrect value type encountered. Expected Value::Object.".into()),
Ensure that this function is covered by unit tests.
Do you want me to generate the unit testing code or open a GitHub issue to track this task?
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
fn event_message_field() -> Field { | |
Field::new("eventMessage", TypeRef::named(EVENT_MESSAGE_TYPE_NAME), |ctx| { | |
FieldFuture::new(async move { | |
match ctx.parent_value.try_to_value()? { | |
Value::Object(indexmap) => { | |
let mut conn = ctx.data::<Pool<Sqlite>>()?.acquire().await?; | |
let entity_id = utils::extract::<String>(indexmap, INTERNAL_ENTITY_ID_KEY)?; | |
let data = | |
fetch_single_row(&mut conn, EVENT_MESSAGE_TABLE, ID_COLUMN, &entity_id) | |
.await?; | |
let event_message = value_mapping_from_row(&data, &ENTITY_TYPE_MAPPING, false)?; | |
Ok(Some(Value::Object(event_message))) | |
} | |
_ => Err("incorrect value, requires Value::Object".into()), | |
} | |
}) | |
}) | |
} | |
fn event_message_field() -> Field { | |
Field::new("eventMessage", TypeRef::named(EVENT_MESSAGE_TYPE_NAME), |ctx| { | |
FieldFuture::new(async move { | |
match ctx.parent_value.try_to_value()? { | |
Value::Object(indexmap) => { | |
let mut conn = ctx.data::<Pool<Sqlite>>()?.acquire().await?; | |
let entity_id = utils::extract::<String>(indexmap, INTERNAL_ENTITY_ID_KEY)?; | |
let data = | |
fetch_single_row(&mut conn, EVENT_MESSAGE_TABLE, ID_COLUMN, &entity_id) | |
.await?; | |
let event_message = value_mapping_from_row(&data, &ENTITY_TYPE_MAPPING, false)?; | |
Ok(Some(Value::Object(event_message))) | |
} | |
_ => Err("Incorrect value type encountered. Expected Value::Object.".into()), | |
} | |
}) | |
}) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
use sqlx::{Pool, Sqlite}; | ||
use tokio_stream::StreamExt; | ||
use torii_core::simple_broker::SimpleBroker; | ||
use torii_core::types::EventMessage; | ||
|
||
use super::entity::model_data_recursive_query; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohayo, sensei! Consider removing unused imports.
The model_data_recursive_query
function is removed, but its import still exists. Removing unused imports helps maintain clean and efficient code.
- use super::entity::model_data_recursive_query;
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
use super::entity::model_data_recursive_query; |
for (id, name) in model_ids { | ||
// the model id is used as the id for the model members | ||
for (id, namespace, name) in model_ids { | ||
// the model id in the model mmeebrs table is the hashed model name (id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// the model id in the model mmeebrs table is the hashed model name (id) | |
// the model id in the model members table is the hashed model name (id) |
Wrap up the work to add event messages for graphql & expose subscription to event messages
Summary by CodeRabbit
New Features
eventMessage
added to theModelDataObject
, improving GraphQL API data retrieval.namespace
field.Bug Fixes
Refactor
Entity
type, improving extensibility and maintainability.model_data_recursive_query
function to simplify data retrieval processes.